You are to implement a simulation of the game of Craps utilizing the State design pattern. Players (shooters) rotate rounds, in which a round is played by a single shooter. A round is played in two stages the come out phase and the point phase. A player may win, lose, or establish point in the come outphase. If an establish point occurs in this phase, then the game proceeds to the point phase. The possible outcomes during play of the game is summarized below.
Come Out Phase
Point Phase
In the actual game of Craps, the rounds rotate between any number of players. We will write a program that simulates the playing of rounds for two players, the player and the computer. Given that the rolling of dice will be performed by a call to a random number generator, the only difference between actions of the program for a player vs. the computer is that the player gets to indicate how much they wish to bet, while the computer will randomly generate its bet. At the start of the program, the number of rounds to be played is entered. The program then displays all of the outcomes of play, tallying the total winnings for both the player and computer.
Following the State design pattern to implement the program. The context would be the current point to match in the second Point phase (if a 4,5,6,8,9 or 10 is rolled in the come out phase). In the come out phase, there is not a point value to store, so it can be set to 0 in the context. Thus, the point context in the this problem is similar to the CustomerAccount object of the State pattern given in class (and in the lecture notes). And whereas in the banking problem each state implemented the appropriate actions after a deposit or withdrawal, each state in this problem would simulate what should occur after each roll.
State of game ...
How many rounds would you like to play? 2
Here we go, you are shooting ...
How much would you like to wager this round? 10
I wager $20 (computer)
roll of 5 (point) roll of 6 roll of 8 roll of 7 (craps)
Now its my turn ... roll of 2 (craps)
Your current winnings: -$10
My current winnings: -$20
------------
Here we go, you are shooting ...
How much would you like to wager this round? $20
I wager $15
roll of 7 (natural - win)
Now its my turn ... roll of 9 (point) roll of 6 roll of 8
roll of 9 (hit the point - win)
Your current winnings: $10
My current winnings: -$5
Game Over – Humans Rule!