chesspresso.move
Class Move

java.lang.Object
  |
  +--chesspresso.move.Move

public class Move
extends java.lang.Object

Abstraction of a chess move.
This class provides support for two ways to encode moves:

  • Based on short: optimized for speed and memory but cannot be used to print a SAN (short annotation, see PGN spec). Contains the following information: from square, to square, capturing, promotion piece.
  • Based on this class containing full information of the move such that a SAN (and LAN) of the move can be printed without further assistance. Contains all information of the short move plus information whether to to skip rank and file of the from square, check and mate information, the moving piece and whether or not is is a white move.
    Internal representation is based on two shorts. In order to create a full move out of a short move a position is needed.

    Version:
    $Revision: 1.2 $
    Author:
    Bernhard Seybold

    Field Summary
    static short BLACK_LONG_CASTLE
               
    static short BLACK_SHORT_CASTLE
               
    static short ILLEGAL_MOVE
              Representing an illegal move.
    static short NO_MOVE
              Represents "no move".
    static short NUM_OF_OTHER_SPECIALS
              Number of special moves which can be defined.
    static int NUM_OF_SPECIAL_MOVES
               
    static short OTHER_SPECIALS
              The range [OTHER_SPECIALS,OTHER_SPECIALS+NUM_OF_OTHER_SPECIALS[ is reserved for clients of Move to define their own special moves.
    static int SPECIAL_MOVE
               
    static short WHITE_LONG_CASTLE
               
    static short WHITE_SHORT_CASTLE
               
     
    Constructor Summary
    Move(short move, int movingPiece, int colFrom, int rowFrom, boolean isCheck, boolean isMate, boolean isWhiteMove)
              Creates a full move.
     
    Method Summary
    static Move createCastle(short move, boolean isCheck, boolean isMate, boolean whiteMove)
              Convenience method to create a castle move.
    static Move createIllegalMove()
              Premanufactured illegal move, always returns the same instance.
    static Move createLongCastle(int toPlay, boolean isCheck, boolean isMate, boolean whiteMove)
              Convenience factory method to create a long castle move.
    static Move createShortCastle(int toPlay, boolean isCheck, boolean isMate, boolean whiteMove)
              Convenience factory method to create a short castle move.
     boolean equals(java.lang.Object obj)
              Equality test.
    static java.lang.String getBinaryString(short move)
               
     int getColFrom()
               
    static short getEPMove(int fromSqi, int toSqi)
              Manufacture an en passant move.
     int getFromSqi()
               
    static int getFromSqi(short move)
               
     java.lang.String getLAN()
              Returns the LAN (long annotation, see PGN spec) of the move, e.g.
    static short getLongCastle(int toPlay)
              Manufacture a long castle move.
     int getMovingPiece()
               
    static short getPawnMove(int fromSqi, int toSqi, boolean capturing, int promotionPiece)
              Manufacture a pawn move.
     int getPromo()
               
    static int getPromotionPiece(short move)
               
    static short getRegularMove(int fromSqi, int toSqi, boolean capturing)
              Manufacture a regular move.
     int getRowFrom()
               
     java.lang.String getSAN()
              Returns the SAN (short annotation, see PGN spec) of the move, e.g.
    static short getShortCastle(int toPlay)
              Manufacture a short castle move.
     short getShortMoveDesc()
               
    static java.lang.String getString(short move)
              Returns a string representation of the move.
     int getToSqi()
               
    static int getToSqi(short move)
               
     boolean isCapturing()
               
    static boolean isCapturing(short move)
               
    static boolean isCastle(short move)
               
     boolean isCheck()
               
    static boolean isEPMove(short move)
               
     boolean isLongCastle()
               
    static boolean isLongCastle(short move)
               
     boolean isMate()
               
     boolean isPromotion()
               
    static boolean isPromotion(short move)
               
     boolean isShortCastle()
               
    static boolean isShortCastle(short move)
               
    static boolean isSpecial(short move)
               
     boolean isValid()
               
    static boolean isValid(short move)
               
     boolean isWhiteMove()
               
    static void normalizeOrder(short[] moves)
              Returns the moves in a normalized order such that the same set of moves always yields the same order.
     java.lang.String toString()
               
     
    Methods inherited from class java.lang.Object
    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
     

    Field Detail

    SPECIAL_MOVE

    public static final int SPECIAL_MOVE
    See Also:
    Constant Field Values

    NUM_OF_SPECIAL_MOVES

    public static final int NUM_OF_SPECIAL_MOVES
    See Also:
    Constant Field Values

    WHITE_SHORT_CASTLE

    public static final short WHITE_SHORT_CASTLE
    See Also:
    Constant Field Values

    WHITE_LONG_CASTLE

    public static final short WHITE_LONG_CASTLE
    See Also:
    Constant Field Values

    BLACK_SHORT_CASTLE

    public static final short BLACK_SHORT_CASTLE
    See Also:
    Constant Field Values

    BLACK_LONG_CASTLE

    public static final short BLACK_LONG_CASTLE
    See Also:
    Constant Field Values

    NO_MOVE

    public static final short NO_MOVE
    Represents "no move". Set to 0 to allow rapid initialization of arrays to no moves (arrays are injitialized to 0 by Java).

    See Also:
    Constant Field Values

    ILLEGAL_MOVE

    public static final short ILLEGAL_MOVE
    Representing an illegal move.

    See Also:
    Constant Field Values

    OTHER_SPECIALS

    public static final short OTHER_SPECIALS
    The range [OTHER_SPECIALS,OTHER_SPECIALS+NUM_OF_OTHER_SPECIALS[ is reserved for clients of Move to define their own special moves. This can be used to indicate special conditions when a move is expected. Moves of the range above do not collide whith any other moves.

    See Also:
    Constant Field Values

    NUM_OF_OTHER_SPECIALS

    public static final short NUM_OF_OTHER_SPECIALS
    Number of special moves which can be defined.

    See Also:
    Constant Field Values
    Constructor Detail

    Move

    public Move(short move,
                int movingPiece,
                int colFrom,
                int rowFrom,
                boolean isCheck,
                boolean isMate,
                boolean isWhiteMove)
    Creates a full move.

    Parameters:
    move - the short move
    movingPiece - the piece moving
    colFrom - file if should be taken for SAN, NO_COL otherwise
    rowFrom - rank if should be taken for SAN, NO_ROW otherwise
    isCheck - whether the move gives a check
    isMate - whether the move sets mate
    Method Detail

    normalizeOrder

    public static void normalizeOrder(short[] moves)
    Returns the moves in a normalized order such that the same set of moves always yields the same order. Implementation is: short values ascending.


    getRegularMove

    public static short getRegularMove(int fromSqi,
                                       int toSqi,
                                       boolean capturing)
    Manufacture a regular move.

    Parameters:
    fromSqi - the from square
    toSqi - the to square
    capturing - whether or not it is a capturing move

    getPawnMove

    public static short getPawnMove(int fromSqi,
                                    int toSqi,
                                    boolean capturing,
                                    int promotionPiece)
    Manufacture a pawn move.

    Parameters:
    fromSqi - the from square
    toSqi - the to square
    capturing - whether or not it is a capturing move
    promotionPiece - set to a piece if it is a promotion move, set to No_PIECE otherwise

    getEPMove

    public static short getEPMove(int fromSqi,
                                  int toSqi)
    Manufacture an en passant move.

    Parameters:
    fromSqi - the from square
    toSqi - the to square

    getShortCastle

    public static short getShortCastle(int toPlay)
    Manufacture a short castle move.

    Parameters:
    toPlay - for which color

    getLongCastle

    public static short getLongCastle(int toPlay)
    Manufacture a long castle move.

    Parameters:
    toPlay - for which color

    getFromSqi

    public static final int getFromSqi(short move)

    getToSqi

    public static final int getToSqi(short move)

    isCapturing

    public static final boolean isCapturing(short move)

    isPromotion

    public static final boolean isPromotion(short move)

    getPromotionPiece

    public static final int getPromotionPiece(short move)

    isEPMove

    public static final boolean isEPMove(short move)

    isCastle

    public static boolean isCastle(short move)

    isShortCastle

    public static boolean isShortCastle(short move)

    isLongCastle

    public static boolean isLongCastle(short move)

    isSpecial

    public static boolean isSpecial(short move)

    isValid

    public static boolean isValid(short move)

    getBinaryString

    public static java.lang.String getBinaryString(short move)

    getString

    public static java.lang.String getString(short move)
    Returns a string representation of the move.

    Returns:
    the string representation, e.g. e2xf4

    createIllegalMove

    public static Move createIllegalMove()
    Premanufactured illegal move, always returns the same instance.

    Returns:
    an illegal move

    createCastle

    public static Move createCastle(short move,
                                    boolean isCheck,
                                    boolean isMate,
                                    boolean whiteMove)
    Convenience method to create a castle move.

    Parameters:
    move - a castling move to based upon, must be a castling move
    isCheck - whether the move gives a check
    isMate - whether the move sets mate
    Returns:
    the castle move

    createShortCastle

    public static Move createShortCastle(int toPlay,
                                         boolean isCheck,
                                         boolean isMate,
                                         boolean whiteMove)
    Convenience factory method to create a short castle move.

    Parameters:
    toPlay - the moving player
    isCheck - whether the move gives a check
    isMate - whether the move sets mate
    Returns:
    the castle move

    createLongCastle

    public static Move createLongCastle(int toPlay,
                                        boolean isCheck,
                                        boolean isMate,
                                        boolean whiteMove)
    Convenience factory method to create a long castle move.

    Parameters:
    toPlay - the moving player
    isCheck - whether the move gives a check
    isMate - whether the move sets mate
    Returns:
    the castle move

    getShortMoveDesc

    public short getShortMoveDesc()

    getPromo

    public int getPromo()

    getFromSqi

    public int getFromSqi()

    getToSqi

    public int getToSqi()

    getMovingPiece

    public int getMovingPiece()

    getColFrom

    public int getColFrom()

    getRowFrom

    public int getRowFrom()

    isCapturing

    public boolean isCapturing()

    isPromotion

    public boolean isPromotion()

    isCheck

    public boolean isCheck()

    isMate

    public boolean isMate()

    isShortCastle

    public boolean isShortCastle()

    isLongCastle

    public boolean isLongCastle()

    isValid

    public boolean isValid()

    isWhiteMove

    public boolean isWhiteMove()

    equals

    public boolean equals(java.lang.Object obj)
    Equality test. Two move are equal if and only if all arguments match.

    Overrides:
    equals in class java.lang.Object
    Parameters:
    obj - the object to compare against
    Returns:
    whether the two moves are equal

    getLAN

    public java.lang.String getLAN()
    Returns the LAN (long annotation, see PGN spec) of the move, e.g. Ne2xf4+.

    Returns:
    the LAN representation

    getSAN

    public java.lang.String getSAN()
    Returns the SAN (short annotation, see PGN spec) of the move, e.g. Nxf4+.

    Returns:
    the SAN representation

    toString

    public java.lang.String toString()
    Overrides:
    toString in class java.lang.Object