Node

class 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.

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

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

Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard

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

Link copied to clipboard
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
val parent: 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

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

Link copied to clipboard

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

Functions

Link copied to clipboard
fun appendMove(move: String, initialComment: String? = null, comment: String? = null, endLineComment: String? = null, suffixAnnotations: JsReadonlyArray<Int>? = null, notation: Notation = SAN): 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

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

Link copied to clipboard
fun copy(parent: Node?): 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 operator override fun equals(other: Any?): Boolean
Link copied to clipboard

Checks if the node has children.

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

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

Link copied to clipboard

Promotes this node to the main line.

Link copied to clipboard

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

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