CSCI 261 - Programming Concepts - Fall 2019

A6 - Yahtzee!

This assignment is due by Friday, November 01, 2019, 11:59 PM.
As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must be provided in accordance with the course collaboration policy.
Do not forget to complete the following labs with this set: L6A, L6B, L6C .

· Instructions · Rubric · Submission ·


Yahtzee!


For this assignment, we are going to implement most of a Yahtzee game and combine everything we have learned to date.

The first step to make Yahtzee is to know how to play. Here are the official rules. You can also play online here. Be sure to take note of two pieces of information each round:

  1. What conditions must be satisfied to earn points
  2. How many points are scored for each category

Play through a complete game. Who won?

After you've played at least one complete game, now it's time to start building out the game. We will do this incrementally, so be sure you have the current step working and tested before moving on to the next piece.


Rolling the Dice


Yahtzee is a dice game and a game of random chance. We need to simulate this random chance of a die rolling. Begin by creating a function called rollDie that has no input and returns an int as output. This function should generate a random value between 1 and 6, inclusive. Once you've tested your function is working properly, move on to the next step.

Next, we need to represent a hand of dice. From above, we are representing a single die as an int. Therefore, to represent a hand of dice, we will use an array of ints. Create a global constant to denote the hand size (of 5), since we will be using this value all over our program.

Once this array is created, let's create a function called printHand that accepts the array as input and has no output. Be sure to look ahead to zyBooks 6.12 about how to pass arrays to a function. This function should simply print out each element of the array to the screen.

We'll now make a third function called rollDice that accepts the array as input and has no output. The function should then call the rollDie function and assign each element of the array with a random value. At this point, your program should have output similar to:

Your hand is: 4 1 2 5 6

When you are happy with the operation of these two functions, continue on.


Playing a Round


Let's begin putting in place the mechanism for the player to roll three times. Wrap your prior code to roll and print a hand of dice in a loop. This loop should run three times or stop early if the player decides not to roll again. An example of these two scenarios is shown below:

Your hand is: 1 6 2 1 5
2 rolls remaining.
Do you want to roll again? (Y or N) Y
Your hand is: 2 1 6 2 5
1 rolls remaining.
Do you want to roll again? (Y or N) Y
Your hand is: 6 4 3 1 4
0 rolls remaining.
Your hand is: 1 5 2 3 2
2 rolls remaining.
Do you want to roll again? (Y or N) Y
Your hand is: 4 4 4 6 6
1 rolls remaining.
Do you want to roll again? (Y or N) N

Next, if the user chooses to roll again we need to ask the user which dice they would like to keep. We'll need to ask the player for each die if they want to keep it or roll it again. We'll store the player's decision in an array of bools. Asking the player which dice to keep is only the first part of this step. The second step is to also pass this second array as a second parameter to the rollDice function. We also need to modify the body of the rollDice function to only reroll the dice that the user chose not to keep. Now, our game looks like below:

Your hand is: 2 2 5 1 3
2 rolls remaining.
Do you want to roll again? (Y or N) Y
Do you want to keep die #1? (Y or N) Y
Do you want to keep die #2? (Y or N) Y
Do you want to keep die #3? (Y or N) N
Do you want to keep die #4? (Y or N) N
Do you want to keep die #5? (Y or N) N
Your hand is: 2 2 2 6 5
1 rolls remaining.
Do you want to roll again? (Y or N) Y
Do you want to keep die #1? (Y or N) Y
Do you want to keep die #2? (Y or N) Y
Do you want to keep die #3? (Y or N) N
Do you want to keep die #4? (Y or N) N
Do you want to keep die #5? (Y or N) Y
Your hand is: 2 2 3 4 5
0 rolls remaining.

Checking for Conditions


After the player has rolled three times, or chosen to not roll again, we need to inspect the current hand of dice and determine which scoring scenarios are present and their corresponding score. In Lab6A we distributed the task of creating all the functions. Copy the 26 functions from Piazza and add them to your project.

