Rock-paper-scissors: Difference between revisions
Content added Content deleted
(→{{header|Vlang}}: Rename "Vlang" in "V (Vlang)") |
(Added Quackery.) |
||
Line 4,856: | Line 4,856: | ||
NPC = randint(0, 2) |
NPC = randint(0, 2) |
||
print('The computer played ' + hands[NPC] + '; ' + judge[YOU-NPC])</syntaxhighlight> |
print('The computer played ' + hands[NPC] + '; ' + judge[YOU-NPC])</syntaxhighlight> |
||
=={{header|Quackery}}== |
|||
<syntaxhighlight lang="Quackery"> |
|||
[ 0 ] is rock ( --> n ) |
|||
[ 1 ] is paper ( --> n ) |
|||
[ 2 ] is scissor ( --> n ) |
|||
[ $ "Choose rock, paper or scissors: " |
|||
input cr |
|||
trim reverse trim reverse |
|||
$ "" swap witheach [ lower join ] |
|||
dup $ "rock" = iff |
|||
[ drop rock ] done |
|||
dup $ "paper" = iff |
|||
[ drop paper ] done |
|||
$ "scissors" = iff |
|||
scissor done |
|||
again ] is player ( --> n ) |
|||
[ stack 1 ] is rocks ( --> s ) |
|||
[ stack 1 ] is papers ( --> s ) |
|||
[ stack 1 ] is scissors ( --> s ) |
|||
[ 1 swap |
|||
[ table rocks papers scissors ] |
|||
do tally ] is notechoice ( n --> ) |
|||
[ 0 ' [ rocks papers scissors ] |
|||
witheach [ share + ] |
|||
random |
|||
dup rocks share < iff |
|||
[ drop paper ] done |
|||
rocks share - |
|||
papers share < iff |
|||
scissor done |
|||
rock ] is computer ( --> n ) |
|||
[ say "Computer chose " |
|||
[ table rock paper scissors ] |
|||
echo say "." cr ] is echomove ( n --> ) |
|||
[ [ table |
|||
[ table 0 1 2 ] |
|||
[ table 2 0 1 ] |
|||
[ table 1 2 0 ] ] do ] is result ( n n --> n ) |
|||
[ [ table |
|||
$ "It's a draw." |
|||
$ "Computer wins." |
|||
$ "Player wins." ] |
|||
do echo$ cr cr ] is announce ( n --> ) |
|||
[ stack 0 ] is draws ( --> s ) |
|||
[ stack 0 ] is cwins ( --> s ) |
|||
[ stack 0 ] is pwins ( --> s ) |
|||
[ [ table draws cwins pwins ] |
|||
1 swap tally ] is keepscore ( n --> ) |
|||
[ say "Computer: " cwins share echo |
|||
say " Player: " pwins share echo |
|||
say " Draws: " draws share echo |
|||
cr cr ] is scoreboard ( --> ) |
|||
[ ' [ rocks papers scissors ] |
|||
witheach [ 1 swap replace ] |
|||
' [ draws cwins pwins ] |
|||
witheach [ 0 swap replace ] ] is initialise ( --> ) |
|||
[ 0 |
|||
[ drop |
|||
$ "How many games? " input |
|||
trim reverse trim reverse |
|||
$->n until ] |
|||
cr ] is games ( --> n ) |
|||
[ initialise |
|||
games times |
|||
[ computer |
|||
player dup notechoice |
|||
over echomove |
|||
result dup announce |
|||
keepscore |
|||
scoreboard ] ] is play ( --> )</syntaxhighlight> |
|||
{{out}} |
|||
As a dialogue in the Quackery shell. |
|||
<pre>/O> play |
|||
... |
|||
How many games? 3 |
|||
Choose rock, paper or scissors: rock |
|||
Computer chose rock. |
|||
It's a draw. |
|||
Computer: 0 Player: 0 Draws: 1 |
|||
Choose rock, paper or scissors: paper |
|||
Computer chose scissors. |
|||
Computer wins. |
|||
Computer: 1 Player: 0 Draws: 1 |
|||
Choose rock, paper or scissors: scissors |
|||
Computer chose paper. |
|||
Player wins. |
|||
Computer: 1 Player: 1 Draws: 1 |
|||
Stack empty. |
|||
/O></pre> |
|||
=={{header|R}}== |
=={{header|R}}== |