Package javachess.model
Class Board
java.lang.Object
javachess.model.Board
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancannotMoveWithoutMate(PieceColor color) Checks if the king of the given color is in checkmate.findPieceByItsFinalPosition(RegularInstruction instruction) getCells()getFEN(int fiftyMoveRuleCounter, PieceColor color) Converts the current state of the board to a FEN string.Gets the ID string of the board.getMoveFromInstructions(Instruction instruction) Converts an instruction to a move.getNextCell(Cell currentCell, Directions direction) Gets the next cell in the given direction from the current cell.getPieceOriginFromMove(Position to, PieceColor pieceColor, PieceType pieceType) Gets the origin positions of pieces that can move to the given position.getSimplifiedFEN(PieceColor color) getValidCellsForBoard(Piece piece) Gets all the possible cells for a piece to move to, (excluding the cells that would put the king in check).voidSets the initial pieces on the board.
-
Constructor Details
-
Board
public Board()
-
-
Method Details
-
getCells
-
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
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
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
Gets the next cell in the given direction from the current cell. Useful for decorators- Parameters:
currentCell- the current celldirection- the direction to move in- Returns:
- the next cell in the given direction
-
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 positionpieceColor- the color of the piecepieceType- the type of the piece- Returns:
- a list of positions from which a piece can move to the target position
-
findPieceByItsFinalPosition
-
getMoveFromInstructions
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
-
getFEN
Converts the current state of the board to a FEN string. see here- Parameters:
fiftyMoveRuleCounter- the counter for the fifty-move rulecolor- the color of the player to move- Returns:
- the FEN string representing the current state of the board
-