Class ChessPiece

java.lang.Object
  |
  +--ChessPiece

public class ChessPiece
extends java.lang.Object

This is the class used for building all chess pieces. This has integer constants in it for piece types and values. It also has methods for pawn promotion, tracking wether a piece has moved or not, and a few accessor methods to retrieve from the object, such as color, type, etc. Last of all is the copy() method that is used to copy the piece itself, making a new object.


Field Summary
static int TYPE_BISHOP
          Integer constant representing a bishop.
static int TYPE_KING
          Integer constant representing a king.
static int TYPE_KNIGHT
          Integer constant representing a knight.
static int TYPE_PAWN
          Integer constant representing a pawn.
static int TYPE_QUEEN
          Integer constant representing a queen.
static int TYPE_ROOK
          Integer constant representing a rook.
static int VALUE_BISHOP
          Integer constant holding the point value of a bishop.
static int VALUE_KING
          Integer constant holding the point value of a king.
static int VALUE_KNIGHT
          Integer constant holding the point value of a knight.
static int VALUE_PAWN
          Integer constant holding the point value of a pawn.
static int VALUE_QUEEN
          Integer constant holding the point value of a queen.
static int VALUE_ROOK
          Integer constant holding the point value of a rook.
 
Constructor Summary
ChessPiece(int type, boolean isWhite)
          Builds a new chess piece based on the given type and color.
 
Method Summary
 ChessPiece copy()
          Returns a field for field copy of this object.
 void firstMove()
          Needs to be called the first time the piece has moved.
 boolean hasMoved()
          Needed for king (castling), rooks (castling), and pawns (they can move two spaces initially).
 boolean isWhite()
          Returns true if the piece is white.
 void promotePawn(int type)
          This is called when a pawn reaches the other side of the board, allowing it to change into one of the other types of pieces.
protected  void setupPiece(int type, boolean isWhite)
          Sets up the piece according to the given data.
 int type()
          Returns an integer representing the type of piece: pawn, knight, bishop, rook, queen, or king.
 int value()
          Returns the material value of the piece.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_PAWN

public static final int TYPE_PAWN
Integer constant representing a pawn.

See Also:
Constant Field Values

TYPE_KNIGHT

public static final int TYPE_KNIGHT
Integer constant representing a knight.

See Also:
Constant Field Values

TYPE_BISHOP

public static final int TYPE_BISHOP
Integer constant representing a bishop.

See Also:
Constant Field Values

TYPE_ROOK

public static final int TYPE_ROOK
Integer constant representing a rook.

See Also:
Constant Field Values

TYPE_QUEEN

public static final int TYPE_QUEEN
Integer constant representing a queen.

See Also:
Constant Field Values

TYPE_KING

public static final int TYPE_KING
Integer constant representing a king.

See Also:
Constant Field Values

VALUE_PAWN

public static final int VALUE_PAWN
Integer constant holding the point value of a pawn.

See Also:
Constant Field Values

VALUE_KNIGHT

public static final int VALUE_KNIGHT
Integer constant holding the point value of a knight.

See Also:
Constant Field Values

VALUE_BISHOP

public static final int VALUE_BISHOP
Integer constant holding the point value of a bishop.

See Also:
Constant Field Values

VALUE_ROOK

public static final int VALUE_ROOK
Integer constant holding the point value of a rook.

See Also:
Constant Field Values

VALUE_QUEEN

public static final int VALUE_QUEEN
Integer constant holding the point value of a queen.

See Also:
Constant Field Values

VALUE_KING

public static final int VALUE_KING
Integer constant holding the point value of a king. It's supposed to be infinite, but 1000000 should do.

See Also:
Constant Field Values
Constructor Detail

ChessPiece

public ChessPiece(int type,
                  boolean isWhite)
Builds a new chess piece based on the given type and color. Simply calls setupPiece().

Method Detail

setupPiece

protected void setupPiece(int type,
                          boolean isWhite)
Sets up the piece according to the given data. Did it this way so promotePawn() can just run this method. This is needed by the constructor and promotePawn().


promotePawn

public void promotePawn(int type)
This is called when a pawn reaches the other side of the board, allowing it to change into one of the other types of pieces. This method should only be called on pawns!


type

public int type()
Returns an integer representing the type of piece: pawn, knight, bishop, rook, queen, or king.


isWhite

public boolean isWhite()
Returns true if the piece is white. False otherwise.


value

public int value()
Returns the material value of the piece. Needed in the evaluation routines to help the engine decide what the best move is, based on value of pieces taken and lost.


hasMoved

public boolean hasMoved()
Needed for king (castling), rooks (castling), and pawns (they can move two spaces initially). This is needed in the Board class's movePiece() method.


firstMove

public void firstMove()
Needs to be called the first time the piece has moved. It's simply used to setup hasMoved(), so it will return the proper value. Only needed for pawns, rooks, and kings.


copy

public ChessPiece copy()
Returns a field for field copy of this object.