Scenario Description Points
Ones Ones Sum of Ones
Twos Twos Sum of Twos
Threes Threes Sum of Threes
Fours Fours Sum of Fours
Fives Fives Sum of Fives
Sixes Sixes Sum of Sixes
Three Of A Kind Three dice of the same value Sum of Dice
Four Of A Kind Four dice of the same value Sum of Dice
Full House Two dice of one value and three dice of a different value 25
Small Straight Four dice in a row (1-4, 2-5, 3-6) 30
Large Straight Five dice in a row (1-5, 2-6) 40
Yahtzee Five dice of the same value 50
Chance Any combination of dice Sum of Dice

When you are have all the functions, we will now ask the player which category they want to score. Present the player with a menu like the following:

Which category do you want to score this hand as?
( 1) Ones
( 2) Twos
( 3) Threes
( 4) Fours
( 5) Fives
( 6) Sixes
( 7) Three of a Kind
( 8) Four of a Kind
( 9) Full House
(10) Small Straight
(11) Large Straight
(12) Yahtzee!
(13) Chance
Category #: 

When the player provides their selection, print the corresponding score for that category.


Play the Game


Now to pull it all together. We now have the functionality to play one round of a Yahtzee game. We want the player to be able to play an entire game of Yahtzee. An entire game consists of 13 rounds. We need to have three components incorporated:

  1. The user can play thirteen rounds - each consisting of rolling and choosing a category to score.
  2. We need to keep track of the player's total score across all rounds.
  3. The player cannot score the same category twice.

A sample play of the first two rounds is shown below:

Your hand is: 4 5 3 1 2
2 rolls remaining.
Do you want to roll again? (Y or N) N

Which category do you want to score this hand as?
( 1) Ones
( 2) Twos
( 3) Threes
( 4) Fours
( 5) Fives
( 6) Sixes
( 7) Three of a Kind
( 8) Four of a Kind
( 9) Full House
(10) Small Straight
(11) Large Straight
(12) Yahtzee!
(13) Chance
Category #: 11
Your current score is: 40

Your hand is: 2 1 2 4 1
2 rolls remaining.
Do you want to roll again? (Y or N) Y
Do you want to keep die #1? (Y or N) Y
Do you want to keep die #2? (Y or N) Y
Do you want to keep die #3? (Y or N) Y
Do you want to keep die #4? (Y or N) N
Do you want to keep die #5? (Y or N) Y

Your hand is: 2 1 2 2 1
1 rolls remaining.
Do you want to roll again? (Y or N) N

Which category do you want to score this hand as?
( 1) Ones
( 2) Twos
( 3) Threes
( 4) Fours
( 5) Fives
( 6) Sixes
( 7) Three of a Kind
( 8) Four of a Kind
( 9) Full House
(10) Small Straight
(12) Yahtzee!
(13) Chance
Category #: 9
Your current score is: 65

Your hand is: 5 4 1 2 1
2 rolls remaining.
Do you want to roll again? (Y or N) N

Which category do you want to score this hand as?
( 1) Ones
( 2) Twos
( 3) Threes
( 4) Fours
( 5) Fives
( 6) Sixes
( 7) Three of a Kind
( 8) Four of a Kind
(10) Small Straight
(12) Yahtzee!
(13) Chance
Category #: 8
Your current score is: 65

Congratulations! You've implemented a fully functioning yahtzee game at this point. See what high score you can get.


Hints



Functional Requirements



Grading Rubric


Your submission will be graded according to the following rubric.

PointsRequirement Description
2 All code submitted properly.
6 All labs completed and submitted
L6A, L6B, L6C
3 Dice rolled & printed properly.
3 User interaction flow matches example (per single round and per complete game).
2 All Yahtzee functions included.
4 Functions placed in separate files.
8 Functional requirements above met.
2 (1) Comments used
(2) Coding style followed
(3) Appropriate variable names, constants, and data types used
(4) Instructions followed
30 Total Points

This assignment is due by Friday, November 01, 2019, 11:59 PM.
As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must be provided in accordance with the course collaboration policy.
Do not forget to complete the following labs with this set: L6A, L6B, L6C .


