|
|
|
|
|
|
|
Discussion: We assume that everyone has played this game and understands it. Therefore, our discussion centers on how to simulate the game in a program. |
|
|
|
|
|
|
|
|
For input, we have to use alphanumeric characters to stand for rock, paper, and scissors. We can input R, P, and S and convert the letters to a user-defined enumeration type made up of the literals ROCK, PAPER, and SCISSORS. |
|
|
|
|
|
|
|
|
Each player creates a file composed of a series of the letters R, P, and S, representing a series of individual games. The letters are read, one from each file, and converted into the appropriate enumeration type literals. Let's call each literal a play. The plays are compared, and a winner is determined. The number of games won is incremented for the winning player. The game is over when there are no more plays (the files are empty). |
|
|
|
|
|
|
|
|
Assumptions: The game is over when one of the files runs out of plays. |
|
|
|
|
|
|
|
|
Open data files (and verify success)
Get plays
WHILE NOT EOF on fileA AND NOT EOF on fileB
IF plays are legal
process plays
ELSE
Print an error message
Get plays
Print big winner |
|
|
|
|
|
|
|
|
|
Get Plays (Out: playForA, playForB, legal) Level 1 |
|
|
|
|
|
|
|
|
|
Read charForA (player A's play) from fileA
Read charForB (player B's play) from fileB
IF EOF on fileA OR EOF on fileB
Return
Set legal = (charForA is 'R', 'P', or 'S') AND
(charForB is 'R', 'P', or 'S')
IF legal
Set playForA = ConversionValue(charForA)
Set playForB = ConversionValue(charForB) |
|
|
|
|
|
|
|