RosettaCodeData/Task/Nim-game/Craft-Basic/nim-game.basic

58 lines
814 B
Text
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
let h = 12
label loop
2026-04-30 12:34:36 -04:00
alert "There are ", h ," tokens remaining."
input "How many would you like to take? ", t
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
if t > 3 or t < 1 then
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
alert "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 h - t < 0 then
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
alert "You cannot take that many. There's only ", h ," left."
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 t <= 3 and t >= 1 and h - t >= 0 then
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
let h = h - t
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
if h = 0 then
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
alert "Congratulations. You got the last token."
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 t = 4 - t
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
if h >= 15 then
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
let t = 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 h <= 3 then
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
let t = h
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
alert "I will take ", t ," tokens."
let h = h - t
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
if h = 0 then
2023-07-01 11:58:00 -04:00
2026-04-30 12:34:36 -04:00
alert "I got the last token. I win. Better luck next time."
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
goto loop