edu.rice.comp440
Class Backgammon

java.lang.Object
  |
  +--edu.rice.comp440.Backgammon

public class Backgammon
extends java.lang.Object

This class wraps all of the backgammon functionality. Basically, the use model for this class is build a new Backgammon with two players, execute backgammon.run(), which runs the game, and the call backgammon.reset(), backgammon.run() if you want to play again.


Field Summary
protected  Board board
           
protected  Dice dice
           
protected  int player
           
protected  Player[] players
           
 
Constructor Summary
Backgammon(Player player1, Player player2)
          Builds a new backgammon instance, given the two players to play the game between.
 
Method Summary
 Board getCurrentBoard()
          Returns the current board.
 int getCurrentPlayer()
          Returns the current player, either Board.BLACK or Board.WHITE
 Dice getDice()
          Returns the current dice
 Move[] getMoves()
          Returns a list of all of the possible moves which the player can currently make
 boolean isGameOver()
          Returns whether or not the game is over
 void print(java.io.PrintStream out)
          Prints out a gnubg-style text board.
 void print(java.io.PrintStream out, Board board)
          Prints out a gnubg-style text board.
 void reset()
          Resets this backgammon instance to the initial state, with a new board and the black player's move
 Player run()
          Runs a game of backgammon, and does not return until the game is over.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

board

protected Board board

dice

protected Dice dice

player

protected int player

players

protected Player[] players
Constructor Detail

Backgammon

public Backgammon(Player player1,
                  Player player2)
Builds a new backgammon instance, given the two players to play the game between.
Parameters:
player1 - The first player (BLACK)
player2 - The second player (WHITE)
Method Detail

run

public Player run()
Runs a game of backgammon, and does not return until the game is over. Returns the player who won the game.
Returns:
The winning player

reset

public void reset()
Resets this backgammon instance to the initial state, with a new board and the black player's move

getCurrentPlayer

public int getCurrentPlayer()
Returns the current player, either Board.BLACK or Board.WHITE
Returns:
The current player

getMoves

public Move[] getMoves()
Returns a list of all of the possible moves which the player can currently make
Returns:
The current available moves

getDice

public Dice getDice()
Returns the current dice
Returns:
The current dice

getCurrentBoard

public Board getCurrentBoard()
Returns the current board. Note that this is the actual board, so *NO CHANGES SHOULD BE MADE TO THIS OBJECT*.
Returns:
The current board

isGameOver

public boolean isGameOver()
Returns whether or not the game is over
Returns:
Whether or not the game is over

print

public void print(java.io.PrintStream out)
Prints out a gnubg-style text board.
Parameters:
out - The output stream to write the board to

print

public void print(java.io.PrintStream out,
                  Board board)
Prints out a gnubg-style text board.
Parameters:
out - The output stream to write the board to
board - The board