Module app
Package app.chess

Class AbstractChessPiece

java.lang.Object
app.chess.AbstractChessPiece
All Implemented Interfaces:
Piece
Direct Known Subclasses:
Bishop, King, Knight, Pawn, Queen, Rook

public abstract class AbstractChessPiece extends Object implements Piece
Internal game implementation of a chess piece
  • Field Details

    • wasMoved

      protected boolean wasMoved
    • isBlack

      protected boolean isBlack
    • isAlive

      protected boolean isAlive
    • position

      protected Field position
    • kind

      protected ChessPieceKind kind
    • color

      protected ChessPieceColor color
  • Constructor Details

  • Method Details

    • overwriteState

      public void overwriteState(AbstractChessPiece toCopy)
      This function effectively copies all state from another piece.
      Please, use it with caution under acceptable circumstances.
      Passing incompatible pieces might result in an exception.
    • getPosition

      public Field getPosition()
      Specified by:
      getPosition in interface Piece
      Returns:
      position this piece is located at
    • isAlive

      public boolean isAlive()
      Specified by:
      isAlive in interface Piece
      Returns:
      true if piece is still in game, false otherwise
    • getPlayer

      public int getPlayer()
      Specified by:
      getPlayer in interface Piece
      Returns:
      id of player that can play with this piece
    • getKind

      public ChessPieceKind getKind()
    • getColor

      public ChessPieceColor getColor()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • kill

      void kill()
    • move

      public void move(Field newPosition)
    • resetMoved

      public void resetMoved()
    • enPassantable

      public boolean enPassantable()
    • canParticipateInCastling

      public boolean canParticipateInCastling()
    • getPotentialMoves

      public abstract List<ChessMove> getPotentialMoves()
      Returns:
      A list of ChessMoves that are potentially valid (i.e. the caller needs to check if king's safety is ok and whether path to the given field isn't obstructed
    • wrap

      public ChessPiece wrap()
      Wraps this piece into ChessPiece that can be publicly exposed
      Returns:
      wrapped piece