chesspresso.position
Class Position

java.lang.Object
  |
  +--chesspresso.position.AbstractPosition
        |
        +--chesspresso.position.AbstractMutablePosition
              |
              +--chesspresso.position.AbstractMoveablePosition
                    |
                    +--chesspresso.position.Position
All Implemented Interfaces:
ImmutablePosition, MoveablePosition, MutablePosition

public final class Position
extends AbstractMoveablePosition


Field Summary
static int E
           
static int N
           
static int NE
           
static int NO_DIR
           
static int NUM_OF_DIRS
           
static int NW
           
static int S
           
static int SE
           
static int SW
           
static int W
           
 
Fields inherited from class chesspresso.position.AbstractMutablePosition
m_changeListeners, m_listeners, m_notifyListeners, m_notifyPositionChanged
 
Fields inherited from class chesspresso.position.AbstractPosition
HASH_ALL_MASK, HASH_TOPLAY_MASK, HASH_TOPLAY_MULT, s_hashCastleMod, s_hashEPMod, s_hashMod
 
Fields inherited from interface chesspresso.position.ImmutablePosition
ALL_CASTLES, BLACK_CASTLE, BLACK_LONG_CASTLE, BLACK_SHORT_CASTLE, NO_CASTLES, WHITE_CASTLE, WHITE_LONG_CASTLE, WHITE_SHORT_CASTLE
 
Constructor Summary
Position()
           
Position(ImmutablePosition pos)
           
Position(int bufferLength)
           
Position(java.lang.String fen)
           
Position(java.lang.String fen, boolean strict)
           
 
Method Summary
 boolean canMove()
           
 boolean canRedoMove()
           
 boolean canUndoMove()
           
 void clear()
           
static Position createInitialPosition()
           
 void doMove(short move)
           
 short[] getAllCapturingMoves()
           
 short[] getAllMoves()
           
 short[] getAllNonCapturingMoves()
           
 short[] getAllReCapturingMoves(short lastMove)
           
 int getCastles()
          Return the still allowed castles as mask.
 int getColor(int sqi)
           
 double getDomination()
           
static long getFirstSqiBB(long bb)
           
 int getHalfMoveClock()
          Return the number of moves since the last capture and the last pawn move.
 long getHashCode()
          Returns a 64bit hash code of the current position. 64bit should be enough to disnstinguish positions with almost no collisions.
 Move getLastMove()
           
 short getLastShortMove()
           
 int getMaterial()
           
 java.lang.String getMovesAsString(short[] moves, boolean validateEachMove)
           
 short getPawnMove(int colFrom, int to, int promoPiece)
           
 int getPiece(int sqi)
           
 short getPieceMove(int piece, int colFrom, int rowFrom, int to)
           
 int getPlyNumber()
          Return the current ply number.
 int getSqiEP()
          Return the current en passant square.
 int getStone(int sqi)
          Return the stone currently on the given square.
 int getToPlay()
          Return the player whose turn it is.
 boolean isCheck()
           
 boolean isLegal()
          Return whether the current position is legal.
 boolean isMate()
           
 boolean isSquareEmpty(int sqi)
           
 boolean isStaleMate()
           
 boolean isTerminal()
           
static long ofCol(int col)
           
static long ofRow(int row)
           
static long ofSquare(int sqi)
           
static void printProfile()
           
 boolean redoMove()
           
 void setCastles(int castles)
           
 void setHalfMoveClock(int halfMoveClock)
           
 void setPlyNumber(int plyNumber)
           
 void setSqiEP(int sqiEP)
           
 void setStone(int sqi, int stone)
           
 void setToPlay(int toPlay)
           
 void takeBaseline()
           
 void toggleToPlay()
           
 boolean undoMove()
           
 void validate()
          Validates the internal state.
 
Methods inherited from class chesspresso.position.AbstractMoveablePosition
doMove, getMove
 
Methods inherited from class chesspresso.position.AbstractMutablePosition
addPositionChangeListener, addPositionListener, excludeCastles, fireCastlesChanged, fireHalfMoveClockChanged, fireMoveDone, fireMoveUndone, firePlyNumberChanged, firePositionChanged, fireSqiEPChanged, fireSquareChanged, fireToPlayChanged, incHalfMoveClock, includeCastles, inverse, removePositionChangeListener, removePositionListener, resetHalfMoveClock, set, setNotifyListeners, setStart
 
Methods inherited from class chesspresso.position.AbstractPosition
equals, getFEN, getStartPositionHashCode, hashCode, isCastlePossible, isSquarePossibleEPSquare, isStartPosition, isWhiteToPlay, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface chesspresso.position.MutablePosition
set, setStart
 
Methods inherited from interface chesspresso.position.ImmutablePosition
getFEN, hashCode, isStartPosition
 

Field Detail

NO_DIR

public static final int NO_DIR
See Also:
Constant Field Values

NUM_OF_DIRS

public static final int NUM_OF_DIRS
See Also:
Constant Field Values

SW

public static final int SW
See Also:
Constant Field Values

S

public static final int S
See Also:
Constant Field Values

SE

public static final int SE
See Also:
Constant Field Values

