600.107 Introduction to Programming in Java
Homework #9 -- Due 11:30pm on Thursday 11/16

Overview

The purpose of this assignment is gain more practice writing classes to define our own data types, building on the Player class from the last assignment. Specifically, we want to understand the interactions between arrays of objects and arrays as class data members. This time you will be designing and implementing the methods for a class to represent and play a full LCRGame, with some suggestions from us. You'll need to get some files to begin with from HW9start.zip file.

Deliverables: Submit a complete zip file named HW9-jhedLogin.zip, substituting your actual JHED login as the second part of the file name. Make sure that this includes all the source code (*.java) files needed for each part (ie, the class definitions and the main program), including those we provide and a working Player class.


Part A: LCR Game

For this assignment you will be creating an LCRgame class and a main program to run it so that you can play (simulate) the LCR game with as many players as you want. These classes will rely on the Player class from the last assignment. All of the actual game initialization, adding players, and playing until there is a winner must take place in a new class you create called LCRgame. The main program should be called Hw9.java and is primarily to create a new game, get user input for the players, and then play the game until there is a winner. Initially an LCRgame object should be initialized with the capacity for only four players. However, based on user input from main, the game must expand to hold as many players as needed.

Here's a recap of how to play the LCR dice game (see Wikipedia for more details). There are three dice for the game. One side of each has an L (left), one an R (right), one a C (center) and the other three sides have dots. When the game starts each player has 3 chips. Taking turns, the players then roll the dice - all 3 if they have at least 3 chips, 2 if only 2 chips, 1 if only 1 chip, and no roll if no chips. Then the player moves chips according to the dice roll results. For each L you roll, you must give a chip to the player on your left, for each R a chip to the player on your right, and C to a center pile. A dot means to keep a chip. The last player to have any chips is the winner and gets the center pot. Chips that go into the center pile stay there. If you run out of chips you are still in the game because one of your neighbors (player to left or right) might give a chip(s) to you on his/her next turn.

The input to the program will be the names of the players, one per line from keyboard input. Names may contain spaces, such as "Mary Jane". Your main program should read these names until it reaches the end of input, adding players to the game as it does so. Once you have all the input, play the game with all the players. The turn order is determined by the order in which their names were input, with the first player going after the last player in a round-robin fashion. The player to your right is the player with the next turn (opposite normal game play). Make sure that you check for a winner after every individual player turn, not just at the end of a round.

Recall that either ctrl-z or ctrl-d is used to mark the end, depending on your system. Sometimes in order to indicate end of input in jGRASP, while running the program you can right click in the input window and select the option to send the end of input signal. Here is a sample run showing the input and output to the screen. (Note that the end of input does not show up here after the last name "Larry" was input.) The corresponding output (for a random simulation remember) is included as "LCRout.txt" in the assignment zip file.

enter name of output file: LCRout.txt
enter LCR player names, one per line, ^Z or ^D to stop
Bill
Bob
Barb
Sue
Harry
Larry
Harry won with 2 chips!
The center pot has 16 chips.

The output of the program must be a record of the each player's turn, listing their name, how many chips before rolling, and what the results of the dice rolls were. The dice results should be displayed simply with a 'd' for a dot, 'L' for left, 'R' for right and 'C' for center. At the end of each completed round (every player has taken a turn in order), display the number of chips in the center pile, and then a blank line before the next round begins. When a winner is found, output the winner's name, how many chips s/he has, and how many chips are in the center pot. The simulation of the game results must be written to a file and the main program should get user input for this filename as in the above example. In addition, the main program should write the winner and center pot information to the screen and the output file when the game concludes. Sample game simulation output is provided in the starter zip file.

In order to implement this assignment, you will need to use the Player.java class. You may use my solution (with proper citation) or an adaptation of your own. You also must create a new LCRgame class which keeps track of all the players for one game, as well as the center pot. Each new game should be created by default with the capacity for only 4 players, then more will be added to it as needed. (Remember to double the collection size whenever you make it bigger so you don't have to resize too often.) Your main program will be used to get the input, add the players to the game, and run the game. All the actual game operations (such as taking turns, rolling, checking winner, etc.) should be done through either the LCRgame class or the Player class.

You must use arrays for this assignment. However, you may not use ArrayList (the JAVA class, or any other Java Collection classes) anywhere in your solution. The LCRgame class will be similar to the Deck class from lectures. Remember to cite any code that you use or adapt!

Remember to use incremental development: code and test one method at a time. Here is a suggested plan of attack:

Don't forget to include javadoc style comments on all the methods and data members of your class and make sure it is checkstyle compliant in all respects. Make sure that you include your Player.java class definition and all other source code files (LCRgame.java, Hw9.java) in your submitted zip.


General assignment requirements, style and submission details: