CS 115 Program 4 Roulette Wheel Fall 2009

Electronic Due Date: Thursday, November 19, 2009 midnight
BONUS 10 points graphics

The purpose of this program assignment is

Roulette is a game played with a wheel with numbers on the rim and a ball that rolls around as the wheel spins. The players bet on which number the ball will land on when the wheel stops.

Your program will simulate a roulette wheel. You will let the player enter various wagers, use pseudorandom numbers to "roll the ball" on the wheel, and calculate the player's winnings. (You can pretend you are betting toothpicks if gambling for money bothers you.)

The rules of the game:
The roulette wheel has numbers from 0 to 36 on it. When it is spun around, a small ball can roll onto one of the numbers. A player wagers an amount of money (no more money than they have!) on which number the ball will stop at. There are also wagers possible on:

Note: if you research roulette wheels, you will find these rules are 'old-fashioned'. That is, modern wheels may not have reds and blacks distributed like this. That's ok. These rules are simpler than what is used today.

All of these wagers have different payoffs. If a player bets on the exact number where the ball lands, they win 5 times the amount wagered. Because the odds are so low that that will happen, if the player does not match the number, they don't lose anything.

If a player bets on "odd" and the number landed on is odd or they bet on "even" and the number is even, they win double their wager. If they bet incorrectly, they lose their wager. If a player bets on "red" or "black" correctly, they win triple the wager, if they are incorrect, they lose twice the wager. If a player bets on "high" or "low" correctly, they win their wager, if incorrectly, they lose their wager.

The player must choose a number to wager on and an amount to wager. They do NOT have to place wagers on any of the other choices if they don't want to. The game is ended in two ways: when the player says they don't want to play any more, or when they lose all their money. The program should report the amount of money that the player leaves with.

Sample interaction with the user:

Spin and Win!!! Roulette!!!
Your stake is $100.00

What number do you want to bet on? (0-36) 10
How much do you want to bet ? 50
Do you want to bet on even/odd/no bet? (E/O/N) E
Do you want to bet on red/black/no bet? (R/B/N) b
Do you want to bet on high/low/no bet? (H/L/N) l

Spinning ... . 1. 2. 3. 4... And the number is 10

You win 5 times your bet! You hit the number! $250.00
You win two times your bet on odd/even!  $100.00
You won three times your bet on red/black!  $150.00
You won your bet on high/low!  $50.00
Now you have $650.00

Do you want to play again? (y/n) y
Spin and Win!!! Roulette!!!
Your stake is $650.00

What number do you want to bet on? (0-36) 25
How much do you want to bet ? 3000
That is too much!
How much do you want to bet ? 300
Do you want to bet on even/odd/no bet? (E/O/N) O
Do you want to bet on red/black/no bet? (R/B/N) n
Do you want to bet on high/low/no bet? (H/L/N) h

Spinning ... . 1. 2. 3. 4... And the number is 13

You win two times your bet on odd/even!  $600.00
You lost your bet on high/low!  $300.00
Now you have $950.00

Do you want to play again? (y/n) n
You left the game with $950.00

Interaction with the player should be carefully error-checked. They can't bet negative amounts nor more than they have. The bets can be floating point values. They can only bet on numbers between 0 and 36, inclusive. They should be able to enter either upper or lower case letters for any of the answers.

You will need to use the random number generator to get the number where the ball lands. Random numbers will be discussed in class. It is also described in the examples directory. To start off, you need to call the srand function exactly one time per program. You need to call srand with a seed value - the best way to do this, using the time function, will be discussed in class. You will need to call rand many times during one run of the program.

Functions that you must write:

Part I
Write a pseudocode design of how you think you will do the program. Bring this to lab when the design lab is scheduled. You and your TA will discuss designs during that lab. You should have details down to the 1.1 level, at least, for this lab period. Your design does not have to be complete at the design lab, but you must bring a file that shows you have thought about the problem. You get points on the program grade for having this design at the designated lab period. By the time the program is due, your design should be at the 1.1.1 level of detail.

Work from the top down - what does your main function have to do? Think about what kind of loops you will need. Think about what kind of logic you will need. Think about parameter lists - what information does a function need to work?

Winnings will be the most complex function you have. Write a version that calculates ONLY the payoff from matching the number. Test this restricted function with the rest of your program.

Part II
Now "flesh out" the winnings function to include all the payoffs that are described above. It should be easier because you have the rest of your program working. Turn in your source code with the full winnings function in it. Your captured test runs should also be for this version.

Testing:

You should think carefully about testing your program. One run of the program can generate a lot of output. Capture two test runs. You should test different combinations of wagers. Show these combinations in a test plan. Many of them may be tested in one run. Label your test run captures, so that we can tell what is being tested.

BONUS: 10 points

When you have the program working, then add in this. Expand the displayspin function to show some sort of animation of the wheel using the graphics library. Use your imagination!

Please read the documentation standard on the class web page. As you can see from looking at the grading sheet, we will be looking to see how you meet these standards.

A reminder: you do not want to use any global variables! The penalty is now 30 points! Missing prototypes will also cost you 30 points!

You will be using a few libraries for this program. Document what functions you are using from each library.

Turn in electronically, zipped into one file,