E

public static final int E
See Also:
Constant Field Values

NE

public static final int NE
See Also:
Constant Field Values

N

public static final int N
See Also:
Constant Field Values

NW

public static final int NW
See Also:
Constant Field Values

W

public static final int W
See Also:
Constant Field Values
Constructor Detail

Position

public Position()

Position

public Position(int bufferLength)

Position

public Position(ImmutablePosition pos)

Position

public Position(java.lang.String fen)
         throws java.lang.IllegalArgumentException

Position

public Position(java.lang.String fen,
                boolean strict)
         throws java.lang.IllegalArgumentException
Method Detail

printProfile

public static void printProfile()

ofSquare

public static final long ofSquare(int sqi)

ofCol

public static final long ofCol(int col)

ofRow

public static final long ofRow(int row)

getFirstSqiBB

public static final long getFirstSqiBB(long bb)

createInitialPosition

public static Position createInitialPosition()

clear

public void clear()
Specified by:
clear in interface MutablePosition
Overrides:
clear in class AbstractMutablePosition

getToPlay

public final int getToPlay()
Description copied from interface: ImmutablePosition
Return the player whose turn it is.

Returns:
the player whose turn it is

isSquareEmpty

public final boolean isSquareEmpty(int sqi)
Overrides:
isSquareEmpty in class AbstractMutablePosition

getCastles

public final int getCastles()
Description copied from interface: ImmutablePosition
Return the still allowed castles as mask.

Returns:
the still allowed castles as mask.

getSqiEP

public final int getSqiEP()
Description copied from interface: ImmutablePosition
Return the current en passant square.

Returns:
the current en passant square, NO_SQUARE if none

getHalfMoveClock

public final int getHalfMoveClock()
Description copied from interface: ImmutablePosition
Return the number of moves since the last capture and the last pawn move. This number is used for the 50-move rule.

Returns:
the number of moves since the last capture and the last pawn move

getPlyNumber

public final int getPlyNumber()
Description copied from interface: ImmutablePosition
Return the current ply number.

Returns:
the current ply number, starting at play no. 0

getHashCode

public final long getHashCode()
Description copied from interface: ImmutablePosition
Returns a 64bit hash code of the current position. 64bit should be enough to disnstinguish positions with almost no collisions. TODO: add reference to paper

Specified by:
getHashCode in interface ImmutablePosition
Overrides:
getHashCode in class AbstractPosition
Returns:
a 64bit hash code

getStone

public final int getStone(int sqi)
Description copied from interface: ImmutablePosition
Return the stone currently on the given square.

Parameters:
sqi - the square
Returns:
the stone of the given square

getPiece

public final int getPiece(int sqi)
Overrides:
getPiece in class AbstractMutablePosition

getColor

public final int getColor(int sqi)
Overrides:
getColor in class AbstractMutablePosition

setStone

public final void setStone(int sqi,
                           int stone)

setPlyNumber

public final void setPlyNumber(int plyNumber)

setHalfMoveClock

public void setHalfMoveClock(int halfMoveClock)

setCastles

public final void setCastles(int castles)

setSqiEP

public void setSqiEP(int sqiEP)

setToPlay

public final void setToPlay(int toPlay)

toggleToPlay

public final void toggleToPlay()
Overrides:
toggleToPlay in class AbstractMutablePosition

takeBaseline

public void takeBaseline()

doMove

public void doMove(short move)
            throws IllegalMoveException
IllegalMoveException

canUndoMove

public boolean canUndoMove()

undoMove

public boolean undoMove()

canRedoMove

public boolean canRedoMove()

redoMove

public boolean redoMove()

isLegal

public boolean isLegal()
Description copied from interface: ImmutablePosition
Return whether the current position is legal.

Specified by:
isLegal in interface ImmutablePosition
Overrides:
isLegal in class AbstractPosition
Returns:
whether the current position is legal

validate

public void validate()
              throws IllegalPositionException
Description copied from interface: ImmutablePosition
Validates the internal state. Used for debugging and testing.

Specified by:
validate in interface ImmutablePosition
Overrides:
validate in class AbstractPosition
Throws:
IllegalPositionException - if the internal state is illegal

isCheck

public final boolean isCheck()

isTerminal

public boolean isTerminal()

isMate

public boolean isMate()

isStaleMate

public boolean isStaleMate()

getLastShortMove

public short getLastShortMove()

getLastMove

public Move getLastMove()

getPawnMove

public short getPawnMove(int colFrom,
                         int to,
                         int promoPiece)

getPieceMove

public short getPieceMove(int piece,
                          int colFrom,
                          int rowFrom,
                          int to)

getAllMoves

public short[] getAllMoves()

getAllReCapturingMoves

public short[] getAllReCapturingMoves(short lastMove)

getAllCapturingMoves

public short[] getAllCapturingMoves()

getAllNonCapturingMoves

public short[] getAllNonCapturingMoves()

canMove

public boolean canMove()

getMovesAsString

public java.lang.String getMovesAsString(short[] moves,
                                         boolean validateEachMove)

getMaterial

public int getMaterial()

getDomination

public double getDomination()