[an error occurred while processing this directive]

CMSC201
Programming Project Three

The Slot Machine

Corrected Version

Out: Wednesday 10/29/97
Due: Midnight Wednesday 11/12/97

New Due Date: 24 hour extension ... Midnight Thursday 11/13/97

The Objective

The objective of this assignment is to give you some more practice writing functions, using separate compilation, generating pseudo-random numbers, and using getchar(). It 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:

ORANGE LEMON CHERRY

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 write a program that simulates playing a slot machine. 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, and pay the user any appropriate winnings. For example, a user might be lucky enough to see the following sample run:

umbc9[1]% a.out
Would you like to test the program or play the slots (t or p) ? p
Would you like instructions ? n
You have $ 50.  Would you like to play ? y
PLUM     LEMON    LEMON     -- You lose.
You have $ 49.  Would you like to play ? y
PLUM     BAR      LEMON     -- You lose.
You have $ 48.  Would you like to play ? y
BELL     LEMON    ORANGE    -- You lose.
You have $ 47.  Would you like to play ? y
CHERRY   CHERRY   ORANGE    -- You win $ 5.
You have $ 51.  Would you like to play ? y
LEMON   ORANGE   BAR       -- You lose.
You have $ 50.  Would you like to play ? y
PLUM    BELL     PLUM      -- You lose.
You have $ 49.  Would you like to play ? y
BELL     BELL     BELL      -- You win $ 20.
You have $ 68.  Would you like to play ? y
CHERRY   PLUM     LEMON     -- You win $ 2.
You have $ 69.  Would you like to play ? y
ORANGE   BAR      PLUM      -- You lose.
You have $ 68.  Would you like to play ? y
ORANGE   PLUM     BELL      -- You lose.
You have $ 67.  Would you like to play ? y
BAR      BAR      BAR       -- You win $ 250.
You have $ 316.  Would you like to play ? n
umbc9[2]%

Even though doing so is not realistic (and would make the slot machine unprofitable for the casino), you should assume that each of the six symbols is equally likely 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 proj3.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 14, rand5.c as two of your utility functions.

You must write a utility function called GetYOrN, which gets a character from the user, only accepts 'y', 'n', 'Y', or, 'N' and returns either 'Y'or 'N' to the calling function. This function is to use getchar() to get the character.

This program must be capable of running in either test mode or play mode. For test mode, the user should be prompted for a seed for the pseudo-random number generator. For play mode, the program should seed the generator by using a call to time as in SetRandomSeed(). You must write a utility function called TestOrPlay, which could be used for any game of chance. It gets a character from the user with getchar(), only accepts 't', 'p', 'T', or 'P' and then handles the seeding of the pseudo-random number generator appropriately.

In slot.c, there should be functions named GiveInstructions() and PlaySlot(). There should definitely be more functions than this in slot.c, but I will leave the design of the rest of the program to you.

Correction: The following sentence is not true, since in test mode you need to ask the user for a seed which is a positive integer. Notice that you will not need any of the Roberts' functions for this program.

If you already are familiar with scanf and would like to try to compile using cc, feel free. Remember that if you use the cc compiler rather than cc201, you should not #include "genlib.h", "simpio.h", or any of the other Roberts' header files and you cannot use the bool or string types.


Submitting the Program

To submit the file you should use the command:

submit cs201 proj3 proj3.c util.c slot.c util.h slot.h

You can check your submission by using the command:

submitls cs201 proj3 [an error occurred while processing this directive]Wednesday, 19-Nov-1997 09:42:37 EST