Mistro116@yahoo.com |
10-16-2005 05:38 PM |
This is the entire slot.c file as of right now, I tried to reduce the switch statement and cases to just do it directly, it didnt work, i tried to get rid of the simulatenumberofgames function didnt work... i tried everything. All the main does is TestSlots ( ); This is everything
Code:
/* Slot machine item constants */
#define LEMON 0 /* Slot
machine
item 0,
LEMON. */
#define CHERRY 1 /* Slot
machine
item 1,
CHERRY. */
#define ORANGE 2 /* Slot
machine
item 2,
ORANGE. */
#define PLUM 3 /* Slot
machine
item 3,
PLUM. */
#define BELL 4 /* Slot
machine
item 4,
BELL. */
#define BAR 5 /* Slot
machine
item 5,
BAR. */
/* Number of games constants */
#define MINNUMBEROFGAMES 0 /* The minimum
number of
games that
can be
simulated
in Test
Mode,
0. */
#define MAXNUMBEROFGAMES 100000 /* The maximum
number of
games that
can be
simulated
in Test
Mode,
100,000. */
/* Test mode positive seed constants */
#define MINPOSITIVESEED 1 /* The minimum
positive
seed that
can be
input by
the user
for the
pseudo-
random
number
generator,
1. */
#define MAXPOSITIVESEED 65000 /* The maximum
positive
seed that
can be
input by
the user
for the
pseudo-
random
number
generator,
65,000. */
/* Array size constants */
#define NUMBEROFSLOTMACHINEWHEELS 3 /* The total
number of
slot
machine
wheels,
3. */
#define NUMBEROFWINNINGCOMBINATIONS 7 /* The number
of possible
winning
patterns
that can be
produced
from the
slot
machine,
7. */
/* Play mode player stakes constants */
#define INITIALSTAKEOFPLAYER 50 /* The initial
stake of
the player
when first
beginning
Play Mode,
50. */
#define LOSINGSTAKEOFPLAYER 0 /* The losing
stake of
the player,
when Play
Mode will
terminate,
0. */
/* Play mode menu constants */
#define MINPLAYMODEMENU 1 /* The minimum
acceptable
choice from
the play
mode menu,
Option 1,
PLAYMODE
READ
INSTRUCTIONS.
*/
#define PLAYMODEREADINSTRUCTIONS 1 /* Option 1,
from the
play mode
menu,
PLAYMODE
READ
INSTRUCTIONS.
*/
#define PLAYMODEPULLTHEARM 2 /* Option 2,
from the
play mode
menu,
PLAYMODE
PULL THE
ARM. */
#define PLAYMODEQUIT 3 /* Option 3,
from the
play mode
menu,
PLAYMODE
QUIT. */
#define MAXPLAYMODEMENU 3 /* The maximum
acceptable
choice from
the play
mode menu,
Option 3,
PLAYMODE
QUIT. */
/***********************************************************
*
* The following function implementations and definitions
* are listed as hide details functions:
*
**********************************************************/
/***********************************************************
* Function: TestSlots
* Usage: TestSlots ();
*
* This function will be responsible for storing and
* processing all of the input from the user, regarding
* simulating the main driver program in Test Mode. This
* function will manipulate two local array variables, int
* testSlotMachine [NUMBEROFSLOTMACHINEWHEELS], whose
* indices contain three random numbers between
* LOW, 0, and HIGH, 5, inclusively, and int winningResults
* [NUMBEROFWINNINGCOMBINATIONS], whose indices contain
* counters for the number of times each of the possible
* winning combinations were randomly obtained. This
* function will also be responsible for making calls to
* several functions that will perform and/or display the
* results of the processes of the main driver program in
* Test Mode.
*
* This is a high level function that will perform in the
* following way:
*
* This function will first prompt the user for the number
* of games that Test Mode should simulate, by making a
* call to NumberOfGames (), which will ensure that the
* number of games simulated in Test Mode is a positive
* integer that is 100,000 or less, or between
* MINNUMBEROFGAMES, 0, and MAXNUMBEROFGAMES, 100,000.
* The function will also prompt the user for a positive
* integer seed for the pseudo-random generator to be
* passed to, by making a call to GetPositiveSeed (),
* which will ensure that the positive seed is a positive
* integer between MINPOSITIVESEED, 1, and MAXPOSITIVESEED,
* 65,000. After prompting the user for a positive integer
* seed for the pseudo-random number generator, this
* function makes a call to SetPositiveSeed (int
* positiveSeed), which seeds the pseudo-random number
* generator with the positive integer value returned from
* GetPositiveSeed (). Then, this function will make a
* call to SimulateNumberOfGames (int numberOfGames), which
* will call InitializeCounterArray (int winningResults
* [NUMBEROFWINNINGCOMBINATIONS]), which will initialize
* all of the indices of the local counter array variable,
* int winningResults [NUMBEROFWINNINGCOMBINATIONS], to 0
* before this function starts to progress through the
* for-loop. This function will also call the function
* TestPullSlotMachine () int numberOfGames amount of
* times, and will simulate the numberOfGames specified by
* the user. The function, TestPullSlotMachine, makes a
* call to SimulatePullSlotMachine (int testSlotMachine
* [NUMBEROFSLOTMACHINEWHEELS], which assigns a pseudo-
* random number between LOW, 0, and HIGH, 5, into the
* three indices of the local array variable, int
* testSlotMachine [NUMBEROFSLOTMACHINEWHEELS], and makes a
* call to TestGetSlotResults (int testSlotMachine
* [NUMBEROFSLOTMACHINEWHEELS], int winningResults
* [NUMBEROFWINNINGCOMBINATIONS]), which evaluates the
* three indices of the local array variable, int
* testSlotMachine[NUMBEROFSLOTMACHINEWHEELS], and checks
* to see if the order and the values of the three indices
* match any of the seven winning combinations by using
* three nested switch statements. If the switch statements
* match the three random numbers with one of the seven
* possible winning combinations, then the proper position
* of the second local array variable, int winningResults
* [NUMBEROFWINNINGCOMBINATIONS], denoting the winning
* combination that was detected by this function, will be
* incremented by 1. This is all repeated int numberOfGames
* amount of times through the call to the function,
* SimulateNumberOfGames (int numberOfGames). Then, the
* number of occurences of each of the possible winning
* combinations is displayed, as well as the number of
* losses, by making a call to the function,
* DisplayTestResults (int winningResults
* [NUMBEROFWINNINGCOMBINATIONS], int numberOfGames). Once
* these tasks have been executed, the user is returned to
* the main menu.
*
* Input: None - this function takes void as its argument
* specifier/parameter.
* Output: None - this function takes a void return-type.
*
**********************************************************/
void TestSlots (void)
{
/* A local variable array that will hold the values after
each pull of the slot machine arm. */
int testSlotMachine [NUMBEROFSLOTMACHINEWHEELS];
/* A local variable array that will serve as a counter
for the number of times a winning combination was
produced. */
int winningResults [NUMBEROFWINNINGCOMBINATIONS];
/* Prompt the user to enter the number of games to be
simulated, between MINNUMBEROFGAMES and
MAXNUMBEROFGAMES. */
int numberOfGames = NumberOfGames ();
/* Prompt the user for the positive seed to be passed to
the pseudo-random number generator, between
MINPOSITIVESEED and MAXPOSITIVESEED. */
int positiveSeed = GetPositiveSeed ();
/* Seed the pseudo-random number generator with the
positive seed entered by the user. */
SetPositiveSeed(positiveSeed);
/* Initialize all of the indicies of the local counter
array variable, int winningResults
[NUMBEROFWINNINGCOMBINATIONS], to 0. */
InitializeCounterArray (winningResults,
NUMBEROFWINNINGCOMBINATIONS);
/* Simulate the number of games input by the user. */
int i;
for (i = 0; i < numberOfGames; i++)
{
SimulatePullSlotMachine (testSlotMachine,
NUMBEROFSLOTMACHINEWHEELS);
TestGetSlotResults (testSlotMachine, winningResults);
}
DisplayTestResults (winningResults,
NUMBEROFWINNINGCOMBINATIONS,
numberOfGames);
}
/***********************************************************
* Function: NumberOfGames
* Usage: int numberOfGames = NumberOfGames (void);
*
* This function will be responsible for prompting the user
* for and returning the number of games that the user
* indicates the Test Mode should simulate. This function
* will make a call to GetValidInt (MINNUMBEROFGAMES,
* MAXNUMBEROFGAMES), which will ensure that the number of
* games simulated in test mode is a positive integer that
* is 100,000 or less. This value, the number of games to
* be simulated, will be stored in the local variable, int
* numberOfGames.
*
* Input: None - this function takes void as its argument
* specifier/parameter.
* Output: int numberOfGames - returns a valid integer
* value, between
* MINNUMBEROFGAMES, 0, and
* MAXNUMBEROFGAMES, 100,000,
* which corresponds to the
* number of games to be
* simulated in the Test Mode.
*
**********************************************************/
int NumberOfGames (void)
{
int numberOfGames;
/* Prompt the user for the number of games to be
simulated. */
printf ("How many times would you like to play the slots ?\n");
printf ("Please enter an integer between %d and %d : ",
MINNUMBEROFGAMES, MAXNUMBEROFGAMES);
/* Allow the user to select the number of games to be
simulated, between MINNUMBEROFGAMES and
MAXNUMBEROFGAMES. */
numberOfGames = GetValidInt(MINNUMBEROFGAMES,
MAXNUMBEROFGAMES);
printf("\n\n");
return numberOfGames;
}
/***********************************************************
* Function: GetPositiveSeed
* Usage: int positiveSeed = GetPositiveSeed (void);
*
* This function will be responsible for prompting the user
* for and returning a positive integer seed for the
* pseudo-random number generator to simulate from in Test
* Mode. This function will make a call to GetValidInt
* (MINPOSITIVESEED, MAXPOSITIVESEED), which will ensure
* that the positive seed passed to the pseudo-random
* number generator in Test Mode is a positive integer
* value between MINPOSITIVESEED, 1, and MAXPOSITIVESEED,
* 65,000. This value, the positive seed for the pseudo-
* random number generator to be passed to in Test Mode,
* will be stored in the local variable, int positiveSeed.
*
* Input: None - this function takes void as its argument
* specifier/parameter.
* Output: int positiveSeed - returns a valid integer
* value, between
* MINPOSITIVESEED, 1, and
* MAXPOSITIVESEED, 65,000,
* which corresponds to the
* positive integer seed value
* for the pseuo-random number
* generator to be passed in
* Test Mode.
*
**********************************************************/
int GetPositiveSeed (void)
{
int positiveSeed;
/* Prompt the user for the positive seed to be passed to
the pseudo-random number generator. */
printf ("What positive number would you like to use as the seed ?\n");
printf ("Please enter an integer between %d and %d : ",
MINPOSITIVESEED, MAXPOSITIVESEED);
/* Allow the user to select the positive integer to be
passed to the pseudo-random number generator, between
MINPOSITIVESEED and MAXPOSITIVESEED. */
positiveSeed = GetValidInt(MINPOSITIVESEED,
MAXPOSITIVESEED);
printf("\n\n");
return positiveSeed;
}
/***********************************************************
* Function: SetPositiveSeed
* Usage: SetPositiveSeed (int positiveSeed);
*
* This function will be responsible for seeding the
* pseudo-random number generator with the positive integer
* value, between 1 and 65,000 inclusively, that was
* returned from GetPositiveSeed ().
*
* Input: int positiveSeed - the positive integer value
* between MINPOSITIVESEED, 1,
* and MAXPOSITIVESEED, 65,000,
* which corresponds to the
* positive integer seed value
* for the pseuo-random number
* generator to be passed in
* Test Mode.
* Output: None - this function takes a void return-type.
*
**********************************************************/
void SetPositiveSeed (int positiveSeed)
{
srand (positiveSeed);
}
/***********************************************************
* Function: InitializeCounterArray
* Usage: InitializeCounterArray (int winningResults [ ],
* int numberOfWinningCombinations);
*
* This function will be responsible for initializing all
* seven indicies of the local array variable, int
* winningResults [NUMBEROFWINNINGCOMBINATIONS], to 0, in
* order to allow it to be used as a counter.
*
* Inputs: int winningResults [ ] - a local array
* variable in
* TestSlots (),
* whose indices
* contain
* counters for
* the number of
* times each of
* the possible
* winning
* combinations
* were randomly
* obtained.
* int numberOfWinningCombinations - a constant that
* represents the
* number of
* elements in
* the local array
* variable,
* winningResults
* [ ].
* Output: None - this function takes a void return-type.
*
**********************************************************/
void InitializeCounterArray (int winningResults [ ],
int numberOfWinningCombinations)
{
int winningResultsIndex;
for (winningResultsIndex = 0; winningResultsIndex <
NUMBEROFWINNINGCOMBINATIONS; winningResultsIndex++);
{
winningResults [winningResultsIndex] = 0;
}
}
/***********************************************************
* Function: TestPullSlotMachine
* Usage: TestPullSlotMachine (int testSlotMachine [ ],
* int winningResults [ ]);
*
* This function will be responsible for simulating one
* pull of the slot machine in Test Mode by calling
* SimulatePullSlotMachine (int testSlotMachine
* [NUMBEROFSLOTMACHINEWHEELS]), which will generate
* pseudo-random integers between LOW, 0, and HIGH, 5,
* inclusively, into the three indices of the local array
* variable, int testSlotMachine
* [NUMBEROFSLOTMACHINEWHEELS]. This function will also
* call TestGetSlotResults (), which will assign the
* winning combination, if it occured, into the proper
* position of the local array variable, int winningResults
* [NUMBEROFWINNINGCOMBINATIONS].
*
* Inputs: int testSlotMachine [ ] - a local array variable
* in TestSlots (), whose
* indices contain three
* random numbers between
* LOW, 0, and HIGH, 5,
* inclusively.
* int winningResults [ ] - a local array variable
* in TestSlots (), whose
* indices contain
* counters for the
* number of times each
* of the possible
* winning combinations
* were randomly
* obtained.
* Output: None - this function takes a void return-type.
*
**********************************************************/
void TestPullSlotMachine (int testSlotMachine [ ],
int winningResults [ ])
{
SimulatePullSlotMachine(testSlotMachine,
NUMBEROFSLOTMACHINEWHEELS);
TestGetSlotResults(testSlotMachine, winningResults);
}
void SimulatePullSlotMachine (int testSlotMachine [ ],
int numberOfSlotMachineWheels)
{
int testSlotMachineIndex;
for (testSlotMachineIndex = 0; testSlotMachineIndex <
numberOfSlotMachineWheels; testSlotMachine++)
{
testSlotMachine [testSlotMachineIndex] =
GetRandomNumber ();
}
}
/***********************************************************
* Function: TestGetSlotResults
* Usage: TestGetSlotResults (int testSlotMachine [ ],
* int winningResults [ ]);
*
* This function will be responsible for evaluating the
* three indices of local array variable, int
* testSlotMachine [NUMBEROFSLOTMACHINEWHEELS], and
* checking to see if the order and the values of the three
* indices match any of the seven winning combinations by
* using three nested switch statements. If the switch
* statements match the three random numbers with one of
* the seven possible winning combinations, then the proper
* position of the second local array variable, int
* winningResults [NUMBEROFWINNINGCOMBINATIONS], denoting
* the winning combination that was detected by this
* function, will be incremented by one.
*
* Inputs: int testSlotMachine [ ] - a local array variable
* in TestSlots (), whose
* indices contain three
* random numbers between
* LOW, 0, and HIGH, 5,
* inclusively.
* int winningResults [ ] - a local array variable
* in TestSlots (), whose
* indices contain
* counters for the
* number of times each
* of the possible
* winning combinations
* were randomly
* obtained.
* Output: None - this function takes a void return-type.
*
**********************************************************/
void TestGetSlotResults (int testSlotMachine [ ],
int winningResults [ ])
{
switch (testSlotMachine [0])
{
case LEMON:
break;
case CHERRY:
winningResults [0]++;
switch (testSlotMachine [1])
{
case LEMON:
break;
case CHERRY:
winningResults [1]++;
switch (testSlotMachine [2])
{
case LEMON:
break;
case CHERRY:
winningResults [2]++;
break;
case ORANGE:
break;
case PLUM:
break;
case BELL:
break;
case BAR:
break;
}
break;
case ORANGE:
break;
case PLUM:
break;
case BELL:
break;
case BAR:
break;
}
break;
case ORANGE:
switch (testSlotMachine [1])
{
case LEMON:
break;
case CHERRY:
break;
case ORANGE:
switch (testSlotMachine [2])
{
case LEMON:
break;
case CHERRY:
break;
case ORANGE:
winningResults [3]++;
break;
case PLUM:
break;
case BELL:
break;
case BAR:
winningResults [3]++;
break;
}
break;
case PLUM:
break;
case BELL:
break;
case BAR:
break;
}
break;
case PLUM:
switch (testSlotMachine [1])
{
case LEMON:
break;
case CHERRY:
break;
case ORANGE:
break;
case PLUM:
switch (testSlotMachine [2])
{
case LEMON:
break;
case CHERRY:
break;
case ORANGE:
break;
case PLUM:
winningResults [4]++;
break;
case BELL:
break;
case BAR:
winningResults [4]++;
break;
}
break;
case BELL:
break;
case BAR:
break;
}
break;
case BELL:
switch (testSlotMachine [1])
{
case LEMON:
break;
case CHERRY:
break;
case ORANGE:
break;
case PLUM:
break;
case BELL:
switch (testSlotMachine [2])
{
case LEMON:
break;
case CHERRY:
break;
case ORANGE:
break;
case PLUM:
break;
case BELL:
winningResults [5]++;
break;
case BAR:
winningResults [5]++;
break;
}
break;
case BAR:
break;
}
break;
case BAR:
switch (testSlotMachine [1])
{
case LEMON:
break;
case CHERRY:
break;
case ORANGE:
break;
case PLUM:
break;
case BELL:
break;
case BAR:
switch (testSlotMachine [2])
{
case LEMON:
break;
case CHERRY:
break;
case ORANGE:
break;
case PLUM:
break;
case BELL:
break;
case BAR:
winningResults [6]++;
break;
}
}
break;
}
}
/***********************************************************
* Function: SimulateNumberOfGames
* Usage: SimulateNumberOfGames (int numberOfGames)
*
* /
void SimulateNumberOfGames (int numberOfGames,
int testSlotMachine [ ],
int winningResults [ ])
{
int numberOfGamesIndex;
for (numberOfGamesIndex = 0; numberOfGamesIndex <
numberOfGames; numberOfGamesIndex++)
{
TestPullSlotMachine(testSlotMachine, winningResults);
}
}
|