chess-core

Welcome to chess-core! This Kotlin library is designed to handle all the core logic and rules of chess, making it easy to build chess apps, tools, or analysis utilities. It focuses on move generation, rule enforcement, and game state management. If you want to connect to a chess engine like Stockfish for analysis or computer play, this library provides a simple wrapper for that—but it does not include a chess engine or AI itself.

Features

  • Comprehensive Chess Rules: Handles all standard chess rules, including castling, en passant, pawn promotion, and draw conditions (like threefold repetition and the fifty-move rule).

  • FEN and PGN Support: Easily load and export games using Forsyth-Edwards Notation (FEN) and Portable Game Notation (PGN) for saving, sharing, and analyzing games.

  • Fast Move Generation: Quickly generate all legal moves for any position—ideal for building analysis tools, GUIs, or integrating with chess engines.

  • Modular and Extensible: The code is organized for easy extension, so you can add features or adapt it for your own chess-related projects.

  • Engine Communication: Includes a wrapper to communicate with external chess engines like Stockfish for advanced analysis or computer play.

Packages

Link copied to clipboard

This is the main package, bringing together all the core features for working with chess games. Here you’ll find the primary classes for setting up and managing a chess game.

Link copied to clipboard

Handles everything related to the chessboard: board representation, squares, files (columns), and ranks (rows). Responsible for tracking piece positions, validating moves, and setting up positions (including from FEN strings).

Link copied to clipboard

Custom exceptions for error handling, such as invalid moves, bad FEN strings, or out-of-bounds board coordinates.

Link copied to clipboard

Manages the flow of the chess game: turn management, special moves (castling, en passant), and game end conditions ( checkmate, stalemate, draw, etc.).

Link copied to clipboard

Focuses on move generation and validation. Generates legal moves, checks move validity, and applies moves to the board. PseudoLegalMoveGenerator.kt: Generates moves that are legal except for leaving the king in check.

Link copied to clipboard

Defines how each chess piece moves. Implements the movement rules for pawns, knights, bishops, rooks, queens, and kings.

Link copied to clipboard

Defines chess pieces, their types, and colors.

Link copied to clipboard

Utility functions for working with chess data, including FEN and PGN parsing/generation and standard algebraic notation (SAN).