core
Class Piece
java.lang.Object
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
-
-
state : int //Useful for castling/en passant
-
color : Color //Who the owner is
-
name : String //Name of this piece type
- Derived Fields:
moves(GameState) : Set //Possible moves from a position
|
Constructor Summary |
Piece(Color color,
int lastMove)
Constructs a new piece. |
color
protected Color color
Piece
public Piece(Color color,
int lastMove)
- Constructs a new piece.
- Parameters:
color - of the piecelastMove - of the piece (0 means it hasn't moved)- Requires:
- color not null, last move valid
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