core
Class Piece

java.lang.Object
  extended by core.Piece
Direct Known Subclasses:
King, Knight, NoneSquare, Pawn, StraightPiece

public abstract class Piece
extends Object

A Piece represents a state of the board. Individual pieces are subclasses of Piece, overriding various methods to determine their name and how they move. Pieces are immutable. One special case is Empty, for non-piece squares.

Specification Fields
Derived Fields:
moves(GameState) : Set //Possible moves from a position

Field Summary
protected  Color color
           
 
Constructor Summary
Piece(Color color, int lastMove)
          Constructs a new piece.
 
Method Summary
 Color getColor()
           
 int getLastMove()
           
protected abstract  String getName()
           
abstract  int hashCode()
          This should be unique for different pieces or different colors.
abstract  Collection<Move> moveCandidates(GameState g, Position here)
           
abstract  String pieceString()
           
 void postMove(GameState gs, Map<Position,Piece> move, Position here)
          Apply the modifications to a move map for a move onto this square completes.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

color

protected Color color
Constructor Detail

Piece

public Piece(Color color,
             int lastMove)
Constructs a new piece.

Parameters:
color - of the piece
lastMove - of the piece (0 means it hasn't moved)
Requires:
color not null, last move valid
Method Detail

getName

protected abstract String getName()
Returns:
a single-character name of this piece

pieceString

public abstract String pieceString()
Returns:
a human readable string for the piece.

moveCandidates

public abstract Collection<Move> moveCandidates(GameState g,
                                                Position here)
Requires:
g, here != null
Returns:
valid moves for this piece.

getLastMove

public int getLastMove()
Returns:
the last time this piece moved

getColor

public Color getColor()
Returns:
the color of this piece

toString

public String toString()
Overrides:
toString in class Object
Returns:
the short 1-character name of this piece, in lower case for black and upper case for white.

postMove

public void postMove(GameState gs,
                     Map<Position,Piece> move,
                     Position here)
Apply the modifications to a move map for a move onto this square completes. Used to implement powerups; others can safely do nothing.


hashCode

public abstract int hashCode()
This should be unique for different pieces or different colors.

Overrides:
hashCode in class Object