Node

interface Node

Each game can be interpreted as a series of interconnected nodes in a tree. Each node is move in the game and holds information about the board state after that move. Additionally, each node can have regular or end-of-line comments, suffix annotations, as well as more than one child (from the second child onwards, they are variations), and always only one parent node.

Properties

Link copied to clipboard

The children of the node. The first child corresponds to the main line. The rest are variations (RAVs).

Link copied to clipboard
abstract var comment: String?

The regular comment that follows the move and any suffix annotations (e.g., 1. e4 {Comment}).

Link copied to clipboard
abstract var endLineComment: String?

The end-of-line comment for the node, which follows a semicolon ; and goes until the end of the line.

Link copied to clipboard
abstract var initialComment: String?

The comment that precedes the move number in PGN (e.g., "{Comment} 1. e4").

Link copied to clipboard
abstract val move: Move?

The move of the node. It is null when it is the root node, which only has the starting position of the game.

Link copied to clipboard
abstract var parent: Game.Node?

The parent node. It can only be null when it is the root node, which evidently cannot have a parent.

Link copied to clipboard
abstract val position: Position

The position of the node, which is the result after executing the move.

Link copied to clipboard
abstract var suffixAnnotations: List<Int>?

The list of suffix annotations (NAGs) for the node.

Functions

Link copied to clipboard
abstract fun appendMove(move: String, initialComment: String? = null, comment: String? = null, endLineComment: String? = null, suffixAnnotations: List<Int>? = null, notation: Notation = Notation.SAN): Game.Node

Appends a move and returns the added node. If the node already has a child, the added move will be a variation (RAV). Returns the new node if the move is legal, or the current node if the move is illegal.

Link copied to clipboard
abstract fun belongsToMainLine(): Boolean

Indicates whether this node belongs to the main line (i.e., it is the first child of all its ancestors).

Link copied to clipboard
abstract fun copy(parent: Game.Node?): Game.Node

Creates a deep copy of this node and its entire subtree, assigning the specified parent to the new copy. This process is recursive; copying the root node copies the entire game tree.

Link copied to clipboard
open fun hasChildren(): Boolean

Checks if the node has children.

Link copied to clipboard
open fun promoteChild(index: Int): Boolean

Promotes the child at the given index to the primary variation (children0).

Link copied to clipboard
open fun promoteNode(): Boolean

Promotes this node to the main line.

Link copied to clipboard
open fun removeChild(node: Game.Node): Boolean

Removes the specified child node (variation) from the current node's list of children.