CMSI 186 Problem Set #1
A New Dice Game
Due Thursday, January 25
- For this assignment, you will implement a dice game in which two players- one computer, one human- roll dice (of a rather general sort). Refer to the Official Rules for a New Dice Game.
- Your main file should be called NewDiceGame.java, and the program will be invoked via java NewDiceGame points, where optional argument points is a positive number that indicates the number of points for this game (default = 100).
- You must sketch out the overall structure of your program- and, especially, the major classes and their relationships- before you start coding.
- You must write unit tests for all of your classes before you begin coding the members of those classes. Each class' main method should invoke a comprehensive suite of tests for all of the members (i.e., methods) of that class.
Official Rules for a New Dice Game
- There are two players.
- The game proceeds by rounds, one round at a time, until some player reaches the predetermined number of points.
- The human player goes first on all odd-numbered rounds; the computer player goes first on all even-numbered rounds.
- The protocol for a single round is as follows (players are identified as p1 and p2):
- p1 selects the number of dice for this round, n (must be at least 1).
- p2 selects the number of sides for this round, k (must be at least 2).
- p1 rolls n k-sided dice. Let f1 be the number of occurrences of the most frequent value among the dice multiplied by that value. In case of a tie for most frequent value, choose the highest such value.
- p2 rolls n k-sided dice. Let f2 be the number of occurrences of the most frequent value among the dice multiplied by that value. Again, in the event of a tie for most frequent value, choose the highest such value.
- If f1 > f2, then p1 gets their difference, f1-f2, in points; otherwise, p2 gets f2 - f1 points.
- Here's an example of how the first round might proceed; since it's an odd-numbered round, the human player goes first:
- Human selects n = 8.
- Computer selects k = 5.
- Human proceeds to roll 8 5-sided dice, which come up 3,1,3,5,3,3,2,1; the high-frequency number is 3, which appears 4 times, so f1 = 3 * 4 = 12.
- Computer proceeds to roll 5,2,5,2,1,2,5,3; both 2 and 5 appear 3 times, so (we take the 5 and) f2 = 5 * 3 = 15.
- Consequently, Computer wins 15 - 12 = 3 points.
Suggestions
- My main program for this problem consists, basically, of one line: new Moderator().startTheGame(). My moderator (object) can only do a few things, like start the game, award points to one player or the other, decide when to end the game, etc.
- I have a class called Player: one Player object represents the human, another represents the computer. Among other things, I can ask a player to select a number within a certain range.
-
I have defined a class called Dice; each object of this class is, in turn, composed of objects from my class Die.
- Click here for a summary of class Dice
- Click here for a summary of class Die
Return to: CMSI 186 home page
Revised: January 12, 2007