Submission


Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available. The following instructions are copied from How to Submit Homework.


It is critical that you follow these steps when submitting homework.

If you do not follow these instructions, your assignment will receive a major deduction. Why all the fuss? Because we have several hundred of these assignments to grade, and we use computer tools to automate as much of the process as possible. If you deviate from these instructions, our grading tools will not work. And that makes us very unhappy. And when we're unhappy, we give penalties. Thus, make us happy.


Submission Instructions



Here are step-by-step instructions for submitting your homework properly:
  1. File and folder names are extremely important in this process. Please double-check carefully, to ensure things are named correctly.
    1. The top-level folder of your project must be named Set6
    2. Inside Set6, create 4 sub-folders that are required for this Set. The name of each sub-folder is defined in that Set (e.g. L6A, L6B, L6C, and A6).
    3. Copy your main.cpp , additional header & source files (main.cpp, dice.h, dice.cpp, yahtzee.h, yahtzee.cpp) plus the CMakeLists.txt file into the subdirectories of Set6 (steps 1-2), zip this Set6 folder (steps 3-4), and then submit the zipped file (steps 5-11) to Canvas.
    4. For example, when you zip/submit Set6, there will be 4 sub-folders called L6A, L6B, L6C, and A6 inside the Set6 folder, and each of these sub-folders will have a file called main.cpp, additional header & source files, plus the CMakeLists.txt file .

  2. Using Windows Explorer (not to be confused with Internet Explorer), find the file named "main.cpp" located inside the folder for the particular lab or homework assignment you will submit.

    STOP: Are you really sure you are viewing the correct assignment's folder?

  3. Now, for A6, right click on the main.cpp to copy the file. Then, return to the Set6/A6 folder and right click to paste the file. In other words, put a copy of your homework's main.cpp source code into the Set6/A6 folder. Repeat this for each additional header & source file you have with this assignment, plus CMakeLists.txt.

    Follow the same steps for L6A, to put a copy of your lab's main.cpp into the Set6/L6A folder. Repeat this process for Set6/L6B, Set6/L6C.

    STOP: Are you sure your Set6 folder now has all your code to submit?

  4. Now, right-click on the "Set6" folder.
    1. In the pop-up menu that opens, move the mouse "Send to..." and expand the sub-menu.
    2. In the sub-menu that opens, select "Compressed (zipped) folder".

    STOP: Are you really sure you are zipping a Set6 folder with sub-folders that each contain a main.cpp file in it?

  5. After the previous step, you should now see a "Set6.zip" file.

  6. Now visit the Canvas page for this course and click the "Assignments" button in the sidebar.

  7. Find Set6, click on it, find the "Submit Assignment" area, and then click the "Choose File" button.

  8. Find the "Set6.zip" file created earlier and click the "Open" button.

    STOP: Are you really sure you are selecting the right homework assignment? Are you double-sure?

  9. WAIT! There's one more super-important step. Click on the blue "Submit Assignment" button to submit your homework.

  10. No, really, make sure you click the "Submit Assignment" button to actually submit your homework. Clicking the "Choose File" button in the previous step kind of makes it feel like you're done, but you must click the Submit button as well! And you must allow the file time to upload before you turn off your computer!

  11. Canvas should say "Submitted!". Click "Submission Details" and you can download the zip file you just submitted. In other words, verify you submitted what you think you submitted!
In summary, you must zip the "Set6" folder and only the "Set6" folder, this zip folder must have several sub-folders, you must name all these folders correctly, you must submit the correct zip file for this homework, and you must click the "Submit Assignment" button. Not doing these steps is like bringing your homework to class but forgetting to hand it in. No concessions will be made for incorrectly submitted work. If you incorrectly submit your homework, we will not be able to give you full credit. And that makes us unhappy.


This assignment is due by Friday, November 01, 2019, 11:59 PM.
As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must be provided in accordance with the course collaboration policy.
Do not forget to complete the following labs with this set: L6A, L6B, L6C .