Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,88 @@
&TRIM = 1
&DUMP = 1
OUTPUT(.prompt, 9, 'T', '-')
********************************************************************************
* GETCOUNT() - Get the count of tokens to take.
********************************************************************************
define('GETCOUNT()I')
:(GETCOUNT.END)
GETCOUNT OUTPUT = 'Enter a number between 1 and 3, blank line to exit.'
****************************************
* Data input and integrity check loop.
****************************************
GETCOUNT.LOOP PROMPT = '> '
i = trim(INPUT)
* Abort on nil entry.
eq(size(i), 0) :S(EXIT)
* Check range.
integer(i) :F(GETCOUNT.INVALID)
lt(i, 4) :F(GETCOUNT.INVALID)
gt(i, 0) :F(GETCOUNT.INVALID)
* It all checked out.
GETCOUNT = i :(RETURN)
****************************************
* An invalid entry was caught.
****************************************
GETCOUNT.INVALID OUTPUT = 'Invalid number.' :(GETCOUNT.LOOP)
GETCOUNT.END
********************************************************************************
* MAINLINE CODE
********************************************************************************
MAIN OUTPUT =
OUTPUT = 'The mysterious game of Nim!'
OUTPUT = 'Whoever takes the last token of twelve wins.'
tokens = 12
****************************************
* MAIN LOOP
****************************************
MAIN.LOOP OUTPUT =
OUTPUT = 'There are ' tokens ' tokens remaining. How many do you want to take?'
********************
* Player turn.
********************
MAIN.P ptake = getcount()
tokens = tokens - ptake
OUTPUT = 'You selected ' ptake ' tokens leaving ' tokens '.'
lt(tokens, 0) :S(ERROR)
gt(tokens, 12) :S(ERROR)
eq(tokens, 0) :S(MAIN.PWIN)
********************
* Computer turn.
********************
MAIN.C ctake = 4 - ptake
tokens = tokens - ctake
OUTPUT = 'Computer selects ' ctake ' tokens leaving ' tokens '.'
lt(tokens, 0) :S(ERROR)
gt(tokens, 12) :S(ERROR)
eq(tokens, 0) :S(MAIN.CWIN)
:(MAIN.LOOP)
****************************************
* Player win is impossible. Joke code.
****************************************
MAIN.PWIN OUTPUT = 'Player wins. This is impossible. You must have cheated.'
OUTPUT = 'Formatting hard drive...' :(ERROR)
****************************************
* Computer win is inevitable.
****************************************
MAIN.CWIN OUTPUT = 'Computer wins.' :(EXIT)
********************************************************************************
* On a routine exit we turn off the variable dump.
* If we exit through an error (like branching to a non-existent label 'ERROR')
* then this code doesn't happen and variables get dumped and the line of the
* failed check getting printed.
********************************************************************************
EXIT OUTPUT = 'Bye!'
&DUMP = 0
END