CSCI 261 - Programming Concepts (C++)Summer 2018 - A5 - Yahtzee!Quick Links: Canvas | CS @ Mines | Piazza | zyBooks |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home | Contact | Syllabus | Assignments | Schedule | Resources | | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This assignment is due by Friday, June 01, 2018 11:59 PM. 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:
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 int s. 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 5.13 about how to pass arrays to a function, we will cover this next week. 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
bool s. 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. This part will give you practice writing functions,
as you will write at least 13 of them (probably 15 if done properly). We need to write a function
for each of the scenarios below. The table lists each scenario, the conditions for it to be scored, and the
corresponding score if present. You should notice that all of the functions have a similar signature (same input/output
but different names). We'll want to name the functions using the following scheme:
scoreOnes ,
scoreTwos , etc.
After you complete the first two functions for scoring ones and twos, have you noticed that they are very
similar save for one detail? Perhaps that can be extracted into its own function that can then be called
six times. When you are happy with the performance of each function, 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:
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 RubricYour submission will be graded according to the following rubric.
This assignment is due by Friday, June 01, 2018 11:59 PM. SubmissionAlways, 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:
In summary, you must zip the
"Set5" folder
and only the "Set5" 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" 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, June 01, 2018 11:59 PM. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Last Updated: 05/24/18 23:35
|