Game

class Game

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.

This class implements Iterable, allowing easy traversal over the nodes of the main line. The toString function returns the game in PGN format.

This is a facade created to enable exporting the code to JS, though it can also be used directly within the JS modules of any KMP project.

Properties

Link copied to clipboard

Stores the current ECO (Encyclopedia of Chess Openings) information for the main line. Setting this property will be ignored if the game is immutable (i.e., MATCH and result is set).

Link copied to clipboard

Indicates whether the 50-move half-move limit has been reached (non-terminal).

Link copied to clipboard

Determines how the fifty-move rule is enforced for this game instance. Setting this property will be ignored if the game is immutable.

Link copied to clipboard

An optional comment placed immediately after the game's result tag in PGN. This comment is enclosed in braces {}. Setting this property will be ignored if the game is immutable.

Link copied to clipboard

An optional end-of-line comment placed immediately after the game's result tag in PGN. This comment follows a semicolon ; and extends until the end of the line. Setting this property will be ignored if the game is immutable.

Link copied to clipboard

Indicates whether a position has been repeated five times, leading to an automatic draw according to FIDE rules (terminal).

Link copied to clipboard
val id: Any?

A developer-provided unique identifier for serialization or tracking purposes (e.g., UUID or String).

Link copied to clipboard

The final result of the game. Setting this property will update the "Result" tag in tags and set the game as immutable if MATCH is used.

Link copied to clipboard
val root: Node

The root node of the game tree. The setter is protected if the game is immutable.

Link copied to clipboard

Indicates whether the 75-move half-move limit has been reached, leading to an automatic draw (terminal).

Link copied to clipboard
val tags: dynamic

Standard PGN tags (e.g., Event, Site, Date, Round, White, Black, Result).

Link copied to clipboard

Determines how the three-fold repetition rule is enforced for this game instance. Setting this property will be ignored if the game is immutable.

Link copied to clipboard

Indicates that a three-fold repetition draw can be claimed, as the repetition is impending (e.g., the current move will complete the third repetition).

Functions

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 all moves (the main line continuation and any variations) that follow the provided node. The move represented by the node is effectively removed from the game.

Link copied to clipboard
fun getTag(name: String): String?

Retrieves the tag's value

Link copied to clipboard
fun setTag(name: String, value: String)

Sets a tag pair (name and value)

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

Creates a deep copy of this game, converting its mode to ANALYSIS and setting both repetition rules to AWARE. This makes the new instance fully mutable for analysis.

Link copied to clipboard
open override fun toString(): String