A Yahtzee game made in C please! Objectives: Student should be able to: Define an array Manipulate and print an array Use parallel arrays Pass
A Yahtzee game made in C please!
Objectives:
Student should be able to:
- Define an array
- Manipulate and print an array
- Use parallel arrays
- Pass an array to a function
- Use pass by reference
- Calculate the frequency of items in an array
Introduction
In this project you will build a simplified version of thegame Yahtzee. You don’t have to know how to play Yahtzee - the rules and a version you can play online can befound here - https://cardgames.io/yahtzee/
Note:
This is not a multiplayer game. This only runs one turnfor one player so multiple Yahtzee can be ignored
The most important rules (from “card games io” link above) arelisted here:
YahtzeeRules
The objective ofYAHTZEE is to get as many points as possible by rolling five diceand getting certain combinations of dice.
Gameplay
In each turn aplayer may throw the dice up to three times. A player doesn't haveto roll all five dice on the second and third throw of a round, hemay put as many dice as he wants to the side and only throw theones that don't have the numbers he's trying to get. For example, aplayer throws and gets 1,3,3,4,6. He decides he want to try for thelarge straight, 1,2,3,4,5. So, he puts 1,3,4 to the side and onlythrows 3 and 6 again, hoping to get 2 and 5.
In this game youclick on the dice you want to keep. They will be moved down andwill not be thrown the next time you press the 'Roll Dice' button.If you decide after the second throw in a turn that you don't wantto keep the same dice before the third throw then you can clickthem again and they will move back to the table and be thrown inthe third throw.
Uppersection combinations
Ones: Get as many ones as possible.
Twos: Get as many twos as possible.
Threes: Get as many threes aspossible.
Fours: Get as many fours as possible.
Fives: Get as many fives as possible.
Sixes: Get as many sixes as possible.
For the sixcombinations above the score for each of them is the sum of dice ofthe right kind. E.g. if you get 1,3,3,3,5 and you choose Threes youwill get 3*3 = 9 points. The sum of all the above combinations iscalculated and if it is 63 or more, the player will get a bonus of35 points. On average a player needs three of each to reach 63, butit is not required to get three of each exactly, it is perfectly OKto have five sixes, and zero ones for example, as long as the sumis 63 or more the bonus will be awarded.
Lowersection combinations
Three ofa kind: Get three dice with the same number. Points arethe sum all dice (not just the three of a kind).
Four ofa kind: Get four dice with the same number. Points are thesum all dice (not just the four of a kind).
Fullhouse: Get three of a kind and a pair, e.g. 1,1,3,3,3 or3,3,3,6,6. Scores 25 points.
Smallstraight: Get four sequential dice, 1,2,3,4 or 2,3,4,5 or3,4,5,6. Scores 30 points.
Largestraight: Get five sequential dice, 1,2,3,4,5 or2,3,4,5,6. Scores 40 points.
Chance: You can put anything into chance, it'sbasically like a garbage can when you don't have anything else youcan use the dice for. The score is simply the sum of thedice.
YAHTZEE: Five of a kind. Scores 50points.
When you build the game, you will use an array to represent the5 dice values in Yahtzee. On a turn, the user rolls the diceto start. After the first roll, the user can choose to keep orre-roll any number of dice. After a selection is made, the user canroll the selected dice. The user can again make a selection androll those dice one last time. The user must accept the result ofthe final roll. A second, parallel array, will use be used to storethe user’s selection - whether to keep or re-reroll the dice. Thesearrays will act in parallel (the indexes line up). For example,given the two arrays below, the user wants to keep the 6s butre-roll the 1, 3 and 5.
Dice Array
6 | 1 | 3 | 6 | 5 |
Keep/ReRoll Array
1 | 0 | 0 | 1 | 0 |
Your program will start with the rolling and making selectionsand rolling again as just described. Once the rolls are completeyour task is to calculate scores for ALL categories and fill outthe scorecard. You will also notify the user of the best possiblescore for a single category.
Below you will find a starter code file with all the prototypeslisted. Your program must define functions for each of theseprototypes. You are welcome to add more, but you must define eachof the included prototypes.
The functions are explained below:
- void getFrequency(int dice_array[], intfrequency_array[])
- A function with input parameters of an array of dice values andan empty frequency array. The function fills the frequency arraywith the dice roll counts. This can be extremely helpful fordetermining 3 of a kind, 4 of a kind, Yahtzee, a full house, andothers.
- Example: Dice array [2, 2, 5, 1, 2] has afrequency of one 1, three 2s, zero 3s, zero 4s, one 5, zero 6s
- void printScoreCard(int scorecard[])
- A function in an input parameter of a scorecard array. Thefunction prints a neatly formatted version of the score card withcategories and scores
- int roll(void)
- a function that rolls (generates a random number) a single die(just one) and returns a value random value, 1 through 6
- void reRoll(int dice_array[], int keepArray[])
- a function with input parameters of the dice array and the keeparray. Uses the keep array to re-roll only those values indicatedby the keep and updates the dice array with new values
- this function should make calls to the roll function to get newdie values
- void printDice(int dice_array[])
- A function that prints the current dice values in a neatlyformatted manner
- int getChanceScore(int dice_array[])
- A function with input parameters of the dice array and returnsthe sum off all the dice (the chance category)
- int sumOfNum(int dice_array[], int num)
- A function with input parameters of the dice array and ininteger (from 1 to 6) that returns the sum off of the dice matchingthe specified number.
- Example: Dice array [2, 2, 5, 1, 2] with numset to 2 returns a sum of 6
- Example: Dice array [6, 6, 1, 2, 4] with numset to 5 returns a sum of 0
- Example: Dice array [6, 6, 1, 2, 4] with numset to 6 returns a sum of 12
- int getThreeOfKindScore(int dice_array[])
- This function has an input parameter of the dice array thatchecks if the dice contains a three of a kind. If so, it returns ascore for a three of a kind, otherwise it returns zero
- int getFourOfKindScore(int dice_array[])
- This function has an input parameter of the dice array thatchecks if the dice contains a four of a kind. If so, it returns ascore for a four of a kind, otherwise it returns zero
- int getSmallStraightScore(int dice_array [])
- This function has an input parameter of the dice array thatchecks if the dice contains a small straight. If so, it returns ascore for a small straight, otherwise it returns zero
- int getLargeStraightScore(int dice_array[])
- This function has an input parameter of the dice array thatchecks if the dice contains a large straight. If so, it returns ascore for a large straight, otherwise it returns zero
- int getFullHouseScore(int dice_array[])
- This function has an input parameter of the dice array thatchecks if the dice contains a full house. If so, it returns a scorefor a full house, otherwise it returns zero
- int getYahtzeeScore(int dice_array[])
- This function has an input parameter of the dice array thatchecks if the dice contains a yahtzee. If so, it returns a scorefor a yahtzee, otherwise it returns zero
You will need to model a score card. The score card is stored asan array of integers.
Requirements
- Model a single player turn of the game Yahtzee following thedescription above.
- Generate and array of dice values
- Display the dice values to the user
- Allow the user to determine which values to keep and which tore-roll.
- Re-roll only the dice the user has selected
- Display the Dice values
- Allow the user to select keep/roll again
- Display final dice value
- Calculate and Print all scores in the scorecard (some will bezeros)
- Note which is the highest score possible
- You must use parallel arrays as stated in theintroduction.
- Do not use any global variables. All variables must be definedin a function body (main function or other function) or from thefunction’s parameter list.
- You must use the starter code attached in blackboard
- You must implement the prototyped functions in the stater file(use as many other functions as you want)
- You must have a score card array for storing scores, but usingthe enum is optional
- Example program output is shown below
Step by Step Solution
3.36 Rating (162 Votes )
There are 3 Steps involved in it
Step: 1
include include include define HANDSIZE 5 define SCORECARDSIZE 13 declaring the functions for the various prototypes void getFrequencyint dicearray int frequencyarray void printScoreCardint scorecard ...See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started