21 game: Difference between revisions
Added Quackery.
(Add F# version) |
(Added Quackery.) |
||
Line 4,865:
root.mainloop()
</lang>
=={{header|Quackery}}==
<lang Quackery> [ say
"Who goes first: Computer, Player"
say " or Random?" cr
[ $ "Enter C, P or R: " input
dup size 1 != iff drop again
0 peek
dup char C = iff [ drop 0 ] done
dup char P = iff [ drop 1 ] done
char R = iff [ 2 random ] done
again ]
cr
dup iff [ say "You go first." ]
else [ say "I will go first." ]
cr ] is chooseplayer ( --> n )
forward is player ( n --> n x )
[ [ dup 17 > iff 1 done
4 over 4 mod
dup 0 = if [ drop 3 ]
- ]
dup say "Computer chooses " echo
say "." cr
+ ' player ] is computer ( n --> n x )
[ say "Choose 1 2 or 3 (running "
$ "total must not exceed 21, Q to quit): " input
dup $ "Q" = iff [ drop 21 999 ] done
trim reverse trim reverse
$->n not iff drop again
dup 1 4 within not iff drop again
2dup + 21 > iff drop again
+ ' computer ] resolves player ( n --> n x )
[ say "The player who makes 21 loses." cr
0 chooseplayer
iff [ ' player ] else [ ' computer ]
[ say "Running total is "
over echo say "." cr cr
do
over 21 = until ]
cr
dup 999 = iff
[ drop 2drop say "Quitter!" ] done
' computer = iff
[ say "The computer won!" ]
else [ say "You won! Well done!" ]
drop ] is play ( --> )</lang>
{{out}}
As a dialogue in the Quackery shell.
<pre>/O> play
...
The player who makes 21 loses.
Who goes first: Computer, Player or Random?
Enter C, P or R: C
I will go first.
Running total is 0.
Computer chooses 1.
Running total is 1.
Choose 1 2 or 3 (running total must not exceed 21, Q to quit): Q
Quitter!
Stack empty.
/O> play
...
The player who makes 21 loses.
Who goes first: Computer, Player or Random?
Enter C, P or R: R
You go first.
Running total is 0.
Choose 1 2 or 3 (running total must not exceed 21, Q to quit): 2
Running total is 2.
Computer chooses 2.
Running total is 4.
Choose 1 2 or 3 (running total must not exceed 21, Q to quit): 3
Running total is 7.
Computer chooses 1.
Running total is 8.
Choose 1 2 or 3 (running total must not exceed 21, Q to quit): 1
Running total is 9.
Computer chooses 3.
Running total is 12.
Choose 1 2 or 3 (running total must not exceed 21, Q to quit): 4
Choose 1 2 or 3 (running total must not exceed 21, Q to quit): 1
Running total is 13.
Computer chooses 3.
Running total is 16.
Choose 1 2 or 3 (running total must not exceed 21, Q to quit): 3
Running total is 19.
Computer chooses 1.
Running total is 20.
Choose 1 2 or 3 (running total must not exceed 21, Q to quit): 2
Choose 1 2 or 3 (running total must not exceed 21, Q to quit): 1
The computer won!
Stack empty.
/O> </pre>
=={{header|R}}==
|