Chess Game
The ChessGame class represents a complete chess game, managing the board state, move history, and game logic. It provides methods for making moves, undoing/redoing moves, loading/saving positions in FEN/PGN formats, and querying the game's status. This class encapsulates the rules and mechanics of chess, ensuring valid gameplay and tracking the progression of the game.
Overview
Tracks the current Board state and GameState, including turn, castling rights, en passant targets, and clocks.
Maintains a history of moves and positions for undo/redo functionality and repetition detection.
Supports legal move generation, move validation, and game result determination.
Provides utility methods for interacting with the game using SAN (Standard Algebraic Notation) and UCI (Universal Chess Interface).
Internal Implementation Details
State Management
The current board state is stored in the board property, and the game state in gameState.
Move history is tracked in moveHistory, with currentMoveIndex indicating the active move.
Position history is stored as FEN strings in positionHistory for repetition detection and undo/redo functionality.
Move Handling
The system validates moves against the list of legal moves generated by LegalMoveGenerator.
It handles special moves such as castling, en passant, and pawn promotion seamlessly.
It supports undo and redo by replaying moves from the initial position.
Example of Usage
val game = ChessGame()
println(game.getBoard()) // Print initial board
game.makeSanMove("e4")
game.makeSanMove("e5")
println(game.getFen()) // Print FEN after two movesExample of Internal Access
val game = ChessGame()
val legalMoves = game.getLegalMoves()
val move = legalMoves.first()
game.makeMove(move)
println(game.getFen())Constructors
Functions
Returns the io.github.alluhemanth.chess.core.piece.PieceColor of the player whose turn it is.
Returns the current io.github.alluhemanth.chess.core.game.GameResult, determining if the game is ongoing, drawn, or won.
Returns the current GameState.
Returns a list of all legal moves for the current player.
Returns true if the game is over, false otherwise.
Makes a move from a SAN (Standard Algebraic Notation) string.
Makes a move from a UCI (Universal Chess Interface) string.