Have you ever tried to solve a dispute via Rochambeau (a.k.a. rock-paper-scissors)? Have you lost the game, only to exclaim, "No, wait, best 2 out of 3!". In this project, we're going to take Romcambeau to new heights (or depths, depending on your perspective) by imposing an elaborate scoring scheme.
You may wonder, "What kind of scoring scheme?" It's one with which you may be familiar: tennis scoring. Each rochambeau contest will merely amount to scoring a single point. A certain number of points will win a game, enough games will win a set, and enough sets will win the match.
Your assignment is a write a program that will play a complete, tennis-scored, Rochambeau match against you. The program must make its own rock-paper-scissors selections as it plays against you, and the program must keep score (correctly!).
You should implement the parts of this problem in a specific order given below, in the Your assignment section. So, be sure to read the entire assignment before beginning work.
For consistency, we outline the complete scoring system, including what must occur for a player to win a point, game, set, and match:
Point: A point is scored when one player wins a Rochambeau round. Specifically, both the user and the computer select either rock, paper or scissors. If both player select the same item, the result is a tie and the round must be replayed.
Player A will win the round over player B (and thus the point) under the following circumstances:
Game: Both players begin with Love (that is, zero). With each point earned, a player's score increases as follows:
That is, a player must score (at least) four points to win the game. However, if both players reach 40, the score becomes deuce. At this point, a player must win two points in a row to win the game. Specifically, if the score is deuce and player A wins a point, then player A has the advantage -- that is, player A will win the game if she wins the next point. However, if player A has the advantage and player B wins the next point, the score returns to deuce.
Set: To win a set, a player must win at least 6 games and must lead the other player by at least two games. Note that in many real tennis matches, a tiebreaker is played when each player has won 6 games. We will ignore this detail.
Match: To win a match, a player must win 3 sets.
Note that a full Rochambeau match, as described above, has many layers and involves a large number of rules. By way of discouraging you from trying to write a program to play a complete match on your first try, I provide some information on the grading of this assignment.
If you implement a program that plays a single Rochambeau point -- that is, repeated rounds until one player wins a round -- then the highest grade you can receive is a B. Since this portion of the program is critical, I strongly recommend that you write, compile, and debug it first.
If you implement a program that plays a single Rochambeau game -- that is, Rochambeau points scored like a tennis game -- then the highest grade you can receive is an A-. Write this part of the program only after you have successfully implemented a point-playing program.
If you successfully implement a Rochambeau set, then your grade will be at most an A, and if you implement a match, your grade will be at most an A+. Thus, you should implement this program from the inside out. By submitting a program that successfully implements some of the inner layers of the game, you will receive substantial credit even though the full assignment has not been completed. Note that you can also not only write each layer, but you can compile and debug it before moving on to the next one, thus ensuring that you've written code that will earn a large portion of the possible credit.
One final requirement: Your program must provide a good interface to the user, presenting useful prompts, robustly responding to invalid inputs, and informing the user of the progress of the game. Here is a sample transcript of a game:
(romulus)[274]~/project-1% java RochambeauMatch You: 0 sets Me: 0 sets You: 0 games Me: 0 games You: Love Me: Love (r)ock, (p)aper, or (s)cissors? q q is not a valid choice, try again (r)ock, (p)aper, or (s)cissors? p I chose rock You chose paper Paper covers rock! You win. You: 15 Me: Love (r)ock, (p)aper, or (s)cissors? r I chose scissors You chose rock Rock smashes scissors! You win. You: 30 Me: Love (r)ock, (p)aper, or (s)cissors? r I chose rock You chose rock It's a tie -- redo! (r)ock, (p)aper, or (s)cissors? r I chose paper You chose rock Paper covers rock! I win. You: 30 Me: 15 (r)ock, (p)aper, or (s)cissors? r I chose paper You chose rock Paper covers rock! I win. You: 30 Me: 30 (r)ock, (p)aper, or (s)cissors? r I chose paper You chose rock Paper covers rock! I win. You: 30 Me: 40 (r)ock, (p)aper, or (s)cissors? r I chose paper You chose rock Paper covers rock! I win. Game: me You: 0 games Me: 1 games You: Love Me: Love (r)ock, (p)aper, or (s)cissors? r I chose scissors You chose rock Rock smashes scissors! You win. You: 15 Me: Love (r)ock, (p)aper, or (s)cissors? r I chose rock You chose rock It's a tie -- redo! (r)ock, (p)aper, or (s)cissors? r I chose rock You chose rock It's a tie -- redo! (r)ock, (p)aper, or (s)cissors? r I chose paper You chose rock Paper covers rock! I win. You: 15 Me: 15 (r)ock, (p)aper, or (s)cissors? r I chose scissors You chose rock Rock smashes scissors! You win. You: 30 Me: 15 (r)ock, (p)aper, or (s)cissors? r I chose rock You chose rock It's a tie -- redo! (r)ock, (p)aper, or (s)cissors? r I chose rock You chose rock It's a tie -- redo! (r)ock, (p)aper, or (s)cissors? r I chose rock You chose rock It's a tie -- redo! (r)ock, (p)aper, or (s)cissors? r I chose paper You chose rock Paper covers rock! I win. You: 30 Me: 30 (r)ock, (p)aper, or (s)cissors? r I chose rock You chose rock It's a tie -- redo! (r)ock, (p)aper, or (s)cissors? r I chose scissors You chose rock Rock smashes scissors! You win. You: 40 Me: 30 (r)ock, (p)aper, or (s)cissors? r I chose rock You chose rock It's a tie -- redo! (r)ock, (p)aper, or (s)cissors? r I chose rock You chose rock It's a tie -- redo! (r)ock, (p)aper, or (s)cissors? r I chose paper You chose rock Paper covers rock! I win. Deuce (r)ock, (p)aper, or (s)cissors? r I chose scissors You chose rock Rock smashes scissors! You win. Your advantage (r)ock, (p)aper, or (s)cissors? r I chose rock You chose rock It's a tie -- redo! (r)ock, (p)aper, or (s)cissors? r I chose paper You chose rock Paper covers rock! I win. Deuce (r)ock, (p)aper, or (s)cissors? r I chose rock You chose rock It's a tie -- redo! (r)ock, (p)aper, or (s)cissors? r I chose paper You chose rock Paper covers rock! I win. My advantage (r)ock, (p)aper, or (s)cissors? r I chose rock You chose rock It's a tie -- redo! (r)ock, (p)aper, or (s)cissors? r I chose paper You chose rock Paper covers rock! I win. Game: me You: 0 games Me: 2 games You: Love Me: Love
In fact, it is likely that you could improve on the interface shown above, so take that only as an example of something that is acceptable.
For the computer to select rock, paper, or scissors, it must, of course, make its own, random selection. There is a method that you can call to obtain a random value, and you would use it like so:
double randomValue = Math.random()
That is, Math.random() is a method that returns a double whose value is between 0.0 and 0.99999... You can use this randomly provided value to drive the computer's random selection at each turn.
When your work is complete, you should submit it using the cs11-submit command, like so:
cs11-submit project-1 RochambeauMatch.java