boardgame
Class Board

java.lang.Object
  extended by boardgame.Board
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
PBoard

public abstract class Board
extends java.lang.Object
implements java.lang.Cloneable

Abstract base class for board representations. INITIALIZATION Board implementations must provide a default constructor accepting no arguments so that they can be instantiated by the server or client software. PLAYER IDs A Board implementation must define a mapping between players and nonzero integer IDs 1,2,3 ... through the getNameForID() and getIDForName() methods. (e.g. "WHITE" -> 1. "BLACK" -> 2) SERVER INTERACTION The server asks the Board who's turn it is, using getTurn(), and requests a move from the appropriate player. Once the move is received, the board is asked to "filter" the moves, by calling the filterMove() method. This method may replace the player's move with an arbitrary sequence of moves. These moves are then executed in the given order by calling the Board.move() method. To allow environment actions, the Board may return the value Board.BOARD in it's getTurn() method. Then a move will be obtained using the getBoardMove() method instead of querying a player. To allow for incomplete information, boards may indicate who receives a move by overriding the Move.getReceivers() method in the move objects. In this case the board state known to the clients may differ from that of the server since clients may not received all moves. All moves are still written to the log file. BOARD STATE ENCODING It is important that all board state changes are implemented as moves for logging purposes, even if no player receives the Move message. This is so that the log file contains a complete description of the game. When a log file is loaded, the logfile viewer (ServerGUI) passes the sequence of moves in the log to the Board.Move() method. This should reconstruct the state of the board completely. CLIENT INTERACTION The client simply updates the board with moves received from the server, by calling the Board.move() methods for all received moves. Take this into account if not sending all moves to all players. It may be necessary to create seperate board classes for use by the clients and the server. This scheme should allow a large variety of games/environments to be represented while ensuring appropriate logging and communication. Essentially, CHANGES TO THE BOARD'S STATE SHOULD ONLY BE MADE IN THE Board.Move() METHOD to ensure proper communication and logging.


Field Summary
static int BOARD
          Special constant to indicate that the environment wants to play a turn
static int DRAW
          Special constant to indicate a draw
static int NOBODY
          Spectical constant to indicate no winner yet
 
Constructor Summary
Board()
           
 
Method Summary
abstract  java.lang.Object clone()
          Return an independant copy of the board.
 BoardPanel createBoardPanel()
          Construct a BoardPanel to display boards of this class.
 java.lang.Object filterMove(Move m)
          This is a hook for the board to modify moves just before they are executed using the move() method.
abstract  void forceWinner(int win)
          Set a winner without finishing the game.
 Move getBoardMove()
          If getTurn() returns the special constatnt BOARD, the server queries the board using this method for a move, instead of querying the players
abstract  int getIDForName(java.lang.String s)
          Get the player ID corresponding to name
abstract  java.lang.String getNameForID(int p)
          Get the name corresponding to a player ID.
abstract  int getNumberOfPlayers()
          Get the number of players.
abstract  int getTurn()
          Return the next player, or the special constant BOARD if the environment is to execute a move.
abstract  int getTurnsPlayed()
          Get the number of turns played.
abstract  int getWinner()
          Return winner ID, DRAW or NOBODY if no winner yet.
abstract  void move(Move m)
          Execute a move, throw an exception if Illegal.
abstract  Move parseMove(java.lang.String str)
          Parse a move from a string
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DRAW

public static final int DRAW
Special constant to indicate a draw

See Also:
Constant Field Values

NOBODY

public static final int NOBODY
Spectical constant to indicate no winner yet

See Also:
Constant Field Values

BOARD

public static final int BOARD
Special constant to indicate that the environment wants to play a turn

See Also:
Constant Field Values
Constructor Detail

Board

public Board()
Method Detail

getWinner

public abstract int getWinner()
Return winner ID, DRAW or NOBODY if no winner yet.


forceWinner

public abstract void forceWinner(int win)
Set a winner without finishing the game. Argument may be a player ID or DRAW.


getTurn

public abstract int getTurn()
Return the next player, or the special constant BOARD if the environment is to execute a move.


getTurnsPlayed

public abstract int getTurnsPlayed()
Get the number of turns played.


getBoardMove

public Move getBoardMove()
If getTurn() returns the special constatnt BOARD, the server queries the board using this method for a move, instead of querying the players


filterMove

public java.lang.Object filterMove(Move m)
                            throws java.lang.IllegalArgumentException
This is a hook for the board to modify moves just before they are executed using the move() method. If may return either a Move object, or an array of moves to be executed instead of the given move. Default implementation just returns its argument. Throw an Exception if the move is illegal.

Throws:
java.lang.IllegalArgumentException

move

public abstract void move(Move m)
                   throws java.lang.IllegalArgumentException
Execute a move, throw an exception if Illegal.

Throws:
java.lang.IllegalArgumentException

getNameForID

public abstract java.lang.String getNameForID(int p)
Get the name corresponding to a player ID. This function should also return an appropriate string for the value Board.BOARD if the board actions mechanism is used.


getIDForName

public abstract int getIDForName(java.lang.String s)
Get the player ID corresponding to name


getNumberOfPlayers

public abstract int getNumberOfPlayers()
Get the number of players. This must correspond to the number of player IDs!


parseMove

public abstract Move parseMove(java.lang.String str)
                        throws java.lang.NumberFormatException,
                               java.lang.IllegalArgumentException
Parse a move from a string

Throws:
java.lang.NumberFormatException
java.lang.IllegalArgumentException

clone

public abstract java.lang.Object clone()
Return an independant copy of the board.

Overrides:
clone in class java.lang.Object

createBoardPanel

public BoardPanel createBoardPanel()
Construct a BoardPanel to display boards of this class. The default implementation returns a board that displays a blank area.