CSC 222: Object-Oriented Programming
Spring 2017

HW 2: Repetition and Simulations

For this assignment, you will utilize an existing class and implement a new class for simulating a game of roulette. Using these classes and a third provided class, you will perform repeated simulations of your roulette game and study the effectiveness of various betting strategies. In doing so, you will experience the power of software models in studying the behavior of real-world systems.

Part 1: Uniform Betting

The RouletteWheel class models an American-style roulette wheel, with slots numbered 1 through 36 and two additional slots, numbered 0 and 00. This class has a method for generating a random spin and additional methods for determining the color and parity of a number on the wheel.

Utilizing the RouletteWheel class, you are to implement a class named RouletteGame that enables the user to play a game of roulette. The user can specify three types of bets, either odd/even, red/black, or a specific number (1-36). A RouletteGame javadoc file is provided for you to define the methods of this class and their precise behavior. Implement this class so that it meets the specifications in the javadoc file. Be sure to test your implementation carefully.

Once you are confident that your RouletteGame class behaves as specified, download the RouletteTester class and add it to your BlueJ project. This class contains static methods for simulating rounds of bets (where a round consists of a set number of the same type of bets), as well as one for simulating repeated rounds and displaying statistics.

Use the playStats to simulate 100,000 rounds of roulette bets using different bet types and varying numbers of bets per round. Fill in the following table with your generated statistics. Note that each entry in the table should consist of three numbers (separated by vertical bars): the percentage of rounds that resulted in the player losing money, the average amount lost per round, and the maximum amount lost in a round.

bet type25 bets
loss % | avg loss | max loss
50 bets
loss % | avg loss | max loss
100 bets
loss % | avg loss | max loss
200 bets
loss % | avg loss | max loss
red ||||||||
odd ||||||||
7 ||||||||

Based on the statistics you generated, answer the following questions along with justifications:

  1. Are there any significant differences between the statistics on red/black bets versus odd/even bets? Should there be?
  2. How does increasing the number of bets per round affect the outcomes for the three bet types? Explain why you believe this is the case.
  3. Which bet type (if any) is the best if your goal is simply to finish a round with at least as much money as you started with?
  4. Which bet type (if any) is the best if your goal is win as much (or lose as little) money, on average, as you can?
  5. Which bet type (if any) is the best if your goal is minimize the worst case (i.e., the maximum loss in a round)?
  6. Are there any other interesting patterns that you see in your statistics?

Part 2: Martingale Betting

The Martingale betting strategy is centuries old, but still pops up in viral emails and in various scams. The strategy calls for the gambler to double the bet amount after each loss, so that the first win would recover all previous losses plus a profit equal to the original bet. The (highly dubious) claim is that this system will guarantee a winning outcome.

Modify the playRound method so that it simulates the Martingale betting strategy. That is, each round should begin using the default bet amount. After a loss, the next bet amount should double. After a win, it should go back to the default bet amount. Using your modified method, generate statistics to refill the table:

bet type25 bets
loss % | avg loss | max loss
50 bets
loss % | avg loss | max loss
100 bets
loss % | avg loss | max loss
200 bets
loss % | avg loss | max loss
red ||||||||
odd ||||||||
7 ||||||||

Based on the statistics you generated, answer the following questions along with justifications:

  1. Does the Martingale betting system make any sense when betting on a specific number? Why or why not?
  2. When betting on a color, how does the Martingale strategy compare with the uniform betting strategy with respect to loss percentage? That is, are you more or less likely to come out ahead when playing a round using Martingale betting?
  3. When betting on a color, how does the Martingale strategy compare with the uniform betting strategy with respect to average winnings? That is, do you win (or lose) more credits on average using Martingale betting?
  4. When betting on a color, how does the Martingale strategy compare with the uniform betting strategy with respect to the maximum amounts lost in a round?
  5. Is there any interpretation of your statistics that supports the claim that Martingale betting guarantees you will be a winner?

Submit your RouletteGame.java and modified RouletteTester.java (in a single ZIP file) via BlueLine2, along with your statistics and answers to the questions.