Knowee
Questions
Features
Study Tools

23.26 LAB*: Program: Poker dice gameProgram Specifications Write a program to calculate the score from a throw of five dice. Scores are assigned to different categories for singles, three of a kind, four of a kind, five of a kind, full house, and straight. Follow each step to gradually complete all functions.Note: This program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress.Step 0. Review the provided main() function. Five integer values are input and inserted into a vector. The vector is sorted and passed to FindHighScore() to determine the highest scoring category. Make no changes to main(). Stubs are provided for all remaining functions.

Question

23.26 LAB*: Program: Poker dice gameProgram Specifications Write a program to calculate the score from a throw of five dice. Scores are assigned to different categories for singles, three of a kind, four of a kind, five of a kind, full house, and straight. Follow each step to gradually complete all functions.Note: This program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress.Step 0. Review the provided main() function. Five integer values are input and inserted into a vector. The vector is sorted and passed to FindHighScore() to determine the highest scoring category. Make no changes to main(). Stubs are provided for all remaining functions.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The question seems to be asking for a step-by-step guide on how to write a program for a poker dice game. Here's a general outline on how you might approach this:

Step 1: Define the main function The main function is already provided for you. It takes five integer inputs (representing the dice throws) and inserts them into a vector. The vector is then sorted and passed to the FindHighScore() function.

Step 2: Create the FindHighScore() function This function should take the sorted vector as an input and determine the highest scoring category. You'll need to define the scoring categories (singles, three of a kind, four of a kind, five of a kind, full house, and straight) and the scoring rules for each category.

Step 3: Implement the scoring rules For each category, write a separate function that checks if the sorted vector matches the category's criteria. For example, for three of a kind, you might write a function that checks if there are three integers in the vector that are the same.

Step 4: Call the scoring functions in FindHighScore() In the FindHighScore() function, call each of the scoring functions you wrote in step 3. If a scoring function returns true, add the score for that category to a total score variable.

Step 5: Return the highest score After all the scoring functions have been called, return the total score variable from the FindHighScore() function. This will be the highest score from the throw of the five dice.

Remember to test your program thoroughly to ensure it's working as expected.

This problem has been solved

Similar Questions

A Dice class representing a set of 6-sided dice that can be rolled by a player, is to be implemented as below:Member    Descriptionprivate: int* diceValues   an array of all dice values rolledprivate: int count   length of diceValues arrayDice(int count)   constructs a dice roller to roll the given # of dice; all dice initially have the value of 6virtual int getCount() const   returns the number of dice managed by this dice roller, as passed to the constructorvirtual int getValue(int index) const   returns the die value (1-6) at the given 0-based indexvirtual void roll(int index)   rolls the given die to give it a new random value from 1-6virtual int total() const   returns the sum of all current dice values in this dice rollervirtual string toString() const   returns string of dice values, e.g. "{4, 1, 6, 5}"ostream& operator <<(ostream& out, Dice& dice)   prints the given dice in its toString format

Below is given a board game that Honey and Sunny are playing. They both start from the box showing 'start'. They throw a dice that can show a number from 1 to 6. On the basis of the number that has come on dice, the player who has thrown the dice moves that many steps in the direction as represented by arrows. The boxes on which a player reaches during the game, the numbers on those boxes are added together to get the score of that player. Player reaching box representing 'end' first wins the game. If none of them is able to reach the box representing 'end' in 6 turns, the game results in a draw. Honey has the first turn.If in his first three turns, Honey gets 2, 3 and 6 on the dice, respectively, then what would be his score after three turns?

