using c programing Develop and implement an interactive two-player Yahtzee game.
ID: 3676662 • Letter: U
Question
using c programing
Develop and implement an interactive two-player Yahtzee game. Yahtzee is a dice game that was invented by Milton Bradley and Edwin S. Lowe in 1956. The challenge of the game is to outduel the other player by scoring the most points. Points are obtained by rolling five 6-sided die across thirteen rounds. During each round, each player may roll the dice up to three times to make one of the possible scoring combinations. Once a combination has been achieved by the player, it may not be used again in future rounds, except for the Yahtzee combination may be used as many times as the player makes the combination. Each scoring combination has different point totals. Some of these totals are achieved through the accumulation of points across rolls and some are obtained as fixed sequences of values.
The Rules of Yahtzee:
The scorecard used for Yahtzee is composed of two sections. A upper section and a lower section. A total of thirteen boxes or thirteen scoring combinations are divided amongst the sections. The upper section consists of boxes that are scored by summing the value of the dice matching the faces of the box. If a player rolls four 3's, then the score placed in the 3's box is the sum of the dice which is 12. Once a player has chosen to score a box, it may not be changed and the combination is no longer in play for future rounds. If the sum of the scores in the upper section is greater than or equal to 63, then 35 more points are added to the players overall score as a bonus. The lower section contains a number of poker like combinations. See the table provided below:
Name
Combination
Score
Three-of-a-kind
Three dice with the same face
Sum of all face values on the 5 dice
Four-of-a-kind
Four dice with the same face
Sum of all face values on the 5 dice
Full house
One pair and a three-of-a-kind
25
Small straight
A sequence of four dice
30
Large straight
A sequence of five dice
40
Yahtzee (think five-of-a-kind)
Five dice with the same face
50
Chance
May be used for any sequence of dice; this is the catch all combination
Sum of all face values on the 5 dice
What is required for this assignment?
You may design the Yahtzee game with functions that you see fit. I recommend that you start with a structure chart and determine sub-problems and functions accordingly. You must also take advantage of applying pointers, output parameters, and/or arrays! Your Yahtzee game must also implement the following algorithm:
(1) (5 pts) Print a game menu for Yahtzee with the following options:
1. Print game rules
2. Start a game of Yahtzee
3. Exit
(2) Get a menu option from the user; clear the screen
(3) If option 1 is entered, then print the game rules stated above and repeat step (1)
otherwise if option 2 is entered, then continue on to step (4); player 1 starts the game
otherwise if option 3 is entered, then print a goodbye message and quit the program
otherwise repeat step (1)
(4) Ask the player to hit any key to continue on to roll the five dice
(5) Roll the five dice and display the face values of each die; enumerate each die with
a number 1 - 5; add 1 to the total number of rolls for this round
(6) (10 pts) If the total number of rolls for this round is less than three,
then ask the player (Y/N) if he/she wants to use the roll for one of the game combinations
otherwise a combination must be selected.
1. Sum of 1's 7. Three-of-a-kind
2. Sum of 2's 8. Four-of-a-kind
3. Sum of 3's 9. Full house
4. Sum of 4's 10. Small straight
5. Sum of 5's 11. Large straight
6. Sum of 6's 12. Yahtzee
13. Chance
(7) If the number of rolls is three or "yes" is entered, then save the combination and it may not be selected again in the future
(Note: The selection of the combination must be verified. If the user selects full house, but does not have one, then your
must assign 0 points for the combination);
continue on to step (8); clear the screen
otherwise if "no" is entered, ask the user which dice to re-roll (1 - 5); re-roll the selected die or dice; clear the screen;
repeat step (6)
otherwise repeat step (6)
(8) Alternate players
(9) If each player has rolled for the round, then increment the round number
if the round number is equal to 14, then continue on to step (10)
otherwise repeat step (4)
otherwise repeat step (4)
(10) If the total score in the upper section is greater than or equal to 63 for a player, then add 35 points to the total score
(11) Print the scores for both players and print the winner
(12) Repeat step (1)
IV. Expected Results:
I recommend that you check out this website http://www.yahtzeeonline.org/ to grasp the game play for Yahtzee. Of course the game you build is text based.
V. Submitting Assignments:
Using Blackboard Learn https://learn.wsu.edu/webapps/login/ submit your assignment to your TA through the link ending with “-LAB”. Under the "Content" link navigate to the "Programming Assignment Submissions" folder and upload your solutions to the appropriate “Assignment” space. You must upload your solutions as _pa5.zip by the due date and time.
Your .zip file should contain your one header file (a .h file), two C source files (which must be .c files), and project workspace. Delete the debug folders before you zip the project folder.
Your project must build properly. The most points an assignment can receive if it does not build properly is 65 out of 100.
Name
Combination
Score
Three-of-a-kind
Three dice with the same face
Sum of all face values on the 5 dice
Four-of-a-kind
Four dice with the same face
Sum of all face values on the 5 dice
Full house
One pair and a three-of-a-kind
25
Small straight
A sequence of four dice
30
Large straight
A sequence of five dice
40
Yahtzee (think five-of-a-kind)
Five dice with the same face
50
Chance
May be used for any sequence of dice; this is the catch all combination
Sum of all face values on the 5 dice
Explanation / Answer
main.c
#include "function.h"
int main (void)
{
int choice = 1, die1 = 0, die2 = 0, die3 = 0, die4 = 0, die5 = 0, die_value = 0, press = 0, roll = 0, count = 0, combination = 0, menu = 0, number = 0;
char yes = '', no = '';
int two = 0, three = 0, four = 0, five = 0, six = 0
srand ((unsigned int) time (NULL));
while (choice)
{
switch (game_menu())
{
case RULES:
game_rules ();
system("PAUSE");
break;
case GAME:
run_game (die1, die2, die3, die4, die5);
break;
case EXIT:
printf ("Goodbye. ");
choice = 0;
break;
default:
printf ("Illegal option. ");
break;
}
return 0;
}
}
Function.h
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define RULES 1
#define GAME 2
#define EXIT 3
#define ONE 4
#define NOT_ONE 0
#define TWO 5
#define NOT_TWO 0
#define THREE 6
#define NOT_THREE 0
#define FOUR 7
#define NOT_FOUR 0
#define FIVE 8
#define NOT_FIVE 0
#define SIX 9
#define NOT_SIX 0
#define THREE_KIND 10
#define NOT_THREE_KIND 0
#define FOUR_KIND 11
#define NOT_FOUR_KIND 0
#define SMALL 12
#define NOT_SMALL 0
#define LARGE 13
#define NOT_LARGE 0
#define FULL 14
#define NOT_FULL 0
#define CHANCE 15
#define NOT_CHANCE 0
#define YAHTZEE 16
#define NOT_YAHTZEE 0
int game_menu (void);
void game_rules (void);
int roll_die (void);
int run_game (int die1, int die2, int die3, int die4, int die5);
int get_sum_one (int die1, int die2, int die3, int die4, int die5);
int get_sum_two (int die1, int die2, int die3, int die4, int die5);
int get_sum_three (int die1, int die2, int die3, int die4, int die5);
int get_sum_four (int die1, int die2, int die3, int die4, int die5);
int get_sum_five (int die1, int die2, int die3, int die4, int die5);
int get_sum_six (int die1, int die2, int die3, int die4, int die5);
int calculate_three_kind (int die1, int die2, int die3, int die4, int die5);
int get_four_of_a_kind (int die1, int die2, int die3, int die4, int die5);
int get_small_straight (int die1, int die2, int die3, int die4, int die5);
int get_large_straight (int die1, int die2, int die3, int die4, int die5);
int get_full_house (int die1, int die2, int die3, int die4, int die5);
int get_chance (int die1, int die2, int die3, int die4, int die5);
int get_yahtzee (int die1, int die2, int die3, int die4, int die5);
int choose_combination (int yahtzee, int chance, int full_house, int large_straight, int small_straight, int four_of_a_kind, int three_of_a_kind, int sum_one, int sum_two, int sum_three, int sum_four, int sum_five, int sum_six);
Function.c
#include "function.h"
int game_menu (void)
{
int choose = 0;
do {
system ("cls");
printf ("Yahtzee ");
printf ("%d. Print Game Rules. ", RULES);
printf ("%d. Start a game of Yahtzee. ", GAME);
printf ("%d. Exit ", EXIT);
scanf ("%d", &choose);
} while ((choose < RULES) && (choose > EXIT));
return choose;
}
void game_rules (void)
{
printf ("The scorecard used for Yahtzee is composed of two sections. A upper section and a lower section. ");
printf ("A total of thirteen boxes or thirteen scoring combinations are divided amongst the sections. ");
printf ("The upper section consists of boxes that are scored by summing the value of the dice matching the faces of the box. ");
printf ("If a player rolls four 3's, then the score placed in the 3's box is the sum of the dice which is 12. ");
printf ("Once a player has chosen to score a box, it may not be changed and the combination is no longer in play for future rounds. ");
printf ("If the sum of the scores in the upper section is greater than or equal to 63, then 35 more points are added ");
printf ("to the players overall score as a bonus. The lower section contains a number of poker like combinations. ");
}
int roll_die (void)
{
int die_value = 0;
die_value = rand () % 6 + 1;
return die_value;
}
int run_game (int die1, int die2, int die3, int die4, int die5)
{
int press = 0, roll = 0, number = 0, game = 0;
char yes = '', no = '';
do
{
printf (" Press any key in order to role the dice!!");
scanf ("%d", &press);
die1 = roll_die (1);
printf ("Die 1: %d ",die1);
die2 = roll_die (2);
printf ("Die 2: %d ",die2);
die3 = roll_die (3);
printf ("Die 3: %d ",die3);
die4 = roll_die (4);
printf ("Die 4: %d ",die4);
die5 = roll_die (5);
printf ("Die 5: %d ",die5);
roll++;
}while (press != press);
printf ("That is roll number %d ", roll);
while (roll < 3)
{
printf ("Would you like to use this role for a game combination?(press Y for yes or N for no) ");
scanf (" %c %c", &yes, &no);
if ((yes == 'y')||(yes == 'Y'))
{
printf("What combination would you like to use? ");
printf("(Press the number of the combination you would like to use.) ");
printf("%d. Sum of 1's. ", ONE);
printf("%d. Sum of 2's. ", TWO);
printf("%d. Sum of 3's. ", THREE);
printf("%d. Sum of 4's. ", FOUR);
printf("%d. Sum of 5's. ", FIVE);
printf("%d. Sum of 6's. ", SIX);
printf("%d. Three of a Kind. ", THREE_KIND);
printf("%d. Four of a Kind. ", FOUR_KIND);
printf("%d. Full House. ", FULL);
printf("%d. Small Straight. ", SMALL);
printf("%d. Large Straight. ", LARGE);
printf("%d. Yahtzee. ", YAHTZEE);
printf("%d. Chance ", CHANCE);
scanf("%d", &number);
}
else if ((no == 'n')||(no == 'N'))
{
printf("Would you like to keep any of the dice you just rolled? (press Y for yes and N for no) ");
scanf(" %c %c", &yes, &no);
if ((yes == 'y')||(yes == 'Y'))
{
printf ("Please enter the die number you would like to save.");
}
else
{
return 0;
}
}
}
while (roll == 3)
{
printf ("What combination would you like to use?");
printf("What combination would you like to use? ");
printf("(Press the number of the combination you would like to use.) ");
printf("%d. Sum of 1's. ", ONE);
printf("%d. Sum of 2's. ", TWO);
printf("%d. Sum of 3's. ", THREE);
printf("%d. Sum of 4's. ", FOUR);
printf("%d. Sum of 5's. ", FIVE);
printf("%d. Sum of 6's. ", SIX);
printf("%d. Three of a Kind. ", THREE_KIND);
printf("%d. Four of a Kind. ", FOUR_KIND);
printf("%d. Full House. ", FULL);
printf("%d. Small Straight. ", SMALL);
printf("%d. Large Straight. ", LARGE);
printf("%d. Yahtzee. ", YAHTZEE);
printf("%d. Chance ", CHANCE);
scanf("%d", &number);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.