Project 2: Farkle
Due: Friday, July 10 by 5:00pm
Updates
7/9 (2): We talked in class about the different types of output when a player's turn ends.
- When a player farkles, output should match Sample Output 2:
Enter command: roll Your roll: [4, 5, ] FARKLE. Turn over. It is now player 3's turn. - If a player types "finish", output should match Sample Output 2:
Enter command: finish Player 1 earned 4 points. It is now player 2's turn.
- If a player's turn ends because there are no remaining dice, you can print the normal roll output:
Enter command: roll Your roll: [1, 1, 1, 1, 1, 1, ] Roll worth 6 points. 0 dice remain.and then print whose turn is next:It is now player 2's turn.
You can choose to also print "Turn over." and/or "Player 1 earned 6 points." but you do not have to (this is because the project specification did not clarify this previously).
7/9 (1): Updated Dice.java to properly produce values [1,6]. Students can redownload this file if they choose; however, this should not impact your game in any way (previously it was not possible to roll a 6).
7/8: Note that the printTurn method should only print initialized and available dice (see Sample Output 2 and the turn command). Uninitialized dice (value of -1) and unavailable dice (value of 0) should not be printed; follow the same rules as for the two printDice methods.
7/7: Added example for step 3 in dice scoring (in Farkle Rules and Scoring, new text is in blue).
7/6: Output for the dice command added to sample output 2.
Overview
This project has several goals:
- Implement a program that uses multiple static methods
- Implement methods that call other methods
- Practice passing arguments to methods
- Practice returning values from methods
- Practice writing code using 1D- and 2D-arrays
- Learn how to read and interpret Javadoc method comments
In this project, you will build the dice game Farkle. In this game, players take turns rolling dice (regular 6-sided dice). Each roll may accumulate some points; your version of Farkle will have much simpler scoring than the original. A player's turn ends when their roll accumulates no points, when they run out of dice still in play, or when they decide to voluntarily end their turn. The game ends when some player accumulates the number of points necessary to win. The game is described more fully in Farkle Rules and Scoring.
You may work on this project in pairs. See pairs for more information.
Farkle Rules and Scoring
Farkle may be played by 2-6 players. At the start of the game, players get to decide how many points will be needed to win. Players then take turns rolling dice.
On each turn: A turn begins with six dice. The player may choose to roll or finish their turn. Additionally, they may print out the current dice (which are all initialized to 1 at the start of a turn), print out a record of all the dice rolled so far during their turn, or print out the current scores.
If a player rolls the dice: all active dice are rolled. At the start of a turn, this is all 6 dice. The dice are then scored by the game. Dice are scored as follows:
- Count the number of dice that show each number (1-6).
- The largest group (of size > 1) of dice of the same number will be worth points. The number of points is equal to the number of dice in the group.
- If more than one die number has the same size group, the smallest die number should be used.
E.g., if the roll is [4, 4, 3, 3, 5, 5, ], there are three groups of two dice (two 4s, two 3s, two 5s). The scoring dice are the two 3s, because 3 is less than 4 and 5. 2 points are earned because the group is of size two. - If no valid groups exist, 1 point can be earned if there is a die showing the number 1.
- Otherwise, 0 points are earned.
- Dice that are found to be worth points should be set to 0, indicating that they are no longer available to be re-rolled later in this turn.
If a roll earns points, these are added to a running total of points for this turn. If there are dice still available for re-roll, the user may choose to roll or finish their turn. If no dice are available for re-roll, the user's score should be updated to reflect the total points they accumulated during this turn, and the next player begins their turn.
If a roll does not earn any points, the game prints Farkle! to the console and this user's turn is over. The user does not accumulate any points from their turn.
If a player chooses to finish their turn: their score should be updated to reflect the total number of points they accumulated during this turn, and the next player begins their turn.
The game ends when a user finishes their turn and has scored at least the number of points necessary to win the game.
Details
Start by creating a new project in Eclipse and copying Farkle.java and Dice.java to your project folder. You must use these files for this project. See Project 1 for a refresher on how to do this. You should NOT modify Dice.java in any way. When we test your code, we will use this original version.
In this project, you will be implementing all methods provided in Farkle.java. You may also implement your own methods in addition to the provided methods, but they must be declared private static. You may not add any static fields (class variables). All code must be contained in the Farkle class.
Being able to read and understand Javadoc files is an important part of Java programming. The methods in Farkle.java are described in this javadoc file. Dice.java is described here. Javadoc pages document Java classes and methods. They contain uniformly formatted explanations of the classes and methods in Java programs. The javadoc for this project was generated from the comments we provided in the code skeleton.
When you first open the link, you will be taken to the page for the Farkle class. Scroll down to the Method Summary. This section provides information about the methods you are required to implement for this project. Each method has a short summary that displays the return type, method name, and input parameters, followed by a brief description.
If you click on a method name, it will take you to a full description of the method. These descriptions describe in detail what each method does, and many provide example usage. You should refer to these documents frequently as you work on this project.
You should read though Farkle.java and the provided Farkle class javadoc and Dice class javadoc.
You will need to edit each provided method's body (including main!) so that it implements the functionality described in the Javadoc and the program. When we grade this project, we will test individual methods to verify that they work as specified. Your program output should match the sample output provided below. For this project, you may assume that we will provide valid user input; that is, you do not need to implement input validation.
Sample Output
Note: both of these output sequences were generated with the original Dice.java file. To replicate, nextInt must be called with 5 inside Dice.java, instead of the updated (and correct) value of 6.
Sample Output 1: help and exitWelcome to Farkle. How many players? 2 How many points do you need to win? 10 Game will play until 10 points. It is now player 1's turn. Enter command: help "roll" - roll the dice "finish" - terminate the current turn "dice" - print the current dice "turn" - print the current turn so far "scores" - print scores "help" - print this help menu "exit" - terminates the game Enter command: exit Game over. Player 1: 0 Player 2: 0 Game ended before there was a winner.
Sample Output 2: Normal game
(Output for the dice command added on 7/6)
Welcome to Farkle. How many players? 3 How many points do you need to win? 6 Game will play until 6 points. It is now player 1's turn. Enter command: roll Your roll: [1, 4, 4, 5, 1, 1, ] Roll worth 3 points. 3 dice remain. Enter command: roll Your roll: [1, 4, 5, ] Roll worth 1 points. 2 dice remain. Enter command: turn [1, 4, 4, 5, 1, 1, ] [1, 4, 5, ] 4 points so far this turn. Enter command: dice [4, 5, ] Enter command: finish Player 1 earned 4 points. It is now player 2's turn. Enter command: roll Your roll: [4, 3, 3, 2, 3, 2, ] Roll worth 3 points. 3 dice remain. Enter command: roll Your roll: [3, 2, 1, ] Roll worth 1 points. 2 dice remain. Enter command: roll Your roll: [4, 5, ] FARKLE. Turn over. It is now player 3's turn. Enter command: roll Your roll: [1, 4, 2, 4, 4, 2, ] Roll worth 3 points. 3 dice remain. Enter command: roll Your roll: [1, 4, 3, ] Roll worth 1 points. 2 dice remain. Enter command: finish Player 3 earned 4 points. It is now player 1's turn. Enter command: scores Player 1: 4 Player 2: 0 Player 3: 4 Enter command: roll Your roll: [2, 1, 2, 1, 1, 3, ] Roll worth 3 points. 3 dice remain. Enter command: finish Player 1 earned 3 points. Game over. Player 1: 7 Player 2: 0 Player 3: 4 Player 1 wins!
Working in Pairs
For the project, you may work in pairs. Both partners must be currently enrolled in CS 302-001. If you choose to work with a partner, you must follow the rules below.
Rules for Pair Programming
- You may only have one partner for this project
- You may have a different partner for future projects
- You may not pair program with multiple partners on the same project
- Once you start working with a partner on a project, you must complete the project with that partner.
- You must list your partner as a collaborator in the header comments of your source files
- Only one partner will submit .java files via the Dropbox for this project. However, both partners must submit a README file that lists the full names of both partners
- You must follow the principles of pair programming summarized below
Principles of Pair Programming
This summary of pair principle principles was summarized by Finn Kuusisto from a paper by Williams and Kessler:
- Pair programming involves two people working together at one computer, continuously collaborating on design, coding, and testing. One person types; the other either provides directions ("Now we need to write a new method that does ..., Now we need a loop to do ...") or constantly reviews what the typer is doing, and provides comments.
- Pair programming has proved successful both in classes and in industry. Programmers usually report having more confidence in their solutions and enjoying programming more when working in pairs.
- It is important to switch roles often (slide the keyboard back and forth). Because pair programming can be quite intense, it is also a good idea to take breaks (to check e-mail, go for a walk, have a snack).
- It is important to provide honest but friendly feedback. To be effective, there needs to be some healthy disagreement and debate, but pairs also need to be respectful of each other, and try to avoid becoming defensive when receiving criticism.
- Inevitably, programmers do some independent thinking/working. For best results, that work should be reviewed by both partners (and perhaps revised) when they start working together again.
- To be successful, pair programmers must realize that the benefits of working together outweigh their usual preference for working alone, they must confidently share their work, accepting instruction and suggestions for improvement in order to improve their own skills and the code they are writing, and they must accept ownership of their partner's work and thus be willing to constructively express criticism and suggest improvements.
What to Turn In
Before you submit your work, check the following:
- Is your source file named Farkle.java?
- Is the entirety of your program in a single class, Farkle?
- Did you implement all of the methods specified in the skeleton file and Javadoc, making sure to not alter the method names, parameters, or return values in any way?
- Does your program match the sample output?
- If you worked on your own computer, did you verify that your program works correctly on a lab computer?
- Did you follow the style and commenting guidelines?
To submit:
- Upload Farkle.java to the Project 2 Dropbox folder on Learn@UW.
- Do not upload Dice.java.
- If you worked with a partner: only one partner should submit Farkle.java. Both partners must submit a README file that contains the full names of both partners.