Handout 32
Spring 2011
May 13
th
, 2011
Assignment 6: Yahtzee
Assignment originally crafted by Todd Feldman, and then refined by Julie Zelenski and Eric Roberts.
Now that you have arrays at your disposal, your ability to write interesting programs takes a
dramatic leap forward.
To solidify your understanding, Assignment 6 uses arrays in a
variety of contexts to implement a popular multiplayer dice game.
There are arrays for the
dice, arrays for the player names, arrays for a player’s score, and even an array of arrays to
handle the entire scorecard.
By the time you’re done, you will be well on your way to
mastering this critical concept.
Due: Monday, May 23
rd
at 11:59 p.m.
The goal
Your task is to create a computer version of the game Yahtzee
™
.
Some of you may have
already played the game, but for those who haven’t, it’s simple to learn.
There are five
dice and one to four players.
A
round
of the game consists of each player taking a turn.
On each
turn
, a player rolls the five dice with the hope of getting them into a configuration
that corresponds to one of 13 categories (see the following section on "Dice Categories").
If
the first roll doesn’t get there, the player may choose to roll any or all of the dice again.
If
the second roll is still unsuccessful, the player may roll any or all of the dice once more.
By the end of the third roll, however, the player must assign the final dice configuration to
one of the thirteen categories on the scorecard.
If the dice configuration meets the criteria
for that category, the player receives the appropriate score for that category; otherwise the
score for that category is 0.
Since there are thirteen categories and each category is used
exactly once, a game consists of thirteen rounds.
After the thirteenth round, all players will
have received scores for all categories.
The player with the total highest score is declared
the winner.
Dice categories
The thirteen categories of dice configurations and their scores are:
1.
Ones
.
Any dice configuration is valid for this category.
The score is equal to the
sum of all of the 1’s showing on the dice, which is 0 if there are no 1’s showing.
2–6.
Twos
,
Threes
,
Fours
,
Fives
, and
Sixes
.
(same as above but for different values).
Any
dice configuration is valid for these categories. The score is equal to the sum of the
2’s, 3’s, 4’s, and so on, showing on the dice.
7.
Three of a Kind
.
At least three of the dice must show the same value.
The score is
equal to the sum of all of the values showing on the dice.
8.
Four of a Kind
.
At least four of the dice must show the same value.
The score is
equal to the sum of all of the values showing on the dice.
9.