com.editev.chess
Class GameState

java.lang.Object
  |
  +--com.editev.chess.Chess
        |
        +--com.editev.chess.Board
              |
              +--com.editev.chess.GameState
Direct Known Subclasses:
Game

public class GameState
extends Board

Represents the State of a game of chess, including the Board position, and castling status, e.p. moves, 50 move rule, etc.

See Also:
the source here.

Inner classes inherited from class com.editev.chess.Chess
Chess.Black, Chess.White
 
Field Summary
(package private)  byte epColumn
          Which row the previous (2-square, pawn) move was in, for a possible e.p., or NO_EP_COLUMN if none.
(package private)  boolean[] kingMoved
          Have the { White, Black } kings moved yet?
(package private)  int moves
          Moves since the start of the game.
static byte NO_EP_COLUMN
          This constant represents the very common case where the last move didn't introduce the possibility of an en passant capture in the next move.
(package private)  int reversibleMoves
          Moves since the last irreversible move.
(package private)  boolean[][] rookMoved
          Have the { {WK, WQ}, {BK, BQ} } rooks moved yet?
 
Fields inherited from class com.editev.chess.Board
PIECE_NAMES, PIECES, squares
 
Fields inherited from class com.editev.chess.Chess
BLACK, NO_MOVE, NO_PIECE, WHITE
 
Constructor Summary
GameState()
           
 
Method Summary
 boolean canBeCaptured(byte piece)
          Can this piece be captured by the player on the move? \
 boolean canMove(byte piece)
          Does this piece belong to the player on-the-move?
 void clearEP()
          Clear the enpassant column, the last move wasn't a pawn or wasn't two squares.
 byte getEP()
           
 int getMoves()
          Moves since start of game.
 int getReversibleMoves()
          Get the number of moves since an irreversible move has occurred (50 move rule).
 void incrementMoves()
          Moves since start of game.
 void irreversibleMove()
          An irreversible move has occurred, which must be a capture or a pawn move (50 move rule).
 boolean isWhiteMove()
          Is white on the move?
 boolean kingMoved(byte king)
          Has a king been moved?
 void moveKing(byte king)
          Marks a king as having been moved.
 void moveRook(byte rook, boolean kSide)
          Mark a rook as having been moved.
 boolean rookMoved(byte rook, boolean kSide)
          Has a rook been moved?
 void setEP(byte column)
          Set the e.p.
 
Methods inherited from class com.editev.chess.Board
clone, cloneBoard, copyFrom, equals, findPieceSquare, getPiece, getPiece, getPieceIndex, getPieceIndex, hasPiece, inCheck, isAttacked, resultsInCheck, setPieceIndex, toString
 
Methods inherited from class com.editev.chess.Chess
notColor, toColor, toColor, toColorName
 
Methods inherited from class java.lang.Object
, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

kingMoved

boolean[] kingMoved
Have the { White, Black } kings moved yet?

rookMoved

boolean[][] rookMoved
Have the { {WK, WQ}, {BK, BQ} } rooks moved yet?

reversibleMoves

int reversibleMoves
Moves since the last irreversible move.

moves

int moves
Moves since the start of the game.

NO_EP_COLUMN

public static final byte NO_EP_COLUMN
This constant represents the very common case where the last move didn't introduce the possibility of an en passant capture in the next move.

epColumn

byte epColumn
Which row the previous (2-square, pawn) move was in, for a possible e.p., or NO_EP_COLUMN if none.
Constructor Detail

GameState

public GameState()
Method Detail

getMoves

public int getMoves()
Moves since start of game.
Returns:
the number of moves since the start of the game

incrementMoves

public void incrementMoves()
Moves since start of game.
Returns:
the number of moves since the start of the game

isWhiteMove

public boolean isWhiteMove()
Is white on the move?
Returns:
true if White is on the move.

canMove

public boolean canMove(byte piece)
Does this piece belong to the player on-the-move?
Returns:
true if this is a piece on the move.

canBeCaptured

public boolean canBeCaptured(byte piece)
Can this piece be captured by the player on the move? \
Returns:
true if this is a piece that can be captured.

kingMoved

public boolean kingMoved(byte king)
Has a king been moved?
Parameters:
color - a piece to indicate the color.
Returns:
true if the king has been moved.

moveKing

public void moveKing(byte king)
Marks a king as having been moved.
Parameters:
color - a piece to indicate the color.

rookMoved

public boolean rookMoved(byte rook,
                         boolean kSide)
Has a rook been moved?
Parameters:
color - a piece to indicate the color.
isKingSide - true if we are looking at the kingside rook
Returns:
true if the rook has been moved.

moveRook

public void moveRook(byte rook,
                     boolean kSide)
Mark a rook as having been moved.
Parameters:
color - a piece to indicate the color.
isKingSide - true if we are looking at the kingside rook

irreversibleMove

public void irreversibleMove()
An irreversible move has occurred, which must be a capture or a pawn move (50 move rule).

getReversibleMoves

public int getReversibleMoves()
Get the number of moves since an irreversible move has occurred (50 move rule).

setEP

public void setEP(byte column)
Set the e.p. column indicating that the last pawn move was two squares (first move).

clearEP

public void clearEP()
Clear the enpassant column, the last move wasn't a pawn or wasn't two squares.

getEP

public byte getEP()
Returns:
e.p. column if there's a potential e.p. capture this turn.