Rock-paper-scissors: Difference between revisions
Algol 68 - Slight simplifications
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: fix whitespace syntax errors) |
(Algol 68 - Slight simplifications) |
||
Line 258:
=={{header|ALGOL 68}}==
<lang algol68>BEGIN
# rock/paper/scissors game #
# counts of the number of times the player has chosen each move #
# we initialise each to 1 so that the total isn't zero when we are #
# choosing the computer's first move (as in the Ada version) #
INT r count := 1;
INT p count := 1;
INT s count := 1;
# counts of how many games the player and computer have won #
INT
INT
print( ( "rock/paper/scissors", newline, newline ) );
WHILE
# get the players move - r => rock, p => paper, s => scissors #
# q => quit #
WHILE
print( ( "Please
AND player move /= "
AND player move /= "q"
)
DO
print( ( "Unrecognised move", newline ) )
OD;
# continue playing until the player chooses quit #
player move /= "q"
DO
CHAR computer move;
INT move count = r count + p count + s count;
# is in the range 0 .. rock / total #
# predict player will play paper if the random number #
# is in the range rock / total .. ( rock + paper ) / total #
# predict player will play scissors otherwise #
REAL r limit = r count / move count;
REAL p limit = r limit + ( p count / move count );
IF random move < r limit THEN
computer move := "p"
ELSE
#
computer move := "r"
FI;
print( ( "You chose: " + player move, newline ) );
print( ( "I chose: " + computer move, newline ) );
IF player move = computer move THEN
# both players chose the same - draw #
print( ( "
ELSE
# players chose different moves - there is a winner #
IF player move = "r" THEN
# player chose rock - rock blunts scissors #
computer move = "s"
ELIF player move = "p" THEN
# player chose paper - paper wraps rock #
computer move = "r"
ELSE
# player chose scissors - scissors cut paper #
computer move = "p"
FI;
IF player wins THEN
player count +:= 1;
print( ( "You win", newline ) )
ELSE
computer count +:= 1;
print( ( "I win", newline ) )
FI;
print( ( "You won: "
, whole( player count , 0 )
, ", I won: "
, whole( computer count, 0 )
, newline
)
)
FI;
IF player move = "r" THEN
# player chose rock #
r count +:= 1
ELIF player move = "p" THEN
# player chose paper #
p count +:= 1
ELSE
# player chose scissors #
s count +:= 1
FI
OD;
print( ( "Thanks for a most enjoyable game", newline ) )
END</lang>
=={{header|AutoHotkey}}==
<lang AHK>DllCall("AllocConsole")
|