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

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

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

nags() → {Array.<number>}

Return the NAGs associated to the current variation.

Returns:
Array.<number> -

Sorted array.

nodes() → {Array.<Node>}

Generate the nodes corresponding to the moves of the current variation.

Returns:
Array.<Node> -

An empty array is returned if the variation is empty.

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.