Class Board

java.lang.Object
javachess.model.Board

public class Board extends Object
Class representing a chess board. The board is an 8x8 grid of cells, each of which can contain a piece. The board keeps track of the last move made and provides methods to manipulate the pieces on the board.
  • Constructor Details

    • Board

      public Board()
  • Method Details

    • getCells

      public BiMap<Position,Cell> getCells()
    • getLastMove

      public Move getLastMove()
    • setInitialPieces

      public void setInitialPieces()
      Sets the initial pieces on the board. The pieces are placed in their starting positions according to the rules of chess.
    • cannotMoveWithoutMate

      public boolean cannotMoveWithoutMate(PieceColor color)
      Checks if the king of the given color is in checkmate. it simulates all the possible moves of the pieces of the given color
      Parameters:
      color - the color of the king to check
      Returns:
      true if the king is in checkmate, false otherwise
    • getValidCellsForBoard

      public ArrayList<Cell> getValidCellsForBoard(Piece piece)
      Gets all the possible cells for a piece to move to, (excluding the cells that would put the king in check).
      Parameters:
      piece - the piece to check
      Returns:
      a list of valid cells for the piece to move to
    • getNextCell

      public Cell getNextCell(Cell currentCell, Directions direction)
      Gets the next cell in the given direction from the current cell. Useful for decorators
      Parameters:
      currentCell - the current cell
      direction - the direction to move in
      Returns:
      the next cell in the given direction
    • getIdString

      public String getIdString()
      Gets the ID string of the board. The ID string is a unique representation of the board state. It is used by the threefold repetition rule to check if the same position has occurred before.
      Returns:
      the ID string of the board
    • getPieceOriginFromMove

      public ArrayList<Position> getPieceOriginFromMove(Position to, PieceColor pieceColor, PieceType pieceType)
      Gets the origin positions of pieces that can move to the given position. This is used to parse moves from PGN files.
      Parameters:
      to - the target position
      pieceColor - the color of the piece
      pieceType - the type of the piece
      Returns:
      a list of positions from which a piece can move to the target position
    • findPieceByItsFinalPosition

      public Position findPieceByItsFinalPosition(RegularInstruction instruction)
    • getMoveFromInstructions

      public Move getMoveFromInstructions(Instruction instruction)
      Converts an instruction to a move. This is used to parse moves from PGN files.
      Parameters:
      instruction - the instruction to convert
      Returns:
      the move corresponding to the instruction
    • getSimplifiedFEN

      public String getSimplifiedFEN(PieceColor color)
    • getFEN

      public String getFEN(int fiftyMoveRuleCounter, PieceColor color)
      Converts the current state of the board to a FEN string. see here
      Parameters:
      fiftyMoveRuleCounter - the counter for the fifty-move rule
      color - the color of the player to move
      Returns:
      the FEN string representing the current state of the board