Your task is to design and code a partial implementation of the dice game Craps. In Craps there are several (many?) different kinds of bets that can be made on the outcome of a sequence of rolls of 2 dice. In Exercise 1, you will be implementing just 2 kinds of line bets: the "pass line" and the "come" bet. In Exercise 2, you will add odds bets on both the pass line and come bets.
See the following links for more informaton on the rules and play of the game ...
Each player starts with some initial amount of chips - representing some number of dollars. Bets will be placed in even dollar amounts. The application will keep a running total of each player's chips.
The game consists of a sequence of rounds. For each round, one of the players acts as the shooter. (S/he rolls the 2 dice.) At the end of each round, the shooter may choose to pass the dice to the next player - unless s/he "7's out". In that case, the shooter must pass the dice to then next shooter. (I think that this suggests that the collection of players is stored as a list. The initial shooter will be the first person in the list.)
The shooter must make a pass line bet before rolling the dice. This first roll of the round is know as the come-out roll. Other players may also bet on this come out roll.
For the come-out roll there are 3 cases:
Note that a round ends when the result of the shooter's pass line bet is determined.
All of this suggests that a round is in one of 3 possible states:
We should be able to draw the appropriate state transition diagram!
If the shooter has set a point, any player may make a come bet on his/her next roll - as if it was a come-out roll. A come bet is treated exactly the same as a pass line bet: it wins if the next roll is 7 or 11, loses if the next roll is 2, 3, or 12, and has a point set otherwise.
So it is posssible in an extreme case for a player to have simultaneously a pass line bet and 5 come bets, all "waiting for" different points.
Note that pass line bets are always decided at the end of a round, but come bets might be decided in a subsequent round perhaps with a different shooter.
For now the game will be run using either a hard-coded sequence of functions calls - or a simiple keyboard interface. (We can hold out hope for a GUI interface later in the course.) This interface will accept the following types of commands:
For simplicity, you can just ignore invalid input (except as indicated above) - since this keyboard interface is intended to drive the application logic for development purposes, not support real users.
Note ...
Let's say Bob - the shooter - bets $10 on the pass line. On his come-out roll, he rolls an 11, so he win $10.
Bob now "starts another round", with a $15 bet on his new come-out roll. He rolls a 9, which becomes the point.
Adam decides to place a $10 come bet before the next roll.
On the roll Bob gets a 6, which now becomes the point Adam needs in order to win his $10 come bet.
The next roll is a 9. Bob wins $15 on his $15 pass line bet.
Bob bets $25 on the pass line again, and his new come-out roll is a 7. He win $25 for his pass line bet. Adam loses his $10 come line bet.
Obviously, roll() should generate a random total by rolling 2 dice. However in developing this application, it very useful to have a roll(int x) method to allow us to specify the next roll for testing purposes. Let's do that - and just agree that roll(0) will mean roll().
Implement Odds bets. Any player may place or change an Odds bet on a point (4, 5, 6, 8, 9 or 10) before any roll - if s/he already has a line bet on that point. (An Odds bet is the bet with the smallest edge for the house / casino.)
Your CrapsGame controller will need to handle 2 additional commands: placeOddsBet(player, point, amount) and changeOddsBet(player, point, amount)
An Odds bet wins if the point is rolled again before a 7 is rolled, and pays at the true odds of 2-to-1 if 4 or 10 is the point, 3-to-2 if 5 or 9 is the point, and 6-to-5 if 6 or 8 is the point. For example, a player with a $10 Odds bet on 5 will win $20 on the Odds bet (and get the orginal $10 back) if the shooter rolls a 5. (S/he also wins the LineBet on 5.) If the payoff is not an even number, it is rounded down in the casino's favour, of course.
Note that this "added wrinkle" will be worth only a couple of marks!
With a come bet, if the shooter makes their point, a player can find themselves in the situation where they have a come bet (possibly with odds on it) and the next roll is a come-out roll. In this situation odds bets on the come bets are presumed to be not working for the come-out roll. That means that if the shooter rolls a 7 on the come-out roll, any players with active come bets (waiting for a "come-point") will lose their initial bet but will have their odds bets returned to them. If the come-point is rolled, then the come bet wins, and the odds bets are returned. Otherwise, the Odds bet is working on the next (non-come-out) roll.
This assignment is due at the beginning of the Tuesday lab class in 2 weeks (March 20) at 3:30 p.m. - and the submit program will enforce this.
I will be compiling and executing your code with main's similar to - or perhaps even identical to - the Test*.java classes in the lab6 directory. I hope your code works!