The educational goals of this program are to:
Any program turned in which uses "break" or an infinite loop of the form "while (True)" or "while (1)" will lose 50 points immediately. Don't let it happen to you!
Your program will simulate a slot machine, a "one-armed bandit". You will let the player enter their wager, use pseudorandom numbers to "spin the wheels" on the machine, 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 slot machine has 3 wheels with symbols of a
cherry, apple, lemon, melon, plum, grape, orange, a bar and a JACKPOT.
There are 9 symbols on each wheel.
A player wagers an amount of money (no more than they have!).
When the player "pulls the handle", the wheels spin around,
and then each one stops at one of the symbols.
If the three wheels come up with matching symbols, the
player wins various amounts of money.
How the player wins:
if three JACKPOTS come up, the player wins 20 times the amount
they bet. If three bars come up, they win 10 times the bet.
If any other symbol comes up three times, they win 3 times the bet.
If any symbol comes up just two times, they win twice the amount
they bet. Otherwise they lose the amount they bet.
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: (no graphics)
One Armed Bandit!! What's your name? Debby You start off with 200 dollars Want to play with the one-armed bandit? y What do you want to bet (up to $200) ? 50 Pulling the handle.... Orange Apple Grape You lost $50 You now have 150 dollars Play again? y What do you want to bet (up to $150) ? 300 You can't bet more than you have What do you want to bet (up to $150) ? 2000 You can't bet more than you have What do you want to bet (up to $150) ? 100 Pulling the handle.... Apple Apple Orange Double! You won $200 You now have 350 dollars Play again? y What do you want to bet (up to $350) ? 75 Pulling the handle.... Bar Bar Orange Double! You won $150 You now have 500 dollars Play again? n Debby Thanks for playing!! You leave with $500
Test Cases
First, read the assignment carefully.
Look for how the program is supposed to behave.
The assignment gives some examples of normal runs.
There are many other test cases possible.
Save this doc file
and fill in the table with test cases. Put your
name and the section at the top. Submit this file
with your individual additions at the link here.
Choose the menu choices of "TestCases" and "Program 4".
This is due by Sunday, April 1, midnight.
Have at least 7 test cases.
Also bring this file with you to lab on
Monday, April 2, to contribute to your team's effort.
Design
Make a list of steps
and put it in Python form in comment statements.
Save this Python file as "design4.py".
# supply program prolog # main function # display introductory message # get user's name # set pot to 200 dollars, tell user # ask the user if they want to play # while answer is y and pot is not 0 or negative # get their bet # get the random numbers for the spins # display the wheels # figure the payoff and report to the user # add the payoff to the pot and report to the user # ask the user if they want to play again # if the pot is negative or zero # "you ran out of money" # else # "you leave with $pot"and individually fill in the missing steps in the design. You also need to do design for each of the specified functions. Note that the main function will not need to change much at all when the graphics displays for the wheels is added. Submit this file with the link here. Choose the menu choices of "Design" and "Program 4". This is due by Tuesday, April 3, midnight. Also bring this file with you to lab on Wednesday, April 4, to contribute to your team's effort.
Interaction with the player should be carefully error-checked. They can't bet negative amounts nor more money than they have. They should be able to enter either upper or lower case letters.
You will need to use the random number generator to get the symbols where the wheels stop. Random numbers will be discussed in class.
Functions that you must write:
You are welcome to write more functions as you think you need them.
Data structures - you may choose how you store the results of the 3 spins. There are some list methods which would be useful when manipulating these numbers.
Once you have the program working as described above,
then add in the graphics component.
The function drawwheels is where
you do this. It should open a graphics window,
display three rectangles of different colors and the names of
the symbols on the rectangles in different colors.
It should look something like
.
Different names are generated and displayed with a short delay
between each set, to give the effect of the wheels "spinning".
The last ones shown are the ones the machine pays off for.
Here is an executable to run.
See below for a bonus with this function.
You should investigate the following graphics library functions as being useful to this program:
The sleep function from the time library will also be useful for adding a small delay.
A reminder: you do not want to use any global variables! There is a penalty of 25 points if you do.
The program must be turned in on time to be eligible for bonus points. So don't wait to turn in your program to finish the bonus until it is late!
Bonus 1 (10 points)
The High Score file: Your program will use a small file to keep track of the name of the player with the highest score for the game, as well as their score. The file must be named hiscore, and has two lines of data in it, the name on one line (may have spaces in it) and the high score on the next line. When the program starts, it needs to check that file and get the data in it if it exists. The first time the game is played, there will be no file there. In that case, the high score is considered zero and should not be reported to the player. When the game is over, the program needs to check to see if the player made a new high score and record that fact in the hiscore file if that is the case. It should also tell the player if they made a new high score.
If you do this bonus, you must write more functions:
Bonus 2 (10 points)
Instead of using the names of the symbols on the wheels,
like "apple", collect small images that represent them
(images.google.com is a very good source, look at
thumbnail pictures) and use the
Image constructor function from the graphics library to put
the images on the rectangles.
Hint: img = Image(Point(x,y),"image.gif")
NEW SPECIFICATION for the bonus
If you do this bonus, use the filenames as listed below. This means that you will not have to submit any image files. The TAs will use these images when grading your code. Of course while you are testing your program you can use any images you like:) Just make sure the program submitted has the given file names exactly as listed.
For those who wanted smaller images, these are 100x100 pixels. If you want to use them, rename the files to the standard names above (i.e. without the "small" in the name).
Please read the documentation standard on the class web page. We will be looking to see how you meet these standards. In your documentation, mention what functions you use from which libraries. Document what your functions are doing and what the parameters mean.