Package-level declarations

Types

Link copied to clipboard
class EcoInfo

A container class representing the information about a chess opening based on the Encyclopedia of Chess Openings (ECO). It is immutable.

Link copied to clipboard

Class for manipulating games. It allows starting a game from a configurable initial position and with various configuration options, such as the game type (match or analysis), and how to apply the three-fold repetition and 50-move rules.

Link copied to clipboard
open class Move

Represents a single player's move on the board. It does not store information about the origin position, as its primary purpose is move representation. Its string representation is the full algebraic notation of the move as used in the UCI protocol (e.g., "e2e4", "a7a8q"). It is immutable.

Link copied to clipboard

Exception thrown when inconsistencies occur in functionalities related to move validation or generation logic.

Link copied to clipboard

This enum represents the types of move notation supported by this library. This enum is used as an argument in functions related to move validation and generation logic.

Link copied to clipboard
enum Piece : Enum<Piece>

This class represents the chess pieces on the board. Each piece has a corresponding side (color).

Link copied to clipboard
class Position

Class to represent a position on the chessboard. It is immutable.

Link copied to clipboard
enum Side : Enum<Side>

This enum represents the two sides (colors) in a chess game: White or Black.

Link copied to clipboard
enum Square : Enum<Square>

This enum represents the squares on the chessboard. The order is set such that when calling ordinal, the integer 0 corresponds to A1, 1 corresponds to B1, and so on, following the file-major order (A1, B1, C1... H1, A2, B2... H8), with 63 corresponding to H8.

Link copied to clipboard
class Tuple<T1, T2>

Auxiliary generic class to represent a pair of related, heterogeneous elements. It is immutable.

Properties

Link copied to clipboard

A list of tuples, where each tuple represents a legal move from this position and the resulting new position (Tuple). This list effectively defines the legal branches of the game tree from the current position.

Link copied to clipboard

True if the position is a forced draw. This is true if the position results in a stalemate or lackOfMaterial. False otherwise.

Link copied to clipboard

The square exposed to an en passant capture, if one exists. Returns null if no en passant capture is possible in the current position.

Link copied to clipboard

True if the game state is concluded (terminal position), either due to a forced draw or checkmate. False otherwise.

Link copied to clipboard

The side (Side.WHITE or Side.BLACK) whose turn it is to move.

Functions

Link copied to clipboard
fun analysisGame(idSupplier: () -> Any? = { null }): Game

Creates a new Game instance configured for analysis. Uses Game.GameMode.ANALYSIS with Game.ThreeRepetitionsMode.AWARE and Game.FiftyMovesRuleMode.AWARE, making the game fully mutable.

Link copied to clipboard
fun customGame(gameMode: Game.GameMode, threeRepetitionsMode: Game.ThreeRepetitionsMode, fiftyMovesRuleMode: Game.FiftyMovesRuleMode, initialFen: String? = null, initialTags: Map<String, String>? = null, idSupplier: () -> Any? = { null }): Game

Creates a new Game instance with fully customizable parameters. Allows setting the game mode, rule enforcement, initial FEN, and PGN tags.

Link copied to clipboard

Deletes all moves that preceded the provided node in the main line. The node (and its position) becomes the new effective start of the game, creating a new RootNode.

Link copied to clipboard

Deletes all moves (the main line continuation and any variations) that follow the provided node. The node provided remains in the game.

Link copied to clipboard

Deletes the provided node and all subsequent moves/variations in its subtree. The move represented by the node is effectively removed from the game.

Link copied to clipboard

Returns true if the evaluated Move is legal in the current position, and false otherwise.

fun Position.isLegal(move: String, notation: Notation = Notation.UCI): Boolean

Returns true if the move specified in the given notation is legal in the current position. If no notation is specified, Notation.UCI is assumed.

Link copied to clipboard

Retrieves the new Position that results from executing the provided legal Move. Throws a MoveException if the provided move is not legal in the current position.

fun Position.move(move: String, notation: Notation = Notation.UCI): Position

Retrieves the new Position that results from executing the move specified in the given notation. Throws a MoveException if the move is not legal. If no notation is provided, Notation.UCI is assumed.

Link copied to clipboard
fun moveOf(move: String): Move

Creates a Move object from its UCI notation string (e.g., "e7e8q").

fun moveOf(origin: Square, target: Square): Move

Creates a Move object from the origin square and target square Square enum constants.

fun moveOf(origin: Int, target: Int): Move

Creates a Move object from the specified origin and target squares (using Int as the squares types).

fun moveOf(origin: Square, target: Square, promotionPiece: Piece): Move

Creates a Move object from the origin square, target square, and the promotion piece, using Square and Piece enum constants.

fun moveOf(origin: Int, target: Int, promotionPiece: Int): Move

Creates a Move object from the specified origin and target squares (using Int as the squares types) and the promotion piece.

Link copied to clipboard
fun parseGames(pgnInput: String, idSupplier: () -> Any? = { null }): List<Game>

Parses a string containing one or more games in Portable Game Notation (PGN) format. Games are returned in Game.GameMode.ANALYSIS mode, making them mutable for subsequent use.

Link copied to clipboard

Returns the standard starting Position (the startpos FEN).

Factory function to create a Position object from a FEN string. Throws an exception if the FEN string is invalid or leads to an illegal position.

Link copied to clipboard
fun strictMatch(idSupplier: () -> Any? = { null }): Game

Creates a new Game instance configured for strict competitive match play. Uses Game.GameMode.MATCH with strict enforcement for the three-fold repetition and 50-move rules.

Link copied to clipboard

Removes the last node in the main line, effectively undoing the last move, and returns the parent node. This function only operates on the primary variation (main line).