Lab session 6

LCR Game

LCR (http://en.wikipedia.org/wiki/LCR_(dice_game)) is a dice game for 3 players. Each player receives 3 chips to start with. The game is played with three six-sided dice marked with the following symbols:

“L”, “C”, “R”, “.”, “.”, and “.”

Gameplay:

  1. The current player rolls as many dice as he has chips, but never more than 3 dice.
  2. Based on the result the player distributes some of their chips:
    • “L”: the player passes one chip to the player on their left
    • “R”: the player passes one chip to the player on their right
    • “C”: the player places one chip to the center of the table (the “pot”)
    • “.”: no effect
  3. The next player starts with point 1.

The game ends when only one player still has chips left. That player wins the game.

Players cannot be eliminated from the game: a player has 0 chips rolls 0 dice, but they can still receive chips from the other players.

Assignment

The goal of this lab session is to write a command-line based version of the LCR game.

  1. You need at least 3 classes (not including CommandLineLCR in the code template). One of these classes is LCRGame, representing one complete game of LCR. What other classes do you need?
  2. Choose one class that is independent of the other classes. What is the public interface of this class? Which instance variables does it require? Create the class and implement it. Also override the toString() method so it prints a simple representation of the object.
  3. Create a new method in the class CommandLineLCR called testXXX() where XXX is the name of the class you just implemented. In this method, create at least one new object of the class, call each method at least once, and compare the results with the expected results. Call this method from the main method of CommandLineLCR.
  4. Repeat 2. and 3. for the other classes you identified in 1., starting with the class(es) that only depend on other classes you already implemented.
  5. Finally, create and implement the LCRGame class by using the other classes you implemented.
  6. In the buildLCRGame method in CommandLineLCR, create a new object of class LCRGame and return it.
  7. In the render method in CommandLineLCR, print out a representation of the current game state. This should include the number of chips owned by each player and the most recent result of each die.
  8. Finish the runCommandLineLCR method in CommandLineLCR by uncommenting all the code and filling in the blanks.

TIP Some ideas for possible methods:

Think about which class they belong to. Sometimes there are multiple possible answers.

Example output

LCR started

Players: Alice (3 chips) Bob (3 chips) Cedric (3 chips) 
Current player is Alice (3 chips)
> r
R  .  .  
Players: Alice (2 chips) Bob (4 chips) Cedric (3 chips) 
Current player is Bob (4 chips)
> r
C  R  C  
Players: Alice (2 chips) Bob (1 chips) Cedric (4 chips) 
Current player is Cedric (4 chips)
> r
R  L  .  
Players: Alice (3 chips) Bob (2 chips) Cedric (2 chips) 
Current player is Alice (3 chips)
> r
.  .  .  
Players: Alice (3 chips) Bob (2 chips) Cedric (2 chips) 
Current player is Bob (2 chips)
> r
R  .  
Players: Alice (3 chips) Bob (1 chips) Cedric (3 chips) 
Current player is Cedric (3 chips)
> r
.  .  C  
Players: Alice (3 chips) Bob (1 chips) Cedric (2 chips) 
Current player is Alice (3 chips)
> r
C  .  .  
Players: Alice (2 chips) Bob (1 chips) Cedric (2 chips) 
Current player is Bob (1 chips)
> r
C  
Players: Alice (2 chips) Bob (0 chips) Cedric (2 chips) 
Current player is Cedric (2 chips)
> r
.  .  
Players: Alice (2 chips) Bob (0 chips) Cedric (2 chips) 
Current player is Alice (2 chips)
> r
.  C  
Players: Alice (1 chips) Bob (0 chips) Cedric (2 chips) 
Current player is Bob (0 chips)
> r

Players: Alice (1 chips) Bob (0 chips) Cedric (2 chips) 
Current player is Cedric (2 chips)
> r
C  .  
Players: Alice (1 chips) Bob (0 chips) Cedric (1 chips) 
Current player is Alice (1 chips)
> r
L  
Players: Alice (0 chips) Bob (0 chips) Cedric (2 chips) 
Game over! Winner is Cedric (2 chips)
Menu