RosettaCodeData/Task/Nim-game/FTCBASIC/nim-game.basic

81 lines
1.1 KiB
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
define tokens = 12, take = 0
gosub intro
do
2026-04-30 12:34:36 -04:00
print "There are " \
print tokens \
print " tokens remaining."
crlf
print "How many would you like to take? " \
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
input take
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
if take > 3 or take < 1 then
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
print "You must take between 1 to 3 tokens."
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
endif
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
if tokens - take < 0 then
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
print "You cannot take that many."
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
endif
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
if take <= 3 and take >= 1 and tokens - take >= 0 then
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
let tokens = tokens - take
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
if tokens = 0 then
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
bell
print "Congratulations. You got the last token."
pause
end
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
endif
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
let take = 4 - take
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
if tokens >= 15 then
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
let take = 3
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
endif
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
if tokens <= 3 then
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
let take = tokens
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
endif
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
print "I will take " \
print take \
print " of the tokens."
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
let tokens = tokens - take
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
if tokens = 0 then
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
print "I got the last token. I win. Better luck next time."
pause
end
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
endif
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
endif
2023-07-01 11:58:00 -04:00
loop
sub intro
2026-04-30 12:34:36 -04:00
cls
print "NIM game"
crlf
print "Press any key to play..."
cls
2023-07-01 11:58:00 -04:00
return