Home | | Syllabus | | Assignments | | Lecture Notes
In this problem, you will complete the implementation of a program that simulates a dice game played between two players, player 1 and player 2. The game is a variation of the card game, Poker. The game consists of multiple rounds. In each round, the players each roll five dice. The combination of five dice values is ranked on a scale from 0 to 6 as follows:
rank 6: Five of a Kind:
all five dice have the same value
rank 5: Four of a Kind: four of the five dice have the
same value
rank 4: Full House: the dice include three of one value
and two of another
rank 3: Three of a Kind: three dice have the same value
and the remaining two have different values
rank 2: Two Pairs: the dice include two pairs of the
same values, and a fifth die of a different value
rank 1: One Pair: two dice have the same value, and the
remaining three have different values
rank 0: Nothing: all five dice have different
values
The player with the highest ranking roll of the dice wins the round. The player who wins the most rounds is the winner of the game.
In the ~csci132/assignments/assign1 folder is the skeleton of a program that simulates the playing of this dice game, with a few parts of the code filled in. There are 3 files, playDice.cc, player.h and player.cc. You should create a new directory in your home directory called "assignments", which you should protect by typing:
Copy the files from the csci132 directory into your own by typing:
You should be able to compile the code, but it does not do very much yet. The emacs compile command should look like:
The code for the client program, playDice.cc is provided for you, as has the player.h file. Your job is to implement the player class so that the playDice program works correctly. Note that the player object has 3 private data members:
The player object has 8 public member functions and 1 private member function.
The throwDice implementation should make use of the randomize function that has been provided for you:
Would you like to play a game (y/n)? y How many rounds (less than 10) would you like to play? 2 Round #1: Player 1 throws: Die #1 is a 6 Die #2 is a 3 Die #3 is a 5 Die #4 is a 5 Die #5 is a 6 Two Pairs, 2 points. Player 2 throws: Die #1 is a 2 Die #2 is a 3 Die #3 is a 5 Die #4 is a 2 Die #5 is a 4 One Pair, 1 point. Player 1 wins this round! Round #2: Player 1 throws: Die #1 is a 3 Die #2 is a 4 Die #3 is a 3 Die #4 is a 4 Die #5 is a 6 Two Pairs, 2 points. Player 2 throws: Die #1 is a 6 Die #2 is a 4 Die #3 is a 5 Die #4 is a 1 Die #5 is a 4 One Pair, 1 point. Player 1 wins this round! Player 1 wins the game! Would you like to play again (y/n)? n Thank you for playing Dice Poker!
Home | | Syllabus | | Assignments | | Lecture Notes
Constance Royden--croyden@mathcs.holycross.edu
Computer Science 132--Data Structures
Last Modified: January 28, 2014
Page Expires: January 14, 2015