|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectboardgame.Board
public abstract class Board
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 |
|---|
public static final int DRAW
public static final int NOBODY
public static final int BOARD
| Constructor Detail |
|---|
public Board()
| Method Detail |
|---|
public abstract int getWinner()
public abstract void forceWinner(int win)
public abstract int getTurn()
public abstract int getTurnsPlayed()
public Move getBoardMove()
public java.lang.Object filterMove(Move m)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
public abstract void move(Move m)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentExceptionpublic abstract java.lang.String getNameForID(int p)
public abstract int getIDForName(java.lang.String s)
public abstract int getNumberOfPlayers()
public abstract Move parseMove(java.lang.String str)
throws java.lang.NumberFormatException,
java.lang.IllegalArgumentException
java.lang.NumberFormatException
java.lang.IllegalArgumentExceptionpublic abstract java.lang.Object clone()
clone in class java.lang.Objectpublic BoardPanel createBoardPanel()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||