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 raise Romcambeau to a new level (or lower it, 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 2 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, the project will be split into two portions, each with its own due date:
Part A: You must write a method that plays a single Rochambeau point. That is, you should first write a method that can play a single round. Then, you should write a method that plays a single point by calling on the method than plays a point by calling repeatedly on the method that plays a round until one player wins. These methods, taken together, should be made into its own program.
This part is due on Friday, 2005-Oct-7, at 11:59 pm.
Part B: Write a method that plays a game by calling on the method that plays a point. Then, write a method for playing a set which calls on the game-playing method, and write a method that plays a match based on the set-playing method. Taken together, these are a program that plays a full Rochambeau match.
This part is due on Tuesday, 2005-Oct-18, at 11:59 pm.
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 excerpted transcript of a full match:
(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