# CS1007 Fall 2002 Homework #4 due Thu Nov 7, by 6AM -- electronic submission EXTENDED TO TUE NOV 12

hardcopy due in class: 2.45PM

goal.
The goals of this assignment are to:

1. learn about inheritance and extend a class
2. learn how to use arrays of objects

the game.
You need to write a program to play a variation of the game of Yahtzee. This is a game played with 5 dice. Your program will roll all the dice and your objective is to obtain the highest score you can in each of 10 categories:

1. ones
2. twos
3. threes
4. fours
5. fives
6. sixes
7. 3-of-a-kind
8. 4-of-a-kind
9. 5-of-a-kind
10. full house (3-of-a-kind and 2-of-a-kind)
The rules are specified in detail here.

Your program will determine which scoring category is the best fit for each roll. Remember that you can only record an entry in a category once. If you cannot meet the criteria of a category, then you must score zero (0) for that category. For example, if the only category left to fill is 5-of-a-kind and you don't roll 5-of-a-kind, then you must score 0 for that category. You need to devise your own strategy for determining the best way to maximize your score over the 10 turns.

Write a description of your strategy and include it in the header comment of your player class (described below).

program.

1. (2.25 points total) Create a class called `Die.java` that contains:
• a private value for a single die (i.e., 1 through 6) (0.25 points)
• a public method for getting that value outside of the class (0.5 points)
• a public method for "rolling" the die (i.e., randomly picking setting the value to a number between 1 and 6) (1.0 points)
• a `toString()` method that returns the value of the die as a `String` (0.5 points)

2. (4.75 points total) Create a Java program that implements your game strategy:
1. Name your program file `hw4<your_cunix_id>.java`. For example, mine is called `hw4eis2003.java`.
2. You hw4 class must extend my `Player` class. (0.25 points)
3. You may declare any additional global constants and variables, as you need them.
4. You may override or overload the constructor, if necessary.
5. You may NOT override or overload the `tally()` or the `totalScore()` methods.
6. You can create any additional methods you might need.
7. You MUST override the `main()` method in order to implement your strategy. Note that the strategy in my Player class is very stupid and always scores 0. As above, you can create and define any additional constants, variables and methods you need to implement your strategy. (4.0 points)
8. As shown in the sample run, you must print out the contents of the dice and the score for the category after each turn. I suggest that you also print out the dice after each roll (since you can roll any or all dice up to 3 times in a turn), so you can make sure that your program is running correctly. (0.25 points)
9. You must print out the TOTAL score at the end of the game, using the same format as in my version (0.25 points):
```	System.out.println( "TOTAL = " + p.totalScore() )
```
3. Extra credit (2 points).
For 2 points possible extra credit, add a method to your `Die` class that draws the dice as they are shown on my rules page.

fun tournament.
For fun, we'll hold a tournament between everyone's working players, to see whose strategy works best. The winner(s) will receive C++ books.

sample run.
Here's a sample run, illustrating my extension of Player.java. Note that this implements a terribly simple strategy that simply cycles through each category in order and scores accordingly. I don't roll the dice more than once in a turn -- though you can roll up to three times, as described in the rules.

```unix\$ java hw4eis2003
you have rolled:
[1]  [1]  [5]  [2]  [3]
score = 2  category = ones
you have rolled:
[1]  [1]  [3]  [2]  [3]
score = 2  category = twos
you have rolled:
[1]  [6]  [2]  [3]  [5]
score = 3  category = threes
you have rolled:
[1]  [4]  [2]  [4]  [5]
score = 8  category = fours
you have rolled:
[5]  [2]  [1]  [6]  [3]
score = 5  category = fives
you have rolled:
[6]  [6]  [1]  [2]  [5]
score = 12  category = sixes
you have rolled:
[6]  [3]  [3]  [1]  [2]
score = 0  category = 3-of-a-kind
you have rolled:
[5]  [4]  [2]  [6]  [5]
score = 0  category = 4-of-a-kind
you have rolled:
[2]  [6]  [5]  [1]  [5]
score = 0  category = 5-of-a-kind
you have rolled:
[5]  [3]  [2]  [6]  [5]
score = 0  category = full-house
TOTAL = 32
unix\$
```

source code.
Your source code (i.e., your `.java` file) but be neat and clearly commented. You must have a header comment at the top of each file and you should comment the end of each block (i.e., each `}`). You must also have a comment block at the beginning of each method. In your extension of the Player class, you must specify if you are overloading or overriding any methods from the base class.

submission.
Follow the submission instructions carefully!!! If you don't, human intervention will be required to fix your mistakes, and you will lose 1 point.

1. Name your player file properly.
Your PLAYER file MUST be named `hw4<yourCUNIXusername>.java`
For example, mine is called `hw4eis2003.java`.

You need to turn in ALL the Java source code, e.g., the files named `Die.java` and `hw4eis2003.java`. Follow instructions on the assignments page.

3. Turn in a harcopy of your program during THE FIRST 5 MINUTES OF class.
Print out the homework template cover page (http://www.columbia.edu/~cs1007/hw-template.html) and fill it out.
Staple the cover page to a hardcopy (print-out) of your program. You need to turn in ALL the Java source code, e.g., the files named `Die.java` and `hw4eis2003.java`. Make sure your name is on all the papers you hand in!
Bring the cover page and hardcopy to class on the day the assignment is due and deposit it in the homework box at the front of the classroom within the first 5 minutes of the class (by 2.45pm)

points.
This assignment is worth 10 points (out of 100 for the semester). Distribution of points is:

• 1.0 point for following submission instructions (i.e., no human intervention required)
• 1.0 point for commenting source code and using a clear programming style (i.e., indenting code consistently, using meaningful variable names, etc.)
Note that a large portion of this (4 points) is for implementing your strategy as you've described it in your header comment. Your strategy doesn't have to be particularly clever in order to get full marks -- it just has to work properly. This means you need to be able to figure out the score for each category correctly. Even my silly program (in the sample run, not the stupid version in Player) that just cycles through the categories in order and computes a score would receive full marks. `:-)`