CMSC201
Programming Project Two
The Slot Machine
Out: Wednesday 10/5/05
Due: Before Midnight, Sunday 10/16/05
Sun Oct 16 23:59:59 EST 2005 is on time, but one second later the date
command will show
Mon Oct 17 00:00:00 EST 2005, which is midnight and your project will be worth
0 points at that time and later.
The design document for this project, design2.txt,
is due: Before Midnight, Monday 10/10/05
A sample design document is available from the main Projects page.
|
The Objective
The objective of this assignment is to give you some more practice writing
functions, using separate compilation, generating pseudo-random numbers,
using arrays, passing arrays to functions and will also test your ability to
use top-down design.
The Background
In casinos from Monte Carlo to Las Vegas, one of the most common gambling
devices is the slot machine -- the "one-armed bandit." A typical
slot machine has three wheels that spin around behind a narrow window.
Each wheel is marked with the following symbols: CHERRY, LEMON, ORANGE,
PLUM, BELL, and BAR. The window, however, allows you to see only one symbol
on each wheel at a time. For example, the window might show the following
configuration:
If you put a silver dollar into a slot machine and pull the handle on
its side, the wheels spin around and eventually come to rest in some new
configuration. If the configuration matches one of a set of winning patterns
printed on the front of the slot machine, you get back some money. If not,
you're out a dollar. The following table shows a typical set of winning
patterns, along with their associated payoffs:
BAR BAR BAR pays $ 250
BELL BELL BELL/BAR pays $ 20
PLUM PLUM PLUM/BAR pays $ 14
ORANGE ORANGE ORANGE/BAR pays $ 10
CHERRY CHERRY CHERRY pays $ 7
CHERRY CHERRY - pays $ 5
CHERRY - - pays $ 2
The notation BELL/BAR means that either a BELL or a BAR can appear in
that position, and the dash means that any symbol at all can appear. Thus,
getting a CHERRY in the first position is automatically good for two dollars,
no matter what appears on the other wheels. Note that there is never any
payoff for the the LEMON symbol in the first column, even if you happen
to line up three of them.
The Task
You are to simulate the playing of a slot machine. You should assume that
each of the six symbols is equally likely to come up on each wheel.
Some SPECIFIC REQUIREMENTS for this project:
You are required to use separate compilation for this project. The file
that contains main() is to be called proj2.c. As discussed in class,
the function definitions should be in at least one separate file. For this
project, the functions written will fit into one of two categories, those
that have only to do with a slot machine, and those that are more general
utility functions. The functions that are very general utility functions
should be defined in a file called util.c which will have an associated
interface, the util.h file. The functions that have only to do with
the slot machine should be defined in a file called slot.c, which
will have an associated interface, the slot.h file.
You may use the functions, SetRandomSeed() and GetRandomNumber() from
Lecture 5 - An Example - Cards, cards.c, as two of your utility functions.
GetValidInt() may also be useful and is found in the same lecture.
You should first welcome the user and present him/her with a explanation of
what it means to play the game as opposed to testing the game. After this
initial greeting, a Main Menu should be displayed that allows him/her to
choose to run the program in Test Mode or Play Mode or to QUIT. Your program
must be capable of running in either mode.
- For Test Mode:
- The user should be prompted for the number of games the test
should run (a positive integer which is 100,000 or less)
- The user should be prompted for a positive integer seed for the
pseudo-random number generator. (1 - 65000)
- Seed the random number generator with that positive integer.
- Simulate the playing of the number of games the user entered,
storing the number of times each of the possible winning
combinations occured in an array that is being used as a counter.
You should NOT display the results of each individual roll
- Print out the number of occurrences of each of the winning
possibilities as well as the number of losses.
- Return to the Main Menu
- For play mode:
- The program should seed the generator by using a call to time as
in SetRandomSeed(). - This should happen only when play mode is
first entered, not every pull of the handle.
- The user should then be presented with the Play Menu which allows
him/her to choose to read the instructions, pull the handle to play
a round, or QUIT.
- Your program should provide the user with an initial stake of $ 50
and then let the user play until either the money runs out or the
user decides to quit. During each round, your program should take
away a dollar, simulate the spinning of the wheels, evaluate the
result, display the results of that round and add any winnings to
the players money.
- If a player has run out of money, then they can no longer play, and
should be automatically returned to the main menu after being
shown the results of the last round.
In slot.c, there should be functions named GiveInstructions() and
PlaySlots(). There should definitely be a lot more functions than this in
slot.c, but I will leave the design of the rest of the program to you.
You MUST store the results of each individual roll in an array of ints of
size 3. (1 element for each of the wheels)
You should use many constants in this program. There are many menu choices,
minima, maxima, array sizes, etc. all of which should have constants. You
MUST use the following ones:
/* Slot Items */
#define LEMON 0
#define CHERRY 1
#define ORANGE 2
#define PLUM 3
#define BELL 4
#define BAR 5
Sample Run
linux2[72] % ls
proj2.c slot.c slot.h typescript util.c util.h
linux2[73] % gcc -c -Wall -ansi proj2.c
linux2[74] % gcc -c -Wall -ansi slot.c
linux2[75] % gcc -c -Wall -ansi util.c
linux2[76] % gcc -Wall -ansi proj2.o slot.o util.o
linux2[77] % a.out
MAIN MENU
1 - Play the Slots
2 - Test the Slots
3 - QUIT
Please enter your menu choice : 1
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 1
Your instructions would go here.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 0
Please try again.
Valid choices are between 1 and 3 : 4
Please try again.
Valid choices are between 1 and 3 : 2
You have $ 49.
CHERRY BAR PLUM - YOU WIN $ 2.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 50.
PLUM BAR PLUM - YOU LOSE.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 49.
ORANGE BELL PLUM - YOU LOSE.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 48.
LEMON PLUM ORANGE - YOU LOSE.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 47.
BELL PLUM PLUM - YOU LOSE.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 46.
ORANGE ORANGE LEMON - YOU LOSE.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 45.
BELL ORANGE BAR - YOU LOSE.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 44.
ORANGE BELL CHERRY - YOU LOSE.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 43.
CHERRY PLUM PLUM - YOU WIN $ 2.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 44.
BAR PLUM LEMON - YOU LOSE.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 43.
CHERRY ORANGE BELL - YOU WIN $ 2.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 44.
BELL PLUM PLUM - YOU LOSE.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 43.
CHERRY LEMON ORANGE - YOU WIN $ 2.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 3
Returning to Main Menu
MAIN MENU
1 - Play the Slots
2 - Test the Slots
3 - QUIT
Please enter your menu choice : 4
Please try again.
Valid choices are between 1 and 3 : 0
Please try again.
Valid choices are between 1 and 3 : -2
Please try again.
Valid choices are between 1 and 3 : 2
How many times would you like to play the slots ?
Please enter an integer between 0 and 100000 : 50
What positive number would you like to use as the seed ?
Please enter an integer between 1 and 65000 : 199
FREQUENCY OF WINNINGS
Losses : 41
$ 2 : 5
$ 5 : 1
$ 7 : 0
$ 10 : 0
$ 14 : 1
$ 20 : 1
$ 250 : 1
MAIN MENU
1 - Play the Slots
2 - Test the Slots
3 - QUIT
Please enter your menu choice : 2
How many times would you like to play the slots ?
Please enter an integer between 0 and 100000 : 100000
What positive number would you like to use as the seed ?
Please enter an integer between 1 and 65000 : -2
Please enter an integer between 1 and 65000 : 0
Please enter an integer between 1 and 65000 : 650000
Please enter an integer between 1 and 65000 : 65000
FREQUENCY OF WINNINGS
Losses : 79979
$ 2 : 13943
$ 5 : 2273
$ 7 : 485
$ 10 : 934
$ 14 : 978
$ 20 : 919
$ 250 : 489
MAIN MENU
1 - Play the Slots
2 - Test the Slots
3 - QUIT
Please enter your menu choice : 3
Closing Slot Machine Program
linux2[78] %
End of a Sample Run
This one shows the user playing and running out of money.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 2.
ORANGE CHERRY BELL - YOU LOSE.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 1.
BAR BELL ORANGE - YOU LOSE.
PLAY MENU
1 - Read Instructions
2 - Pull the Arm
3 - QUIT
Please enter your menu choice : 2
You have $ 0.
BELL PLUM ORANGE - YOU LOSE.
Sorry, you've run out of money
Ending your game
MAIN MENU
1 - Play the Slots
2 - Test the Slots
3 - QUIT
Please enter your menu choice : 3
Closing Slot Machine Program
linux2[75] %
Submitting the Program
To submit the file you should use the command:
submit cs201 Proj2 proj2.c util.c slot.c util.h slot.h
You can check your submission by using the command:
submitls cs201 Proj2