The game that you developed in Lab 8 is boring and you need a break from the assignment. You decide to spice up your previous program up by morphing it into a game of Two-Dice Pig. Once again, the game is played against the computer. Game Play During each turn, the player repeatedly rolls both dice until either a 1 is rolled or the player decides to hold. If neither die shows a 1, their sum is added to the turn total. If a single 1 is rolled, the player scores nothing and the turn ends. If two 1s are rolled, the player's entire score is lost and the their turn ends. The first player to score100 or more points wins the game. An example of the basic dice game can be found here: http://cs.gettysburg.edu/projects/pig/piggame.html The only difference between the Two-Dice Pig and the basic game is the addition of the above-mentioned rules and the use of two dice instead of one. Interface The interface of the game is text-based. The game starts by prompting the player for their name with the message What is your name?. The game then greets the player by their chosen name and displays the instructions of the game: The first player that reaches 100 wins. Enter 'r' to roll the dice. -If you roll a '1', you lose all your points for the roll and your turn. -If you roll two '1's, you lose all your score and your turn. Enter 'h' to hold your points and pass the turn to the next player. Enter 'q' at any time to quit the game. Humans go first. At each turn, the game displays the current score for both players in this format and indicates the player's turn. Score: {human_player} - {human_player_score}, Computer - {computer_score} It is now {player_name} turn... where {human_player} and {human_player_score}is replaced by the player's name and score respectively i.e. your score. {player_name} is always either the player's chosen name or Computer. If it is your turn, the program prompts the player to make a decision with the message What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)?. These are the commands recognized by the program: r or R: Roll dice h or H: Player wants the game to hold the current score and pass their turn to the Computer. q or Q: Stops game and exits with the message See you again. If the player attempts to hold before rolling the dice, the program informs the player You have not rolled the dice yet. and re-prompts the player for another decision. If the player enters neither of the above commands, the game displays I don't understand... and re-prompts for another decision from the player. Note that these prompts would not happen when it is the Computer 's turn. During each turn, the program displays the result of the roll with the message: You have rolled: {dice1} {dice2} where {dice1} and {dice2} is replaced with the current value shown on each dice. When one player reaches 100 first, the game declares the winner with the message {player_name} wins! and stops. Computer The Computer will automatically continue to roll until they score at least 15 points on each roll. Once they achieve this, they will decide to hold and pass the turn to the human player. Players can change this limit by passing a positive integer via command line argument. Your program must raise a ValueError exception with the message Must be positive integer. when the argument received is less than or equals to 0. If no arguments are received or invalid arguments are received, the Computer will attempt to score 15 points at each turn i.e. the default limit is 15, and the first line of your program should print what the error was in the format <exception type>: <error message>. Example valid command line arguments: $ python3 pig_double.py 30 # Sets the limit to 30 $ python3 pig_double.py 15 # Sets the limit to 15 again. Example invalid command line arguments where the limit will default to 15: $ python3 pig_double.py 5.5 # Invalid $ python3 pig_double.py fifteen # Invalid Program Execution and Sample Run The auto-marker will only start pig_double.py. User inputs are pre-appended with #. Sample Run 1 The player's name is Pig in this example. Both Pig and Computer does not have much luck and Pig quits after playing a few rounds with Computer. $ python3 pig_double.py 30 What is your name human? #Pig Hi, Pig. The first player that reaches 100 wins. Enter 'r' to roll the dice. -If you roll a '1', you lose all your points for the roll and your turn. -If you roll two '1's, you lose all your score and your turn. Enter 'h' to hold your points and pass the turn to the next player. Enter 'q' at any time to quit the game. Humans go first. Score: Pig - 0, Computer - 0 It is now Pig turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #roll I don't understand... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 1 4 Score: Pig - 0, Computer - 0 It is now Computer turn... You have rolled: 4 4 You have rolled: 5 2 You have rolled: 2 4 You have rolled: 1 5 Score: Pig - 0, Computer - 0 It is now Pig turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #h You have not rolled the dice yet. What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 3 6 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #h Score: Pig - 9, Computer - 0 It is now Computer turn... You have rolled: 1 1 Score: Pig - 9, Computer - 0 It is now Pig turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 6 5 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 2 2 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #h Score: Pig - 24, Computer - 0 It is now Computer turn... You have rolled: 2 2 You have rolled: 2 4 You have rolled: 4 6 You have rolled: 1 3 Score: Pig - 24, Computer - 0 It is now Pig turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 1 4 Score: Pig - 24, Computer - 0 It is now Computer turn... You have rolled: 5 6 You have rolled: 5 2 You have rolled: 1 3 Score: Pig - 24, Computer - 0 It is now Pig turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 5 4 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 3 1 Score: Pig - 24, Computer - 0 It is now Computer turn... You have rolled: 1 1 Score: Pig - 24, Computer - 0 It is now Pig turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 3 6 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #j I don't understand... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 1 1 Score: Pig - 0, Computer - 0 It is now Computer turn... You have rolled: 4 2 You have rolled: 6 3 You have rolled: 1 2 Score: Pig - 0, Computer - 0 It is now Pig turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #q See you again. Sample Run 2 The player's name is Pug in this example. Computer will continuing rolling until they achieve 25 points. Pug is the winner for this example. $ python3 pig_double.py 25 What is your name human? #Pug Hi, Pug. The first player that reaches 100 wins. Enter 'r' to roll the dice. -If you roll a '1', you lose all your points for the roll and your turn. -If you roll two '1's, you lose all your score and your turn. Enter 'h' to hold your points and pass the turn to the next player. Enter 'q' at any time to quit the game. Humans go first. Score: Pug - 0, Computer - 0 It is now Pug turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 2 3 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 2 1 Score: Pug - 0, Computer - 0 It is now Computer turn... You have rolled: 5 6 You have rolled: 1 3 Score: Pug - 0, Computer - 0 It is now Pug turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 3 5 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 2 6 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 4 4 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #h Score: Pug - 24, Computer - 0 It is now Computer turn... You have rolled: 1 6 Score: Pug - 24, Computer - 0 It is now Pug turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 3 1 Score: Pug - 24, Computer - 0 It is now Computer turn... You have rolled: 5 5 You have rolled: 4 6 You have rolled: 2 2 You have rolled: 6 5 Score: Pug - 24, Computer - 35 It is now Pug turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 6 2 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 2 4 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #h Score: Pug - 38, Computer - 35 It is now Computer turn... You have rolled: 5 3 You have rolled: 3 1 Score: Pug - 38, Computer - 35 It is now Pug turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 6 4 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 6 2 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #h Score: Pug - 56, Computer - 35 It is now Computer turn... You have rolled: 6 4 You have rolled: 2 1 Score: Pug - 56, Computer - 35 It is now Pug turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 6 4 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 3 3 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #h Score: Pug - 72, Computer - 35 It is now Computer turn... You have rolled: 4 1 Score: Pug - 72, Computer - 35 It is now Pug turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 3 4 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 4 4 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #h Score: Pug - 87, Computer - 35 It is now Computer turn... You have rolled: 6 1 Score: Pug - 87, Computer - 35 It is now Pug turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 2 6 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 4 6 What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #h Pug wins! Sample Error Case The player's name is Pug in this example. -20 is an invalid limit to give Computer, so a ValueError message is displayed and the limit is set to a default of 15. $ python3 pig_double.py -20 ValueError: Must be a postitive integer. What is your name human? #Pug Hi, Pug. The first player that reaches 100 wins. Enter 'r' to roll the dice. -If you roll a '1', you lose all your points for the roll and your turn. -If you roll two '1's, you lose all your score and your turn. Enter 'h' to hold your points and pass the turn to the next player. Enter 'q' at any time to quit the game. Humans go first. Score: Pug - 0, Computer - 0 It is now Pug turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #r You have rolled: 1 1 Score: Pug - 0, Computer - 0 It is now Computer turn... You have rolled: 5 5 You have rolled: 2 3 Score: Pug - 0, Computer - 15 It is now Pug turn... What do you want to do ('q' to quit game, 'r' to roll, 'h' to hold)? #q See you again. Please ensure your game is entirely runnable from the main function; do NOT have code in the global scope. Let's practice writing on paper for our in-person tests and exam. Take out a piece of paper and answer the following questions. Upload an image (in pdf) of your answers to the workspace. File size must be less than 5MB.

