|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectantichess.Board<M>
public abstract class Board<M extends Move>
A Board represents an arbitrary 2-dimensional game board that is somehow populated by pieces that are allowed to move in specific waves.
Board defines some game-over conditions for all Boards built off of this one: NOTOVER with the value 0, DRAW with value -1, OUTOFTIME with value -2, and RESIGN with a value of -3. Subclasses of this Board should not set a different end condition that matches any of these integer value.
player
: Player // The Player whose move it is
pieces
: Set<Pieces> // The Pieces on the board
observers
: Set<BoardObservers> // Observers that are notified when something on the Board changes
moveStack
// A stack of all moves previously performed on this board, optionally associated with timestamps
Field Summary | |
---|---|
static int |
DRAW
End-game condition that signifies a draw |
static int |
FORCEDEND
End-game condition variable to represent a forced end |
protected int |
gameOverReason
|
protected MoveHistory<M> |
moveStack
|
static int |
NOTOVER
Default Board termination condition, indicating that the game is not over |
protected List<BoardObserver> |
observers
|
static int |
OUTOFTIME
End-game condition that signifies that the game has run out of time for some player |
protected Player |
player
|
protected Player |
winner
|
Constructor Summary | |
---|---|
Board()
Initializes some variables for the Board assuming it is being created for a new game, including observers. |
Method Summary | |
---|---|
void |
addObserver(BoardObserver bo)
Adds an observer to the list of BoardObservers |
abstract List<M> |
allLegalMoves()
|
abstract Board<M> |
clone()
Creates a clone of this Board |
protected void |
copyThis(Board<M> b)
Inheritable helper method for copying various data members from this Board to an empty Board. |
void |
doMove(M m)
|
abstract void |
doMove(M m,
String timestamp)
|
void |
endGame(int gameOverReason,
Player winner)
Terminates the current game, specifying the cause of game termination and the winner. |
abstract int |
getColumns()
|
int |
getGameOverReason()
|
MoveHistory<M> |
getMoveHistory()
|
abstract Piece |
getPieceAt(int row,
int column)
|
abstract List<Piece> |
getPieces()
|
abstract List<Piece> |
getPieces(Player player)
|
Player |
getPlayer()
|
abstract int |
getRows()
|
Player |
getWinner()
|
boolean |
hasALegalMove()
|
boolean |
isGameOver()
|
abstract boolean |
isMoveLegal(M m)
|
abstract List<M> |
legalMoves(Piece p)
|
void |
notifyObservers()
Updates all observers in the list of observers that the Board has been changed. |
protected M |
popMove()
Pop a move off the internal move stack and return it |
protected void |
pushMove(M m,
String timestamp)
Pushes the given move onto the internal piece stack |
void |
removeObserver(BoardObserver bo)
Removes an observer from the list of BoardObservers. |
abstract void |
undoLastMove()
|
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int NOTOVER
public static final int DRAW
public static final int OUTOFTIME
public static final int FORCEDEND
protected Player player
protected Player winner
protected int gameOverReason
protected List<BoardObserver> observers
protected MoveHistory<M extends Move> moveStack
Constructor Detail |
---|
public Board()
Method Detail |
---|
public abstract Board<M> clone()
clone
in class Object
protected void copyThis(Board<M> b)
b
- the empty board into which this board
should be copied.public abstract int getRows()
public abstract int getColumns()
public Player getPlayer()
public abstract Piece getPieceAt(int row, int column)
public abstract List<Piece> getPieces()
public abstract List<Piece> getPieces(Player player)
public boolean hasALegalMove()
public abstract List<M> allLegalMoves()
public abstract List<M> legalMoves(Piece p)
public abstract boolean isMoveLegal(M m)
public void doMove(M m) throws IllegalMoveException
m
- the Move that describes how to modify the Board
IllegalMoveException
- if the move is illegalpublic MoveHistory<M> getMoveHistory()
protected void pushMove(M m, String timestamp)
protected M popMove()
public abstract void doMove(M m, String timestamp) throws IllegalMoveException
m
- the Move that describes how to modify the Boardtimestamp
- the time that Move m
was made
IllegalMoveException
- if the move is illegalpublic abstract void undoLastMove()
public boolean isGameOver()
public Player getWinner()
public int getGameOverReason()
public void endGame(int gameOverReason, Player winner)
gameOverReason
- the game termination condition.
This value should match the value of one of the end-
game conditions available for a particular game.winner
- the winner of the gamepublic void addObserver(BoardObserver bo)
bo
- the BoardObserver to add to this Boardbo
to the list of observerspublic void removeObserver(BoardObserver bo)
bo
- the BoardObserver to remove from this Boardbo
from the list of observers
if bo
is present in the list of observers;
otherwise nothingpublic void notifyObservers()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |