|
Internet Chess ToolKit v0.2.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ictk.boardgame.Move ictk.boardgame.chess.ChessMove
ChessMove is an implementation of the Command Pattern of OOD. It contains mostly references to other objects (Squares, Pieces etc).
There are two two phases to the Move object
1) unverified (rare state)
The move is but coordinates, not associated with a board or
history list. There is no guarentee that the move is valid.
Executing a method that relies on valid information will result
in an UnexecutedMoveException. Such functions are isCheckmate(),
isStalemate(), getChessPiece() etc).
2) verified (common state)
The move has been exceuted at least once on a board and verified
to be a legal move. By default most of the constructors available
check move legality when the move is created. However, if the move
gets played (via ChessBoard, or History) on the board after the
ChessBoard position has changed the move might throw an
IllegalMoveException. Once the move is in the verified state
all functions are available including isStalemate() etc.
Typical usage goes like this:
ChessGame game = new ChessGame(); History history = game.getHistory(); ChessMove move = new ChessMove (game.getBoard(), 5, 2, 5, 4); //1.e4 history.add(move);
An alternative way to do the same thing by using the
SAN
object:
SAN san = new SAN(); ChessMove move = san.stringToMove(board, "e4");
Castling can be done via the following:
ChessMove move = ChessMove(board, ChessMove.CASTLE_QUEENSIDE);
Or
ChessMove move = san.stringToMove(board, "O-O-O");
A Promotion move might look like this:
ChessMove move = ChessMove(board, 5, 7, 5, 8, Queen.INDEX);
Field Summary | |
static int |
CASTLE_KINGSIDE
Kingside always means to white's right or black's left that is, toward the h-file. |
static int |
CASTLE_QUEENSIDE
Queenside always means to white's left or black's right that is, toward the a-file. |
static long |
DEBUG
a mask for Log.debug() |
Constructor Summary | |
ChessMove(ChessBoard b,
int i)
only used for castle moves. |
|
ChessMove(ChessBoard b,
int of,
int or,
int df,
int dr)
international coordinate based constructor all numbers should be in the range 1-8 |
|
ChessMove(ChessBoard b,
int of,
int or,
int df,
int dr,
int promo)
main int constructor All numbers should be in the range 1-8. |
|
ChessMove(ChessBoard b,
Square o,
Square d)
This constructor take Square objects. |
|
ChessMove(ChessBoard b,
Square o,
Square d,
ChessPiece promo)
This constructor take Square objects. |
|
ChessMove(ChessPiece piece,
Square destination)
This constructor takes a ChessPiece on the board to move. |
|
ChessMove(ChessPiece piece,
Square destination,
ChessPiece promotion)
This constructor takes a ChessPiece on the board to move, A Desitnation where the piece is to move to, and the ChessPiece it is to promote to when it gets there. |
Method Summary | |
void |
dispose()
reclaims all resources and recursively deletes all branch moves. |
java.lang.String |
dump()
for debugging |
boolean |
equals(java.lang.Object o)
compares the coordinate data, which is still valid. |
Board |
getBoard()
|
ChessPiece |
getCasualty()
if this move is a capture then the piece captured will be returned. |
ChessPiece |
getChessPiece()
returns the piece that is to move |
int[] |
getCoordinates()
returns an array of ints that are the numeric coordinates of the move. |
Square |
getDestination()
returns the Square this the piece intends to move |
int[] |
getDestinationCoordinates()
returns an array of the ints that are the numeric coordinates of the move. |
Square |
getOrigin()
returns the Square the piece to move originates on. |
int[] |
getOriginCoordinates()
|
ChessPiece |
getPromotion()
if this move leads to the promotion of a pawn it returns the promotion piece. |
Result |
getResult()
returns the result of the game. |
boolean[] |
getUniqueness()
is this move's file or rank unique, so SAN short-hand can be used to represent it? |
int |
hashCode()
|
boolean |
isBlackMove()
is this a black move? |
boolean |
isCastleKingside()
is this a move a kingside castle |
boolean |
isCastleQueenside()
is this move a queenside castle. |
boolean |
isCheck()
is this move a check (a piece attacking the king) |
boolean |
isCheckmate()
does this move result in checkmate? |
boolean |
isDoubleCheck()
is this move a double check (two pieces attacking the king) |
boolean |
isEndOfGame()
does this move terminate the game, either by checkmate, stalemate, or an ChessResult has been set for the move. |
boolean |
isExecuted()
has this move been executed on the board. |
boolean |
isFileUnique()
is the file unique? |
boolean |
isLegal()
this is kinda a strange function since ChessMoves are checked for legality when they are created. |
boolean |
isRankUnique()
is the rank unique? |
boolean |
isStalemate()
has stalemate resulted in one of the detected ways (currently only no-legal move stalemate) |
boolean |
isVerified()
has this move been verified on the board at some point? |
void |
setBoard(Board b)
|
void |
setResult(Result res)
sets the result. |
java.lang.String |
toString()
|
Methods inherited from class ictk.boardgame.Move |
getAnnotation, getContinuationList, getHistory, getNext, getPrenotation, getPrev, hasNext, setAnnotation, setPrenotation |
Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
public static long DEBUG
public static final int CASTLE_QUEENSIDE
public static final int CASTLE_KINGSIDE
Constructor Detail |
public ChessMove(ChessBoard b, int i) throws IllegalMoveException
public ChessMove(ChessBoard b, int of, int or, int df, int dr) throws IllegalMoveException
of
- origin fileor
- origin rankdf
- destination filedr
- destination rankpublic ChessMove(ChessBoard b, int of, int or, int df, int dr, int promo) throws IllegalMoveException
of
- origin fileor
- origin rankdf
- destination filedr
- destination rankpromo
- must be public ChessMove(ChessBoard b, Square o, Square d) throws IllegalMoveException
o
- origin squared
- destination squarepublic ChessMove(ChessBoard b, Square o, Square d, ChessPiece promo) throws IllegalMoveException
o
- origin squared
- destination squarepublic ChessMove(ChessPiece piece, Square destination) throws IllegalMoveException
public ChessMove(ChessPiece piece, Square destination, ChessPiece promotion) throws IllegalMoveException
Method Detail |
public void dispose()
dispose
in class Move
public boolean isLegal()
isLegal
in class Move
public boolean[] getUniqueness()
public boolean isFileUnique()
public boolean isRankUnique()
public boolean isCheck()
public boolean isDoubleCheck()
public boolean isCheckmate()
public boolean isStalemate()
public boolean isEndOfGame()
public Result getResult()
getResult
in class Move
public void setResult(Result res)
Move
setResult
in class Move
public boolean isExecuted()
isExecuted
in class Move
public boolean isVerified()
isVerified
in class Move
public ChessPiece getChessPiece()
public ChessPiece getCasualty()
public ChessPiece getPromotion()
public boolean isBlackMove()
public boolean isCastleQueenside()
public boolean isCastleKingside()
public int[] getCoordinates()
public int[] getDestinationCoordinates()
public Square getDestination()
public Square getOrigin()
public int[] getOriginCoordinates()
public java.lang.String toString()
toString
in class Move
public boolean equals(java.lang.Object o)
public int hashCode()
public java.lang.String dump()
Move
dump
in class Move
public void setBoard(Board b)
public Board getBoard()
getBoard
in class Move
|
Submit a bug or feature Visit the Website Internet Chess ToolKit is licensed under the GPL v2 . |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |