Internet Chess ToolKit
v0.2.0

ictk.boardgame.chess
Class ChessPiece

java.lang.Object
  extended byictk.boardgame.Piece
      extended byictk.boardgame.chess.ChessPiece
Direct Known Subclasses:
Bishop, King, Knight, Pawn, Queen, Rook

public abstract class ChessPiece
extends Piece


Field Summary
static byte BLACK_OFFSET
          an offset for black pieces of the same INDEX value
static byte NULL_PIECE
          the null piece INDEX
 
Constructor Summary
ChessPiece(byte ind, boolean _isBlack, int maxlegaldests, int maxguards)
           
ChessPiece(byte ind, boolean _isBlack, Square _orig, ChessBoard _board, int maxlegaldests, int maxguards)
           
ChessPiece(byte ind, int maxlegaldests, int maxguards)
           
 
Method Summary
 java.lang.String dump()
           
 Board getBoard()
          return the Board that this Piece is associated with (though not necessarily on at the time of the call).
 java.util.List getGuardSquares()
          returns the Squares that this piece guards (when it is the other sides turn to move.
 byte getIndex()
          gets the Index for the type of piece in question.
 java.util.List getLegalDests()
          returns the Squares that are legal destinations on this piece
 Square[] getLineOfSight(ChessPiece target, boolean inclusive)
          get all the squares between two squares along a line (diag or straight).
 Square[] getLineOfSight(int t_file, int t_rank, boolean inclusive)
           
 Square[] getLineOfSight(Square target, boolean inclusive)
           
 ChessPiece getPinnedBy()
           
 Square getSquare()
          gets the square this piece is currently occupying.
 boolean isBishop()
           
 boolean isBlack()
          which side is this piece on?
 boolean isBlockable(Square blocker, ChessPiece target)
          checks to see if another piece may be able to intercede between the piece's origin and destination square
 boolean isCaptured()
          has this piece been captured.
 boolean isGuarding(ChessPiece piece)
          is this piece guarding the parameter piece.
 boolean isGuarding(Square dest)
          is this piece guarding the destination Square?
 boolean isKing()
           
 boolean isKnight()
           
 boolean isLegalAttack(Square dest)
          same as isLegalDests except for special moves like castle and pawn moves.
 boolean isLegalDest(Square dest)
          checks the legalDests list to see if the destination is in that list.
 boolean isPawn()
           
 boolean isQueen()
           
 boolean isRook()
           
 void removeLegalDests()
          clears all legal destinations for this piece.
 void setBoard(ChessBoard b)
          sets the chess board that this piece is on.
 void setCaptured(boolean t)
          sets the piece captured or not.
static ChessPiece toChessPiece(int i)
          this factory method allows for easy conversion of indices to Piece objects of different types.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NULL_PIECE

public static byte NULL_PIECE
the null piece INDEX


BLACK_OFFSET

public static byte BLACK_OFFSET
an offset for black pieces of the same INDEX value

Constructor Detail

ChessPiece

public ChessPiece(byte ind,
                  int maxlegaldests,
                  int maxguards)
Parameters:
ind - is the piece index
maxlegaldests - max number of legal destinations for this piece
maxguards - max number of guard squares for this piece

ChessPiece

public ChessPiece(byte ind,
                  boolean _isBlack,
                  int maxlegaldests,
                  int maxguards)
Parameters:
ind - is the piece index
_isBlack - is the piece black or white
maxlegaldests - max number of legal destinations for this piece
maxguards - max number of guard squares for this piece

ChessPiece

public ChessPiece(byte ind,
                  boolean _isBlack,
                  Square _orig,
                  ChessBoard _board,
                  int maxlegaldests,
                  int maxguards)
Parameters:
ind - is the piece index
_isBlack - is the piece black or white
_orig - which square should it be placed on
_board - which board should it be on
maxlegaldests - max number of legal destinations for this piece
maxguards - max number of guard squares for this piece
Method Detail

isCaptured

public boolean isCaptured()
has this piece been captured.


setCaptured

public void setCaptured(boolean t)
sets the piece captured or not.


getPinnedBy

public ChessPiece getPinnedBy()

isBlack

public boolean isBlack()
which side is this piece on?


setBoard

public void setBoard(ChessBoard b)
sets the chess board that this piece is on.


isLegalDest

public boolean isLegalDest(Square dest)
checks the legalDests list to see if the destination is in that list. If yes then it is a legal move. the piece must also be alive.

Parameters:
dest - - the target of the move, which needs to be considered
Returns:
true - if alive and legalDests contains this destination

isLegalAttack

public boolean isLegalAttack(Square dest)
same as isLegalDests except for special moves like castle and pawn moves.


getLegalDests

public java.util.List getLegalDests()
returns the Squares that are legal destinations on this piece


removeLegalDests

public void removeLegalDests()
clears all legal destinations for this piece. This could be used to eliminate a certian piece from being considered to move in on the board.


getGuardSquares

public java.util.List getGuardSquares()
returns the Squares that this piece guards (when it is the other sides turn to move.


isGuarding

public boolean isGuarding(Square dest)
is this piece guarding the destination Square?


isGuarding

public boolean isGuarding(ChessPiece piece)
is this piece guarding the parameter piece.


getLineOfSight

public Square[] getLineOfSight(ChessPiece target,
                               boolean inclusive)
get all the squares between two squares along a line (diag or straight). Useful for Queens, Rooks and Bishops in determining legal moves and attacks on the King.

Parameters:
inclusive - include the target square in the return set
Returns:
squares in line starting with this peice to target if the squares are not in line then null is returned

getLineOfSight

public Square[] getLineOfSight(Square target,
                               boolean inclusive)

getLineOfSight

public Square[] getLineOfSight(int t_file,
                               int t_rank,
                               boolean inclusive)

isBlockable

public boolean isBlockable(Square blocker,
                           ChessPiece target)
checks to see if another piece may be able to intercede between the piece's origin and destination square

Parameters:
blocker - - the proposed square that can block the attack
target - - the piece under attack
Returns:
true - the blocker intercedes the attack

getIndex

public byte getIndex()
gets the Index for the type of piece in question. This is often used to evade the cost of instanceof and use switch() statements.


getSquare

public Square getSquare()
gets the square this piece is currently occupying.


getBoard

public Board getBoard()
Description copied from class: Piece
return the Board that this Piece is associated with (though not necessarily on at the time of the call).

Specified by:
getBoard in class Piece

toString

public java.lang.String toString()

isKing

public boolean isKing()

isQueen

public boolean isQueen()

isRook

public boolean isRook()

isBishop

public boolean isBishop()

isKnight

public boolean isKnight()

isPawn

public boolean isPawn()

toChessPiece

public static ChessPiece toChessPiece(int i)
this factory method allows for easy conversion of indices to Piece objects of different types.


dump

public java.lang.String dump()

Submit a bug or feature
Visit the Website
Internet Chess ToolKit is licensed under the GPL v2 .