com.editev.chess.piece
Class Piece

java.lang.Object
  |
  +--com.editev.chess.Chess
        |
        +--com.editev.chess.piece.Piece
Direct Known Subclasses:
Bishop, Knight, Pawn, Queen, Rook

public abstract class Piece
extends Chess

Contains a list of possible piece moves as byte offsets, and encompasses all the rules about legal moves and actually performing the move as an operation on the Game.

See Also:
the source here.

Inner classes inherited from class com.editev.chess.Chess
Chess.Black, Chess.White
 
Field Summary
 byte[][] moves
          The moves describe all the possible moves in left-to-right, top-to-bottom order.
 
Fields inherited from class com.editev.chess.Chess
BLACK, NO_MOVE, NO_PIECE, WHITE
 
Constructor Summary
Piece(byte[][] moves)
           
 
Method Summary
 byte applyMoveToBoard(Move move, Board board)
          Adjust the board's pieces only.
 void applyMoveToState(Move move, GameState game)
          Adjust the board's game, which is everything that isn't the board's squares: handles promotions, e.p., castling rules, 50 move rule.
 void firstMoveIndex(Move move)
          Go to the first move Index.
 byte getColumnOffset(Move move)
          Convenience function to translate a move's index into a column offset from the move table.
 byte getRowOffset(Move move)
          Convenience function to translate a move's index into a row offset from the move table.
 boolean incrementMoveIndex(Move move)
          Go to next possible move.
 boolean isCapture(Move move, Board board)
          Is this move a capture on this board?
 boolean isIllegal(Move move, Game game)
          Is this illegal because of a piece-specific rule?
 boolean isIrreversible(Move move, Board board)
          Is this move irreversible?
 boolean moreMoves(Move move)
          Any more possible moves?
 boolean pieceBetween(Move move, Board board)
          Is there a piece between the "from" and "target" squares? Only the Knight overrides this method.
 void setMoveIndex(Move move, byte index)
          Go to a specific move index.
 void undoMoveToBoard(Move move, Board board, byte captured)
          Undo a move, using the piece captured, if any.
 
Methods inherited from class com.editev.chess.Chess
notColor, toColor, toColor, toColorName
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

moves

public final byte[][] moves
The moves describe all the possible moves in left-to-right, top-to-bottom order.
Constructor Detail

Piece

public Piece(byte[][] moves)
Method Detail

pieceBetween

public boolean pieceBetween(Move move,
                            Board board)
Is there a piece between the "from" and "target" squares? Only the Knight overrides this method.

applyMoveToBoard

public byte applyMoveToBoard(Move move,
                             Board board)
Adjust the board's pieces only. @return the captured piece if any. Only the King and Pawn override this method.

undoMoveToBoard

public void undoMoveToBoard(Move move,
                            Board board,
                            byte captured)
Undo a move, using the piece captured, if any. Only the King and Pawn override this method.

applyMoveToState

public void applyMoveToState(Move move,
                             GameState game)
Adjust the board's game, which is everything that isn't the board's squares: handles promotions, e.p., castling rules, 50 move rule. We DO need the Game and and not just the game because we need to see if the move is a capture... The King, the Pawn and the Rook override this method.

firstMoveIndex

public void firstMoveIndex(Move move)
Go to the first move Index.
Returns:
false if there are no more possible moves to go to. Only the Pawn overrides this method.

setMoveIndex

public void setMoveIndex(Move move,
                         byte index)
Go to a specific move index.
Returns:
false if there are no more possible moves to go to. Only the Pawn overrides this method.

incrementMoveIndex

public boolean incrementMoveIndex(Move move)
Go to next possible move.
Returns:
false if there are no more possible moves to go to. Only the Pawn overrides this.

moreMoves

public boolean moreMoves(Move move)
Any more possible moves?
Returns:
true if there are more possible moves after this move. Only the Pawn overrides this.

isCapture

public boolean isCapture(Move move,
                         Board board)
Is this move a capture on this board?
Returns:
whether this move is a capture for this board. Only the Pawn overrides this, for e.p. captures and to prevent capturing by advancing straight

isIrreversible

public boolean isIrreversible(Move move,
                              Board board)
Is this move irreversible?
Returns:
true if this move restarts the 50 move rule. Only the Pawn overrides this.

isIllegal

public boolean isIllegal(Move move,
                         Game game)
Is this illegal because of a piece-specific rule?
Returns:
true if the piece makes this move illegal for this game. We only override this for King and Pawn.

getColumnOffset

public final byte getColumnOffset(Move move)
Convenience function to translate a move's index into a column offset from the move table.

getRowOffset

public final byte getRowOffset(Move move)
Convenience function to translate a move's index into a row offset from the move table.