com.editev.chess
Class Board

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

public class Board
extends Chess
implements java.lang.Cloneable

Represent just the Pieces on the 64 Squares of the chess board as byte indices.

See Also:
the source here.

Inner classes inherited from class com.editev.chess.Chess
Chess.Black, Chess.White
 
Field Summary
static char[] PIECE_NAMES
          Character identifiers for the pieces.
static Piece[] PIECES
          A list of Pieces for each piece index which is used to translate the indices representing pieces in the Board into Pieces with rules.
private  byte[][] squares
          The actual 64 squares in an 8x8 array.
 
Fields inherited from class com.editev.chess.Chess
BLACK, NO_MOVE, NO_PIECE, WHITE
 
Constructor Summary
Board()
           
 
Method Summary
 java.lang.Object clone()
          A deep copy clone().
 Board cloneBoard()
          A deep copy clone() that returns a Board.
 void copyFrom(Board board)
          Copy the contents of another Board into this Board.
 boolean equals(java.lang.Object x)
          Two boards are equal if all their squares are equal.
 Square findPieceSquare(byte piece)
          Find a Piece on the board.
 Piece getPiece(Move move)
          Gets the Piece being Moved..
 Piece getPiece(Square sq)
          Gets the Piece at the given square.
 byte getPieceIndex(Move move)
          Get a piece index by source of Move.
 byte getPieceIndex(Square sq)
          Get a piece index by Square.
 boolean hasPiece(Square sq)
          Is there a piece on this square? @return true if there is a piece at this Square
 boolean inCheck(boolean isWhite)
          Is the king of this color in check?
 boolean isAttacked(boolean whitesMove, Square square)
          Is this square attacked?
 boolean resultsInCheck(Move move, Piece piece)
          Does this move result in check?
 void setPieceIndex(Square sq, byte piece)
          Set a piece index by Square.
 java.lang.String 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

squares

private final byte[][] squares
The actual 64 squares in an 8x8 array. Pieces are represented as simple byte indices for efficiency.

PIECES

public static Piece[] PIECES
A list of Pieces for each piece index which is used to translate the indices representing pieces in the Board into Pieces with rules.

PIECE_NAMES

public static final char[] PIECE_NAMES
Character identifiers for the pieces.
Constructor Detail

Board

public Board()
Method Detail

getPieceIndex

public byte getPieceIndex(Square sq)
Get a piece index by Square.

getPieceIndex

public byte getPieceIndex(Move move)
Get a piece index by source of Move.

setPieceIndex

public void setPieceIndex(Square sq,
                          byte piece)
Set a piece index by Square.

hasPiece

public boolean hasPiece(Square sq)
Is there a piece on this square? @return true if there is a piece at this Square

getPiece

public Piece getPiece(Square sq)
Gets the Piece at the given square.
Parameters:
sq - the Square on the Board containing the Piece.
Returns:
the Piece at that square or null if there is no piece at that Square.

getPiece

public Piece getPiece(Move move)
Gets the Piece being Moved..
Parameters:
sq - the Square on the Board containing the Piece.
Returns:
the Piece at the source of the Move or null if there is no piece at the source..

findPieceSquare

public Square findPieceSquare(byte piece)
Find a Piece on the board.
Returns:
a square containing the first matching piece on the board when searched in row-major order or null if no such piece.

inCheck

public boolean inCheck(boolean isWhite)
Is the king of this color in check?

resultsInCheck

public boolean resultsInCheck(Move move,
                              Piece piece)
Does this move result in check?
Returns:
true if making this move would result in check.

isAttacked

public boolean isAttacked(boolean whitesMove,
                          Square square)
Is this square attacked?
Returns:
true if this row/column square is attacked.

equals

public boolean equals(java.lang.Object x)
Two boards are equal if all their squares are equal.
Overrides:
equals in class java.lang.Object

clone

public java.lang.Object clone()
A deep copy clone().
Overrides:
clone in class java.lang.Object
Returns:
a deep copy clone of the board with entirely new arrays.

cloneBoard

public Board cloneBoard()
A deep copy clone() that returns a Board.
Returns:
a deep copy clone of the board with entirely new arrays.

copyFrom

public void copyFrom(Board board)
Copy the contents of another Board into this Board.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a String version of the board for debugging purposes.