Internet Chess ToolKit
v0.2.0

ictk.boardgame.chess
Class ChessMove

java.lang.Object
  extended byictk.boardgame.Move
      extended byictk.boardgame.chess.ChessMove

public class ChessMove
extends Move

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

DEBUG

public static long DEBUG
a mask for Log.debug()


CASTLE_QUEENSIDE

public static final int CASTLE_QUEENSIDE
Queenside always means to white's left or black's right that is, toward the a-file. This is true no matter what the setup of the board (as in Fischer Random)

See Also:
Constant Field Values

CASTLE_KINGSIDE

public static final int CASTLE_KINGSIDE
Kingside always means to white's right or black's left that is, toward the h-file. This is true no matter what the setup of the board (as in Fischer Random)

See Also:
Constant Field Values
Constructor Detail

ChessMove

public ChessMove(ChessBoard b,
                 int i)
          throws IllegalMoveException
only used for castle moves. Legal paramters are CASTLE_QUEENSIDE and CASTLE_KINGSIDE.


ChessMove

public ChessMove(ChessBoard b,
                 int of,
                 int or,
                 int df,
                 int dr)
          throws IllegalMoveException
international coordinate based constructor all numbers should be in the range 1-8

Parameters:
of - origin file
or - origin rank
df - destination file
dr - destination rank

ChessMove

public ChessMove(ChessBoard b,
                 int of,
                 int or,
                 int df,
                 int dr,
                 int promo)
          throws IllegalMoveException
main int constructor All numbers should be in the range 1-8.

Parameters:
of - origin file
or - origin rank
df - destination file
dr - destination rank
promo - must be .INDEX

ChessMove

public ChessMove(ChessBoard b,
                 Square o,
                 Square d)
          throws IllegalMoveException
This constructor take Square objects. The Square objects don't have to be from the board that the move will be executed on. These moves are only used to get the coordinates of the move.

Parameters:
o - origin square
d - destination square

ChessMove

public ChessMove(ChessBoard b,
                 Square o,
                 Square d,
                 ChessPiece promo)
          throws IllegalMoveException
This constructor take Square objects. The Square objects don't have to be from the board that the move will be executed on. These moves are only used to get the coordinates of the move. The promotion piece, however, will.

Parameters:
o - origin square
d - destination square

ChessMove

public ChessMove(ChessPiece piece,
                 Square destination)
          throws IllegalMoveException
This constructor takes a ChessPiece on the board to move. And a Desitnation where the piece is to move to.


ChessMove

public ChessMove(ChessPiece piece,
                 Square destination,
                 ChessPiece promotion)
          throws IllegalMoveException
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. (assuming it's a pawn that's moving)

Method Detail

dispose

public void dispose()
reclaims all resources and recursively deletes all branch moves.

Overrides:
dispose in class Move

isLegal

public boolean isLegal()
this is kinda a strange function since ChessMoves are checked for legality when they are created. But if moves are played on the board this move can still be checked for legality and see if it's still valid.

Specified by:
isLegal in class Move

getUniqueness

public boolean[] getUniqueness()
is this move's file or rank unique, so SAN short-hand can be used to represent it?

Returns:
[true][false] if the file is unique

isFileUnique

public boolean isFileUnique()
is the file unique?


isRankUnique

public boolean isRankUnique()
is the rank unique?


isCheck

public boolean isCheck()
is this move a check (a piece attacking the king)


isDoubleCheck

public boolean isDoubleCheck()
is this move a double check (two pieces attacking the king)


isCheckmate

public boolean isCheckmate()
does this move result in checkmate?


isStalemate

public boolean isStalemate()
has stalemate resulted in one of the detected ways (currently only no-legal move stalemate)


isEndOfGame

public boolean isEndOfGame()
does this move terminate the game, either by checkmate, stalemate, or an ChessResult has been set for the move. This does not indicate that their is no current move that follows this move.


getResult

public Result getResult()
returns the result of the game.

Overrides:
getResult in class Move
Returns:
null if no result has been assigned to this move.

setResult

public void setResult(Result res)
Description copied from class: Move
sets the result. Note: a move does not have to be terminal to have a result.

Overrides:
setResult in class Move

isExecuted

public boolean isExecuted()
has this move been executed on the board.

Overrides:
isExecuted in class Move

isVerified

public boolean isVerified()
has this move been verified on the board at some point?

Overrides:
isVerified in class Move

getChessPiece

public ChessPiece getChessPiece()
returns the piece that is to move


getCasualty

public ChessPiece getCasualty()
if this move is a capture then the piece captured will be returned.


getPromotion

public ChessPiece getPromotion()
if this move leads to the promotion of a pawn it returns the promotion piece.


isBlackMove

public boolean isBlackMove()
is this a black move?


isCastleQueenside

public boolean isCastleQueenside()
is this move a queenside castle.


isCastleKingside

public boolean isCastleKingside()
is this a move a kingside castle


getCoordinates

public int[] getCoordinates()
returns an array of ints that are the numeric coordinates of the move. Coordinates start at 1 and end at 8


getDestinationCoordinates

public int[] getDestinationCoordinates()
returns an array of the ints that are the numeric coordinates of the move. Corrdinates start at 1 and end at 8


getDestination

public Square getDestination()
returns the Square this the piece intends to move


getOrigin

public Square getOrigin()
returns the Square the piece to move originates on.


getOriginCoordinates

public int[] getOriginCoordinates()

toString

public java.lang.String toString()
Specified by:
toString in class Move

equals

public boolean equals(java.lang.Object o)
compares the coordinate data, which is still valid.


hashCode

public int hashCode()

dump

public java.lang.String dump()
Description copied from class: Move
for debugging

Overrides:
dump in class Move

setBoard

public void setBoard(Board b)

getBoard

public Board getBoard()
Specified by:
getBoard in class Move

Submit a bug or feature
Visit the Website
Internet Chess ToolKit is licensed under the GPL v2 .