Learning Center
Plans & pricing Sign in
Sign Out



									Lab Week 5: Section 2
In this lab, you will make a computer game in which two players compete against each other in Rock-
Paper-Scissors game.

Rock-Paper-Scissors is a two-person hand game. It is often used as a selection method in a similar way
to coin flipping or drawing straws to randomly select a person for some purpose.1

A screen shot of the game is given below, and you can get a sense of the game by running rps.exe file
in your lab folder.

Figure: Screen shot of the game in progress, with the Player 2 in the lead

The basic rules of the game are as follows. Each player randomly selects either Rock, or Paper or
Scissors. If both players select the same thing, the round is a draw. However, if they select different
things, then certain rules apply:

       Player 1                  Player 2                     Result
       Rock                      Paper                        Player 2 wins, because paper covers rock
       Rock                      Scissors                     Player 1 wins, because rock breaks scissors
       Paper                     Scissors                     Player 2 wins, because scissors cut paper
       Paper                     Rock                         Player 1 wins because paper covers rock
       Scissors                  Rock                         Player 2 wins because rock breaks scissors
       Scissors                  Paper                        Player 1 wins because scissors cut paper

When the “Play” button is pressed, both players will select one of rock/paper/scissors at random. The
result will be decided according to the rules above. If it is a draw, the score of the players is not
incremented, otherwise which ever player wins will get one additional point.

1   Wikipedia:,_Paper,_Scissors
It is useful to take a bigger program like this and break it into smaller chunks. You should
demonstrate your progress to the TAs in two steps.
        First make the basic functionality of making rock, paper or scissors at random for each player,
        when the “Play” button is pressed. Do not worry about finding out who wins a round, and
        keeping score for this task. Show this to a TA before proceeding further.
        After this, add the scoring functionality to your program. For each round, you will have to
        determine who won (or the round was a draw), and increment the score of the winner.

1.   You can keep a variable for each player which stores the item the player is assigned. This variable
     should be assigned a random number in each round, i.e. either 0, 1, or 2, with equal probability.
     Each value denotes one of the three states, rock, paper or scissors.
2.   Based on the variable mentioned above for each player, appropriate drawing should be made. So
     if the variable value was 0, rock should be drawn, if it is 1, paper should be drawn and so on.
3.   You can also keep a separate variable to keep score of each player.
4.   A series of IF conditions will be needed to determine which player won the round. The score of
     that player should then be incremented.

Add end-game conditions to the code. The first player to reach 10 points should be declared the
winner of the game. After that, pressing the “Play” button should not do anything further.

To top