Nim game: Difference between revisions
Nim game in various dialects BASIC (BASIC256, QBasic, Run BASIC, PureBasic and Yabasic)
(Dialects of BASIC moved to the BASIC section.) |
(Nim game in various dialects BASIC (BASIC256, QBasic, Run BASIC, PureBasic and Yabasic)) |
||
Line 721:
This one-liner demonstrates the 240 character line limit. The program has been crafted to be exactly 244 characters long. The last 4 characters HEAP will be truncated from the last statement in the line. The HEAP variable is optional in the out-most NEXT statement so the program still runs correctly.
<syntaxhighlight lang="applesoftbasic">0ST$(0)="YOU MUST TAKE 1, 2, OR 3 TOKENS.":FORHEAP=12TO1STEP-4:PRINT"THERE ARE "HEAP" TOKENS REMAINING.":FORI=0TO1:INPUT"HOW MANY WOULD YOU LIKE TO TAKE?";T%:I=T%>0ANDT%<4:PRINTST$(I):NEXTI:PRINT"ON MY TURN I WILL TAKE "4-T%" TOKENS.":NEXTHEAP</syntaxhighlight>
==={{header|BASIC256}}===
{{works with|BASIC256|1.99.99.14+}}
<syntaxhighlight lang="basic">monton = 12
llevar = 0
while monton > 0
print "There are "; monton; " tokens remaining. How many would you like to take? ";
input integer llevar
while llevar = 0 or llevar > 3
print "You must take 1, 2, or 3 tokens. How many would you like to take ";
input integer llevar
end while
print "On my turn I will take "; 4 - llevar; " token(s)."
monton = monton - 4
end while
print
print "I got the last token. I win! Better luck next time."
end</syntaxhighlight>
==={{header|Craft Basic}}===
Line 928 ⟶ 949:
320 PRINT "You win!"
330 END IF</syntaxhighlight>
==={{header|PureBasic}}===
<syntaxhighlight lang="PureBasic">OpenConsole()
Define monton.i = 12, llevar.i
While monton > 0
Print("There are " + Str(monton) + " tokens remaining. How many would you like to take? ")
llevar = Val(Input())
While llevar = 0 Or llevar > 3
Print("You must take 1, 2, or 3 tokens. How many would you like to take ")
llevar = Val(Input())
Wend
PrintN("On my turn I will take " + Str(4 - llevar) + " token(s).")
monton = monton - 4
Wend
PrintN("I got the last token. I win! Better luck next time.")
PrintN(#CRLF$ + "--- terminado, pulsa RETURN---"): Input()
CloseConsole()</syntaxhighlight>
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<syntaxhighlight lang="qbasic">monton = 12
llevar = 0
DO WHILE monton > 0
PRINT USING "There are ## tokens remaining. How many would you like to take"; monton;
INPUT llevar
DO WHILE llevar = 0 OR llevar > 3
INPUT "You must take 1, 2, or 3 tokens. How many would you like to take"; llevar
LOOP
PRINT "On my turn I will take"; 4 - llevar; " token(s)."
monton = monton - 4
LOOP
PRINT
PRINT "I got the last token. I win! Better luck next time."
END</syntaxhighlight>
==={{header|Run BASIC}}===
{{works with|Just BASIC}}
{{works with|Liberty BASIC}}
<syntaxhighlight lang="vb">monton = 12
llevar = 0
while monton > 0
input "There are "; monton; " tokens remaining. How many would you like to take? "; llevar
while llevar = 0 or llevar > 3
input "You must take 1, 2, or 3 tokens. How many would you like to take "; llevar
wend
print "On my turn I will take "; 4 - llevar; " token(s)."
monton = monton - 4
wend
print
print "I got the last token. I win! Better luck next time."
end</syntaxhighlight>
==={{header|S-Basic}}===
Line 1,107 ⟶ 1,190:
PRINT "Obtuve la última ficha. ¡Gané! Mejor suerte la próxima vez."
END</syntaxhighlight>
==={{header|Yabasic}}===
<syntaxhighlight lang="basic">monton = 12
llevar = 0
while monton > 0
print "There are ", monton, " tokens remaining. How many would you like to take? ";
input "" llevar
while llevar = 0 or llevar > 3
input "You must take 1, 2, or 3 tokens. How many would you like to take? " llevar
wend
print "On my turn I will take ", 4 - llevar, " token(s)."
monton = monton - 4
wend
print "\nI got the last token. I win! Better luck next time."
end</syntaxhighlight>
=={{header|BlooP}}==
|