Anonymous user
Rock-paper-scissors: Difference between revisions
m
→{{header|Perl 6}}: typos, whitespace, unicode
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Added perl 6 example) |
m (→{{header|Perl 6}}: typos, whitespace, unicode) |
||
Line 680:
=={{header|Perl 6}}==
This is slightly more complicated than it could be; it is a general case framework with input filtering. It weights the computers choices based on your previous choices. Type in at least the first two characters of your choice, or just hit enter to quit. Customize it by supplying your own <tt>%vs</tt> options/outcomes.
Here is standard Rock-Paper-Scissors.
Line 689:
ro => [ 2, '' ],
pa => [ 1, 'Paper covers Rock: ' ],
sc => [ 0, 'Rock smashes
},
pa => {
Line 697:
},
sc => {
ro => [ 1, 'Rock smashes
pa => [ 0, 'Scissors cut Paper: ' ],
sc => [ 2, '' ]
Line 706:
my $keys = %choices.keys.join('|');
my $prompt = %vs<options>.map({$_.subst(/(\w\w)/,->$/{"[$0]"})}).join(' ')~"? ";
my %weight = %choices.keys
my @stats = 0,0,0;
Line 713:
while my $player = (prompt "Round {++$round}: " ~ $prompt).lc {
$player.=substr(0,2);
say '
unless $player.chars == 2 and $player ~~ /<$keys>/;
my $computer = %weight.keys.map( { $_ xx %weight{$_} } ).pick;
Line 724:
say " - (W:{@stats[0]} L:{@stats[1]} T:{@stats[2]})\n",
};</lang>Example output:
<pre>Round 1: [Ro]ck [Pa]per [Sc]issors? ro▼
▲Round 1: [Ro]ck [Pa]per [Sc]issors? ro
You chose Rock, Computer chose Paper.
Paper covers Rock: You Lose! - (W:0 L:1 T:0)
Line 744 ⟶ 743:
You chose Scissors, Computer chose Scissors.
Tie. - (W:0 L:3 T:2)
...</pre>
Here is example output from the same code only with a different %vs data structure implementing [http://en.wikipedia.org/wiki/Rock-paper-scissors-lizard-Spock Rock-Paper-Scissors-Lizard-Spock].
Line 754 ⟶ 752:
ro => [ 2, '' ],
pa => [ 1, 'Paper covers Rock: ' ],
sc => [ 0, 'Rock smashes
li => [ 1, 'Rock crushes Lizard: ' ],
sp => [ 0, 'Spock vaporizes Rock: ' ]
Line 766 ⟶ 764:
},
sc => {
ro => [ 0, 'Rock smashes
pa => [ 1, 'Scissors cut Paper: ' ],
sc => [ 2, '' ],
Line 788 ⟶ 786:
);</lang>
<pre>Round 1: [Ro]ck [Pa]per [Sc]issors [Li]zard [Sp]ock? li▼
▲Round 1: [Ro]ck [Pa]per [Sc]issors [Li]zard [Sp]ock? li
You chose Lizard, Computer chose Scissors.
Scissors decapitate Lizard: You Lose! - (W:0 L:1 T:0)
Line 803 ⟶ 800:
Round 4: [Ro]ck [Pa]per [Sc]issors [Li]zard [Sp]ock? ro
You chose Rock, Computer chose Scissors.
Rock smashes
Round 5: [Ro]ck [Pa]per [Sc]issors [Li]zard [Sp]ock? li
You chose Lizard, Computer chose Paper.
Lizard eats Paper: You win! - (W:2 L:3 T:0)
...</pre>
=={{header|Python}}==
|