Variation()

Represent one variation in the tree structure formed by a chess game, meaning a starting chess position and list of played consecutively from this position.

new Variation()

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

Methods

addNag(nag)

Add the given NAG to the current variation.

Parameters:
Name Type Description
nag number

clearMoves()

Erase all the moves in the current Variation: after that, Variation#first returns undefined. If the current Variation is already empty (i.e. if Variation#first returns undefined already), nothing happens.

comment()nullable {string}

Get the text comment associated to the current variation.

Returns:
string -

undefined if no comment is defined for the variation.

comment(value, isLongCommentopt)

Set the text comment associated to the current variation.

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

first()nullable {Node}

First move of the variation.

Returns:
Node -

undefined if the variation is empty.

hasNag(nag) → {boolean}

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

Parameters:
Name Type Description
nag number
Returns:
boolean

id() → {string}

Identifier of the current variation within its parent Game.

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

Returns:
string

initialFullMoveNumber() → {number}

Full-move number at the beginning of the variation.

Returns:
number

initialPosition() → {Position}

Chess position at the beginning of the variation.

Returns:
Position

isLongComment() → {boolean}

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

Returns:
boolean

isLongVariation() → {boolean}

Whether the current variation is considered as a "long" variation, i.e. a variation that should be displayed in an isolated block.

Returns:
boolean

isVariation() → {boolean}

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

Returns:
boolean

nags() → {Array.<number>}

Return the NAGs associated to the current variation.

Returns:
Array.<number> -

Sorted array.

nodes() → {Array.<Node>}

Return the Node-s corresponding to the moves of the current variation.

Returns:
Array.<Node> -

An empty array is returned if the variation is empty.

parentNode()nullable {Node}

Return the Node to which the current variation is attached.

Returns:
Node -

undefined if the current variation is the main one (see Game#mainVariation).

play(move) → {Node}

Play the given move as the first move of the variation.

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 object, to represents the new move.

removeNag(nag)

Remove the given NAG from the current variation.

Parameters:
Name Type Description
nag number

tag(tagKey)nullable {string}

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

Parameters:
Name Type Description
tagKey string
Returns:
string -

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

tag(tagKey, valuenullable)

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

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

tags() → {Array.<string>}

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

Returns:
Array.<string> -

Sorted array.