What is output of below program?int main(){int i,j,count;count=0;for(i=0; i<5; i++);{for(j=0;j<5;j++);{    count++;}}printf("%d",count);return 0;}                                                                                               (A) 55(B) 54(C) 0(D) 1

For this assignment you will write the first part of a program that will play a simple "Guess the Number" game. In the full version of this game (which you will write for this week's project) the program will randomly generate an integer between 1 and 200 inclusive and then will repeatedly ask the user for a guess. If they guess a number that is less than 1 or more than 200 an error message will be printed as a part of this loop. For this lab you will write the piece of the code that checks for this error and ends if the user picks the right number.Sample Output This is a sample transcript of what your program should do. Items in bold are user input and should not be put on the screen by your program. Note that the code for this lab includes a "debugging" output that starts with the word "DEBUG: " that tells you the number that was randomly chosen. In the full version of this program that will be removed, but for this incremental piece your lab submission should include it. (You should get used to having this kind of debugging output in your code that isn't part of the final program but is crucial to ensuring that each incremental piece is working properly before you move onto the next part of the program).If the user enters an invalid choice, your code should inform them that their choice was invalid and ask them to guess again.Enter a random seed: 99DEBUG: The number picked is: 188Enter a guess between 1 and 200: 259Your guess is out of range. Pick a number between 1 and 200.That is not the number.Enter a guess between 1 and 200: -1Your guess is out of range. Pick a number between 1 and 200.That is not the number.Enter a guess between 1 and 200: 88That is not the number.Enter a guess between 1 and 200: 188Congratulations! Your guess was correct!I had chosen 188 as the target number.You guessed it in 4 tries.Random numbers: Just like in the FunWithBranching programming assignment, you must use the Random class to generate numbers between 1 and 200. Make sure you are using int values and not doubles for this assignment! Look back at your submitted code for that project and reuse what you can here - reusing code from old assignments isn't only allowed, it's ENCOURAGED! If you've solved a problem once you should remind yourself how you solved it when asked to do something similar!

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.