CPS 108 : Re-designing Programs


For this problem you will form groups of size three or four persons. You may not work alone! You should start each group activity by introducing yourself to each member of the group. You may also want to choose one person to write down the group's discussion on the provided index cards as you go.

This project is intended to get you to practice some of the programming and design techniques discussed in class recently (i.e., using the open/closed principle to add flexibility to your code and building frameworks that allow others to extend your code in specific ways). Your group should examine the code given and determine how to redesign it to make the code simpler and more flexible. You should present your design using CRC cards and as well as a class interaction diagram. After each group is finished, you may be called on to defend your design in front of your classmates.

Specification

This program simulates a game of roulette. In roulette, a wheel spins and yields a number between 1 and 36 when a ball drops into a numbered slot. There are also slots numbered 0 and 00. These slots are green and each of the other slots is red or black. For the purposes of this program, assume that all odd numbers are black and all even numbers are red. In the real game, the colors black and red are distributed differently, but we will ignore that for the purposes of this program. Additionally, 0 and 00 are not considered either even or odd.

In Las Vegas style rules, gamblers can make several different kinds of bets, each of which pays off differently as listed in the table below.  These payoffs are close to the real mathematical odds of getting such a spin, but slightly lower to allow the casino to make a profit on average.
 

Bet
Payoff
Red/Black
1 to 1
Odd/Even
1 to 1
Single number
35 to 1
Two consecutive numbers
17 to 1
Three consecutive numbers
11 to 1
 
A payoff of 1 to 1 pays even money: a bet of  $10.00 earns the gambler $10.00 if the bet wins.  On the other hand, a payoff of 17 to 1 means that a bet of $10.00 earns the gambler $170.00.  If the gambler loses, no money is paid out and the bet is kept by the casino.

Input/Output

Your program should prompt the user for an initial amount of money, the user's bankroll. The user should then be given the opportunity to make one of three different bets, or to quit the program. You are required to implement the first three bets in the table above; you can implement the last two bets for one point of extra credit each.  Initially you should present the user with a menu similar to the list below: Then, for each bet, you should prompt the user for information specific to that bet.  For example, if the user chooses to bet on a specific number, you should prompt the user to enter the number.  It is fine to represent the number "00" as "37".

The first two bets pay even money: a bet of $5.00 earns $5.00 if the bet wins. Winning a bet on a specific number pays 35 * b where b is the bet. Thus a winning bet of $4.00 earns $140.00. A winning bet earns back the money bet so that betting $10.00 on red and winning means that you get back $20.00 --- the original wager plus the even money winnings, or 10 + 10 = 20.

The user should be allowed to bet any positive amount not exceeding the bankroll. After each bet, the bankroll should be updated appropriately and the new total reported to the user. If the user runs out of money, the program should stop.

Current Code

Questions

Here are some questions you should consider in order to refactor the given code:

  1. What would need to change in order to add a new kind of bet to the system?
  2. What would need to change in order to add a graphical user interface to the system (note, the particulars of how the GUI looks is not important in answering this question (why?))?
  3. What would need to change in order to support multiple players playing the same series of games?
  4. What would need to change in order to support multiple roulette games being played simultaneously?
  5. What would need to change in order to make this one game in a series of table games offered by an online casino (note, think about what part of the code can be reused in other games versus what is specific to this game)?

Comments?