Node()

Represent one move in the tree structure formed by a chess game with multiple variations.

new Node()

This constructor is not exposed in the public Kokopu API. Only internal objects and functions are allowed to instantiate Node objects.

Methods

addNag(nag)

Add the given NAG to the current move.

Parameters:
Name Type Description
nag number

addVariation(isLongVariation) → {Variation}

Create a new variation that can be played instead of the current move.

Parameters:
Name Type Description
isLongVariation boolean
Returns:
Variation

comment()nullable {string}

Get the text comment associated to the current move.

Returns:
string -

undefined if no comment is defined for the move.

comment(value, isLongCommentopt)

Set the text comment associated to the current move.

Parameters:
Name Type Attributes Default Description
value string
isLongComment boolean <optional>
false

figurineNotation() → {string}

SAN-like representation of the move associated to the current node (or '--' for a null-move).

Returns:
string -

Chess pieces are represented with their respective unicode character, instead of the first letter of their English name.

fullMoveNumber() → {number}

Full-move number. It starts at 1, and is incremented after each black move.

Returns:
number

hasNag(nag) → {boolean}

Check whether the current move has the given NAG or not.

Parameters:
Name Type Description
nag number
Returns:
boolean

id() → {string}

Identifier of the current node within its parent Game.

WARNING: the ID may change when variations are modified (added, removed, swapped, promoted...) among the parents the current node.

Returns:
string

isLongComment() → {boolean}

Whether the text comment associated to the current move is long or short.

Returns:
boolean -

Always false if no comment is defined.

isVariation() → {boolean}

Always false. Useful to discrimate between Node and Variation instances.

Returns:
boolean

moveColor() → {Color}

Color the side corresponding to the current move.

Returns:
Color

nags() → {Array.<number>}

Return the NAGs associated to the current move.

Returns:
Array.<number> -

Sorted array.

next()nullable {Node}

Return the Node that comes after the current one in their parent variation.

Returns:
Node -

undefined if the current node is the last one of the variation.

notation() → {string}

SAN representation of the move associated to the current node (or '--' for a null-move).

Returns:
string

parentVariation() → {Variation}

Return the Variation that owns the current node.

Returns:
Variation

play(move) → {Node}

Play the given move, and return a new Node pointing at the resulting position.

Parameters:
Name Type Description
move string

SAN notation (or '--' for a null-move).

Throws:

If the move notation cannot be parsed.

Type
module:exception.InvalidNotation
Returns:
Node -

A new node, pointing at the new position.

position() → {Position}

Chess position obtained after the current move.

Returns:
Position

positionBefore() → {Position}

Chess position before the current move.

Returns:
Position

previous()nullable {Node}

Return the Node that comes before the current one in their parent variation.

Returns:
Node -

undefined if the current node is the first one of the variation.

promoteVariation(variationIndex)

Replace the move on the current node (and the following ones, if any) by the moves of the variation corresponding to the given index, and create a new variation with the move on the current node and its successors.

WARNING: the promoted variation must NOT be empty.

Parameters:
Name Type Description
variationIndex number

Index of the variation to promote (must be such that 0 <= variationIndex < thisNode.variations().length). If the corresponding variation is empty, an exception is thrown.

removeFollowingMoves()

Erase all the moves after the one on the current Node: after that, Node#next returns undefined. If the current Node is already the last one in its variation (i.e. if Node#next returns undefined already), nothing happens.

removeNag(nag)

Remove the given NAG from the current move.

Parameters:
Name Type Description
nag number

removeVariation(variationIndex)

Remove the variation corresponding to the given index.

Parameters:
Name Type Description
variationIndex number

Index of the variation to promote (must be such that 0 <= variationIndex < thisNode.variations().length).

swapVariations(variationIndex1, variationIndex2)

Change the order of the variations by swapping the two variations corresponding to the given indexes.

Parameters:
Name Type Description
variationIndex1 number

Index of one variation to swap (must be such that 0 <= variationIndex1 < thisNode.variations().length).

variationIndex2 number

Index of the other variation to swap (must be such that 0 <= variationIndex2 < thisNode.variations().length).

tag(tagKey)nullable {string}

Get the value associated to the given tag key on the current move.

Parameters:
Name Type Description
tagKey string
Returns:
string -

undefined if no value is associated to this tag key on the current move.

tag(tagKey, valuenullable)

Set the value associated to the given tag key on the current move.

Parameters:
Name Type Attributes Description
tagKey string
value string <nullable>

tags() → {Array.<string>}

Return the keys of the tags associated to the current move.

Returns:
Array.<string> -

Sorted array.

variations() → {Array.<Variation>}

Return the variations that can be followed instead of the current move.

Returns:
Array.<Variation>