Class ChessGame

java.lang.Object
io.github.wolfraam.chessgame.ChessGame
All Implemented Interfaces:
Serializable, Cloneable

public class ChessGame extends Object implements Serializable, Cloneable
A Chess Game.
See Also:
  • Field Details

  • Constructor Details

    • ChessGame

      public ChessGame()
      Constructs a chess game with the initial position.
    • ChessGame

      public ChessGame(String fen)
      Constructs a chess game with the starting position of the fen argument.
  • Method Details

    • clone

      public ChessGame clone()
      Clones the chess game.
      Overrides:
      clone in class Object
    • getASCII

      public String getASCII()
      Returns:
      an ascii representation of the board
    • getAvailablePGNTags

      public Set<PGNTag> getAvailablePGNTags()
      Returns:
      a set of all the PGN tags available. These are filled when a PGN import has been done.
    • getCapturedPieces

      public List<Piece> getCapturedPieces()
      Returns:
      a list of all captured pieces in the order in which they were captured.
    • getChessOpening

      public ChessOpening getChessOpening()
      Returns:
      the chess opening for this game.
    • getFen

      public String getFen()
      Returns:
      the current board in FEN notation (Forsyth-Edwards Notation)
    • getFenSmall

      public String getFenSmall()
      A shorter version of FEN, without new lines and slashes and which combines empty squares across files.
    • getFullMoveCount

      public int getFullMoveCount()
      The number of the full moves. It starts at 1 and is incremented after Black's move.
    • getGameResult

      public ChessGameResult getGameResult()
      The result of the game as determined by the board. This does NOT take the "Result" tag of an PGN import into account. Returns null if there is no result yet.
    • getGameResultType

      public ChessGameResultType getGameResultType()
      The result of the game as determined by the board. This does NOT take the "Result" tag of an PGN import into account. Returns null if there is no result yet.
    • getInitialFen

      public String getInitialFen()
      The fen of the board before move 1.
    • getLastMove

      public Move getLastMove()
      The last played move, or null if no moves have been played.
    • getLegalMoves

      public Set<Move> getLegalMoves()
      Returns:
      all legal moves for the current position.
    • getLegalMoves

      public Set<Move> getLegalMoves(Square from)
      Returns:
      all legal moves for the piece on the square.
    • getMove

      public Move getMove(NotationType notationType, String move) throws IllegalMoveException
      Returns:
      the Move parsed by the rules of the notationType
      Throws:
      IllegalMoveException - if the notation is not correct
    • getMove

      public Move getMove(NotationType notationType, String languageCode, String move) throws IllegalMoveException
      Returns:
      the Move parsed by the rules of the notationType and the given language
      Throws:
      IllegalMoveException - if the notation is not correct
    • getMoves

      public List<Move> getMoves()
      Returns:
      all played moves of this game.
    • getNotation

      public String getNotation(NotationType notationType, Move move)
      Returns:
      the notation of the move in the given notationType
    • getNotation

      public String getNotation(NotationType notationType, String languageCode, Move move)
      Returns:
      the notation of the move in the given notationType and language
    • getNotationList

      public List<String> getNotationList(NotationType notationType)
      Returns:
      all played moves of this game in the given notationType
    • getNotationList

      public List<String> getNotationList(NotationType notationType, String languageCode)
      Returns:
      all played moves of this game in the given notationType and language
    • getOccupiedSquares

      public Set<Square> getOccupiedSquares()
      Returns:
      the occupied squares of the current board
    • getPGNData

      public PGNData getPGNData()
      Returns:
      the PGNData.
    • getPiece

      public Piece getPiece(Square square)
      Returns:
      piece on the square of the current board.
    • getScore

      public int getScore()
      The current score. Returns a positive integer when white has captured more, negative when black has captured more and 0 when black and white have captured the same. pawn = 1, knight = 3, bishop = 3, rook = 5, queen = 9
    • getSideToMove

      public Side getSideToMove()
      Returns:
      the side whose turn it is to move.
    • getSquares

      public Set<Square> getSquares(Piece piece)
      Returns:
      all the squares where the given piece is on the board
    • getSquaresAttackingKing

      public Set<Square> getSquaresAttackingKing()
      Returns:
      all the squares of pieces which are checking the opposing king
    • getSubset

      public ChessGame getSubset(int moveCount)
      Returns:
      a new chess game which a subset of the moves of this game.
    • isKingAttacked

      public boolean isKingAttacked()
      Returns:
      is the king checked?
    • isLegalMove

      public boolean isLegalMove(Move move)
      Returns:
      whether the move is legal.
    • playMove

      public Piece playMove(Move move)
      Returns:
      plays the move. Does NOT check whether the move is legal.
    • playMove

      public void playMove(NotationType notationType, String move) throws IllegalMoveException
      Plays the move given in the notation type.
      Throws:
      IllegalMoveException - if the notation is not correct
    • playMove

      public void playMove(NotationType notationType, String languageCode, String move) throws IllegalMoveException
      Plays the move given in the language and notation type.
      Throws:
      IllegalMoveException - if the notation is not correct
    • playMoves

      public void playMoves(NotationType notationType, String movesArgument) throws IllegalMoveException
      Plays the moves given in notation type.
      Parameters:
      movesArgument - the moves space or comma seperated
      Throws:
      IllegalMoveException - if a notation is not correct
    • playMoves

      public void playMoves(NotationType notationType, List<String> moveList) throws IllegalMoveException
      Plays the moves given in the notation type.
      Throws:
      IllegalMoveException - if a notation is not correct
    • playMoves

      public void playMoves(NotationType notationType, String languageCode, String movesArgument) throws IllegalMoveException
      Plays the moves given in the notation type and language.
      Parameters:
      movesArgument - the moves space or comma seperated
      Throws:
      IllegalMoveException - if a notation is not correct
    • playMoves

      public void playMoves(String languageCode, NotationType notationType, List<String> moveList) throws IllegalMoveException
      Plays the moves given in the notation type and language.
      Throws:
      IllegalMoveException - if a notation is not correct