21 game: Difference between revisions
Added Arturo implementation
(Added Quackery.) |
Drkameleon (talk | contribs) (Added Arturo implementation) |
||
Line 567:
The first move is Raspberry pi.
</pre>
=={{header|Arturo}}==
<lang rebol>print "-----------------------------"
print " Welcome to 21 Game"
print "-----------------------------"
players: ["A" "B"]
currentPlayer: sample players
nextPlayer: first players -- currentPlayer
runningTotal: new 0
num: 0
getNum: function [][
result: strip input "Enter a number (1,2,3) / x to exit: "
if result="x" -> exit
return result
]
loop.forever @[currentPlayer nextPlayer] 'plays [
print ["Running total:" runningTotal]
print ["Player" plays "turn"]
num: getNum
while [or? [not? numeric? num][not? contains? 1..3 to :integer num]][
num: getNum
]
runningTotal: runningTotal + to :integer num
print ""
if runningTotal=21 [
print ["Running total is 21. Player" plays "won!"]
exit
]
]
</lang>
{{out}}
<pre>-----------------------------
Welcome to 21 Game
-----------------------------
Running total: 0
Player B turn
Enter a number (1,2,3) / x to exit: 1
Running total: 1
Player A turn
Enter a number (1,2,3) / x to exit: 2
Running total: 3
Player B turn
Enter a number (1,2,3) / x to exit: 1
Running total: 4
Player A turn
Enter a number (1,2,3) / x to exit: 3
Running total: 7
Player B turn
Enter a number (1,2,3) / x to exit: 4
Enter a number (1,2,3) / x to exit: 2
Running total: 9
Player A turn
Enter a number (1,2,3) / x to exit: 3
Running total: 12
Player B turn
Enter a number (1,2,3) / x to exit: 1
Running total: 13
Player A turn
Enter a number (1,2,3) / x to exit: 2
Running total: 15
Player B turn
Enter a number (1,2,3) / x to exit: 3
Running total: 18
Player A turn
Enter a number (1,2,3) / x to exit: 3
Running total is 21. Player A won!</pre>
=={{header|AutoHotkey}}==
<lang AutoHotkey>Gui, font, S16
|