70 lines
890 B
Text
70 lines
890 B
Text
;NIM game example program for x86 DOS
|
|
;Compiles with Pebble to com file under 1kb.
|
|
|
|
program examples\nim
|
|
|
|
data
|
|
|
|
int tokens[12]
|
|
int take[0]
|
|
|
|
begin
|
|
|
|
call intro
|
|
|
|
label gameloop
|
|
|
|
echo "There are"
|
|
echo [tokens]
|
|
echo " tokens remaining."
|
|
crlf
|
|
echo "How many would you like to take? "
|
|
input [take]
|
|
|
|
if [take] > 3 | [take] < 1 then
|
|
|
|
echo "You must take between 1 to 3 tokens."
|
|
|
|
endif
|
|
|
|
if [take] <= 3 & [take] >= 1 then
|
|
|
|
[tokens] = [tokens] - [take]
|
|
|
|
if [tokens] = 0 then
|
|
|
|
bell
|
|
echo "Congratulations. You got the last token."
|
|
pause
|
|
kill
|
|
|
|
endif
|
|
|
|
[take] = 4 - [take]
|
|
|
|
echo "I will take"
|
|
echo [take]
|
|
echo " tokens.
|
|
[tokens] = [tokens] - [take]
|
|
|
|
if [tokens] = 0 then
|
|
|
|
echo "I got the last token. I win. Better luck next time."
|
|
pause
|
|
kill
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
goto gameloop
|
|
|
|
end
|
|
|
|
sub intro
|
|
|
|
cls
|
|
echo "NIM game"
|
|
crlf
|
|
|
|
ret
|