Rock-paper-scissors: Difference between revisions

Added an Algol 68 implementation
(Updated first D entry)
(Added an Algol 68 implementation)
Line 243:
}</lang>
 
=={{header|ALGOL 68}}==
{{works with|ALGOL 68G|Any - tested with release 2.6.win32}}
<lang algol68>main: (
 
# 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 player count := 0;
INT computer count := 0;
 
print( ( "rock/paper/scissors", newline, newline ) );
 
WHILE
 
CHAR player move;
 
# get the players move - r => rock #
# p => paper #
# s => scissors #
# q => quit #
 
WHILE
print( ( "Please enter your move (r/p/s) or q to quit: " ) );
readf( ( $ a $, player move ) );
read( ( newline ) );
 
( player move /= "r"
AND player move /= "p"
AND player move /= "s"
AND player move /= "q"
)
DO
print( ( "Unrecognised move", newline ) )
OD;
 
# continue playing until the player chooses quit #
player move /= "q"
 
DO
 
# decide the computer's move based on the player's history #
 
CHAR computer move;
 
INT move count = r count + p count + s count;
 
# predict player will play rock if the random number #
# 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 );
 
REAL random move = next random;
 
IF random move < r limit
THEN
# we predict the player will choose rock - we choose paper #
computer move := "p"
 
ELIF random move < p limit
THEN
# we predict the player will choose paper - we choose scissors #
computer move := "s"
 
ELSE
# we predict the player will choose scissors - we choose rock #
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( ( "We draw", newline ) )
 
ELSE
# players chose different moves - there is a winner #
 
BOOL player wins;
 
IF player move = "r"
THEN
# player chose rock - rock blunts scissors #
# but is wrapped by paper #
player wins := ( computer move = "s" )
 
ELIF player move = "p"
THEN
# player chose paper - paper wraps rock #
# but is cut by scissors #
player wins := ( computer move = "r" )
 
ELSE
# player chose scissors - scissors cut paper #
# but are blunted by rock #
player wins := ( 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 ) )
 
)
</lang>
=={{header|AutoHotkey}}==
<lang AHK>DllCall("AllocConsole")
Line 289 ⟶ 445:
FileAppend, % txt, CONOUT$
}</lang>
 
=={{header|AutoIt}}==
 
3,048

edits