com.editev.chess.piece
Class Pawn

java.lang.Object
  |
  +--com.editev.chess.Chess
        |
        +--com.editev.chess.piece.Piece
              |
              +--com.editev.chess.piece.Pawn
Direct Known Subclasses:
Pawn.Black, Pawn.White

public abstract class Pawn
extends Piece

The Pawn has four special cases; first move, en passant, capturing and promotion. This is the most complicated of all the Pieces, and there are two derived classes, Pawn.Black and Pawn.White.

See Also:
the source here.

Inner Class Summary
static class Pawn.Black
          This derivation of Pawn represents a Black pawn, and only differs from the White pawn by its list of moves.
static class Pawn.White
          This derivation of Pawn represents a White pawn, and only differs from the Black pawn by its list of moves.
 
Inner classes inherited from class com.editev.chess.Chess
Chess.Black, Chess.White
 
Field Summary
static byte EP_CAPTURE
          Special piece indicates an en passant (e.p.) capture.
 
Fields inherited from class com.editev.chess.piece.Piece
moves
 
Fields inherited from class com.editev.chess.Chess
BLACK, NO_MOVE, NO_PIECE, WHITE
 
Constructor Summary
protected Pawn(byte[][] moves)
           
 
Method Summary
 byte applyMoveToBoard(Move move, Board board)
          Apply the move to the squares of the board.
 void applyMoveToState(Move move, GameState game)
          Change the GameState component of the game for this pawn move -- we need to override this method because we need to store the e.p.
 boolean incrementMoveIndex(Move move)
          Increment the move to the next one.
 boolean isCapture(Move move, Board board)
          We have to override this method because Pawns only capture diagonally.
 boolean isepCapture(Move move, Board board)
          Is this legal move an e.p.
 boolean isIllegal(Move move, Game game)
          Is this Pawn move legal? It may only move two squares on the first move.
 boolean isIrreversible(Move move, Board board)
          Pawn moves are never reversible.
static boolean isPromotion(Move move)
          Is this move a promotion for either color?
static boolean isPromotion(Move move, byte color)
          Is this move a promotion for the given color?
static boolean isTwoSquare(Move move)
          Is this a two square move for the pawn?
 boolean moreMoves(Move move)
          Any more moves? This is also overridden to take care of the promotions.
 void undoMoveToBoard(Move move, Board board, byte piece)
          Unapply the move to the squares of the board.
 
Methods inherited from class com.editev.chess.piece.Piece
firstMoveIndex, getColumnOffset, getRowOffset, pieceBetween, setMoveIndex
 
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

EP_CAPTURE

public static byte EP_CAPTURE
Special piece indicates an en passant (e.p.) capture.
Constructor Detail

Pawn

protected Pawn(byte[][] moves)
Method Detail

isIllegal

public boolean isIllegal(Move move,
                         Game game)
Is this Pawn move legal? It may only move two squares on the first move. It moves forward to empty squares, and captures diagonally. En passant occurs if the opponent's last move was the two square first move and the player could have captured the pawn if it only moved one square. Promotion isn't involved here.
Overrides:
isIllegal in class Piece
Returns:
true if this Pawn move is illegal

incrementMoveIndex

public boolean incrementMoveIndex(Move move)
Increment the move to the next one. This is overridden in order to count through the promotions.
Overrides:
incrementMoveIndex in class Piece
Tags copied from class: Piece
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 moves? This is also overridden to take care of the promotions.
Overrides:
moreMoves in class Piece
Tags copied from class: Piece
Returns:
true if there are more possible moves after this move. Only the Pawn overrides this.

applyMoveToBoard

public byte applyMoveToBoard(Move move,
                             Board board)
Apply the move to the squares of the board. In the case of a promotion, we need to replace the Pawn with another Piece. In the case of an e.p. capture, we need to remove the captured enemy Pawn.
Overrides:
applyMoveToBoard in class Piece

undoMoveToBoard

public void undoMoveToBoard(Move move,
                            Board board,
                            byte piece)
Unapply the move to the squares of the board. We have the same special cases as applyMoveToBoard, namely promotion and e.p.
Overrides:
undoMoveToBoard in class Piece

applyMoveToState

public void applyMoveToState(Move move,
                             GameState game)
Change the GameState component of the game for this pawn move -- we need to override this method because we need to store the e.p. game to validate next pawn moves for a possible e.p. capture.
Overrides:
applyMoveToState in class Piece

isIrreversible

public boolean isIrreversible(Move move,
                              Board board)
Pawn moves are never reversible.
Overrides:
isIrreversible in class Piece
Returns:
false.

isCapture

public boolean isCapture(Move move,
                         Board board)
We have to override this method because Pawns only capture diagonally.
Overrides:
isCapture in class Piece
Tags copied from class: Piece
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

isPromotion

public static boolean isPromotion(Move move,
                                  byte color)
Is this move a promotion for the given color?

isPromotion

public static boolean isPromotion(Move move)
Is this move a promotion for either color?

isTwoSquare

public static boolean isTwoSquare(Move move)
Is this a two square move for the pawn?

isepCapture

public boolean isepCapture(Move move,
                           Board board)
Is this legal move an e.p. capture?