In this lab you will simulate two players: one plays randomly while the other rotates faithfully from rock to paper to scissors. Your task is to simulate this game and to report the fraction of games won by each of the two players.
Update your workspace as usual, and find the lab2 package in the labs source folder. Create a new class RPS there, and you are ready to begin your development.
It is suggested that you develop code in small steps, so that you can proceed from confidence to confidence, and not have a big pile of untested code to debug at the end.
To help motivate this approach, the TAs will not help you unless you have shown progress based on these steps. Ask for help as soon as you need it, but please follow the steps below so that you can gain confidence.
The steps you might consider are as follows:
This means that you should type in the code to prompt the user for the input(s), print out the values of those inputs, and that's all for now. Run your proram at this point and make sure it is behaving as you want.
What inputs do you need? There's no reason to ask for more than is necessary. At a minimum, you have to know how many rounds of RPS to play before printing the resulting statistics.
Again, run your program. You may want to print something out in your loop so you can verify that the loop works correctly.
What is the concept of the player? There are many details about the player that appear unnecessary: the player's name, address, cell phone number.
On the other hand, if we are going to play RPS, we need to know what move the player has made. This is the important concept.
How do we represent the choice of rock, paper, or scissors? This is left up to you, so try for something simple. It may help to recall how Paul Revere was (poetically) told of how the British were coming: one if by land, two if by sea.
In otherwords, an int encoded the manner of invasion.If there were only two choices, why didn't Paul use a boolean? Sadly, Bool was not yet born.
You've seen how to use the random number generator to pick between two outcomes. Now you must pick between three.
In the interest of consistency and simplicity, you should use the same encoding for this player in terms of what value means rock, what value means paper, what value means scissors.
To verify the cycling player's behavior, you will probably want to print out the values representing that player's move each iteration.
It won't take many iterations to see if this is working or not: 10 should do.
Why do we need a variable to keep track of each player's wins? Why not keep track of only one player's wins and assume the other player won the other rounds?
Use the rules of RPS to adjudicate the winner, and credit the win count properly.
When you done with this lab, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches