We will be implementing a variation of the dice game Cee-lo. The following description has been adopted from Wikipedia.
Two players (in our case, one human, once CPU) roll three dice each until both have a recongized dice combination. Whoever rolls the better combination wins! A tie results in both player and CPU rerolling their three dice until they both have a recognized combination. Recognized combations are ranked below from best to worst:
Note that a tie in terms of Trips would be both players rolling the same trips numbers (i.e. 3-3-3 and 3-3-3), and a tie in terms of Point would be both players rolling the same point (i.e. 6-2-6 and 3-3-2).
A single game of Cee-lo is both players rolling a recognized combination and NOT tying (that is, one player's combination beats the other players combination).
Write a program (called ceelo.c) that implements Cee-lo according to the above rules. The game should also allow for wagering. This means that you need to prompt the user for an initial bank balance (we assume they're honest!) from which their winnings or losings will be added or subtracted. Before each game, prompt the user for a wager. Re-ask for a wager if their wager is not valid (if they dont have enough money to make their wager). Once a game is won or lost, the bank balance should be adjusted, and, if the player has a non-zero balance, the player should be able to choose if they want to play another game or cash out their winnings (quit the program).
Several functions have been implemented for you in the template provided.
You will need to use the below functions to help you write the game logic. You may define more than just these, but these functions must be defined as described below:
All functions should be prototyped above main and defined below it. There is a lot to this assignment, but a good approach is to implement the functions as they're described above (except for main()) and make sure they function as they should (by writing tests in main(). Once you know each function behaves as it should, begin work on main(). Write this function in steps: write it to play a single game of Cee-lo with no wagering, then add wagering (but still one game), then add the ability to play multiple games. You dont have to break it down like this, but many students have found it helpful to approach this assignment like this in the past.
#include < stdio.h >
#include < time.h >
#include < stdlib.h >
void print_game_rules(void);
int is_number_in_die(int die[3], int num);
int has_pair(int die[3]);
// Add other function prototypes below here but above main().
int main(void)
{
// The line below sets the seed of the random number generator.
srand(time(0));
print_game_rules();
// Your game logic goes here.
return 0; }
// It is good practice to define all functions after the body of the main()
// function.
void print_game_rules(void)
{
printf("Cee-lo rules:\n"
"This is a battle of the player against the CPU. Both roll three\n"
"dice each until both have a recognized combination. Whoever rolls\n"
"the better combination wins! A tie results in both player and CPU\n"
"rerolling their die until they each have a new combination.\n"
"Combinations are ranked from best to worst as:\n"
"\t4-5-6:\n\t\tThe die values are 4, 5, and 6 (any order)\n"
"\tTrips:\n\t\tThe three die values are all the same. Higher trips\n"
"\t\tbeats lower trips (but still note that trips beats \"point\"\n"
"\t\t(see below).\n"
"\tPoint:\n\t\tA pair is rolled. The non-matching dice is the\n"
"\t\t\"point\". A higher point beats a lower point (so 1-1-5 beats\n"
"\t\t6-3-6)\n"
"\t1-2-3:\n\t\tThe die values are 1, 2, and 3 (any order)\n"
"The above are the only recognized combinations. A player must\n"
"reroll until they have one of the above combinations\n");
}
int is_number_in_die(int die[3], int num)
{
for (int i = 0; i < 3; i++)
{
if (num == die[i])
return 1;
}
return 0; }
int has_pair(int die[3])
{
if (die[0] == die[1])
return die[2];
else if (die[1] == die[2])
return die[0];
else if (die[0] == die[2])
return die[1];
else
return 0;
}
// Add your other function definitions below here
The following illustrates an example of the program described above. Your program can display the game output however you would like as long as the necessary information is there (see #8 above). Your dice rolls will likely be different.
Cee-lo rules:
This is a battle of the player against the CPU. Both roll three
dice each until both have a recognized combination. Whoever rolls
the better combination wins! A tie results in both player and CPU
rerolling their die until they each have a new combination.
Combinations are ranked from best to worst as:
1-2-3:
"point". A higher point beats a lower point (so 1-1-5 beats
6-3-6)
The die values are 1, 2, and 3 (any order)
The above are the only recognized combinations. A player must
reroll until they have one of the above combinations
Enter in an initial bank balance (in dollars): 100
Your current balance is $100.00
Enter in a wager amount (in dollars): 500
Enter in a wager amount (in dollars): 400
Enter in a wager amount (in dollars): 50
You rolled (5, 4, 3) (unrecognized combo)
You rolled (6, 3, 4) (unrecognized combo)
You rolled (3, 2, 1)
CPU rolled (5, 2, 4) (unrecognized combo)
CPU rolled (4, 4, 6)
You lost!
Do you want to continue playing or quit and take your money ($50.00)
(’c’ for continue, ’q’ for quit): c
Your current balance is $50.00
Enter in a wager amount (in dollars): 50
You rolled (1, 5, 6) (unrecognized combo)
You rolled (1, 2, 1)
CPU rolled (4, 1, 4)
You won!
Do you want to continue playing or quit and take your money ($100.00)
(’c’ for continue, ’q’ for quit): c
Your current balance is $100.00
Enter in a wager amount (in dollars): 100
You rolled (2, 4, 6) (unrecognized combo)
You rolled (6, 4, 6)
CPU rolled (1, 6, 1)
You lost!
You left with $0.00.
Better luck next time.