Game()

Chess game, with the move history, the position at each step of the game, the comments and annotations (if any), the result of the game, and some meta-data such as the name of the players, the date of the game, the name of the tournament, etc...

new Game()

Methods

annotator()nullable {string}

Get the name of the annotator.

Returns:
string

annotator(valuenullable)

Set the name of the annotator.

Parameters:
Name Type Attributes Description
value * <nullable>

If null or undefined, the existing value (if any) is erased.

ascii() → {string}

Return a human-readable string representing the game. This string is multi-line, and is intended to be displayed in a fixed-width font (similarly to an ASCII-art picture).

Returns:
string

date() → {Date|Object|Object|undefined}

Get the date of the game.

Returns:
Date | Object | Object | undefined -

Depending on what is defined, the method returns the whole date, or just the year and the month, or just the year, or undefined.

date(value)

Set the date of the game.

Parameters:
Name Type Description
value Date | Object | Object | undefined

dateAsString(localesnullable)nullable {string}

Get the date of the game as a human-readable string (e.g. 'November 1955', 'September 4, 2021').

Parameters:
Name Type Attributes Description
locales * <nullable>

Locales to use to generate the result. If undefined, the default locale of the execution environment is used. See Intl documentation for more details.

Returns:
string

event()nullable {string}

Get the event.

Returns:
string

event(valuenullable)

Set the event.

Parameters:
Name Type Attributes Description
value * <nullable>

If null or undefined, the existing value (if any) is erased.

initialPosition() → {Position}

Get the initial position of the game.

Returns:
Position

initialPosition(initialPosition, fullMoveNumberopt)

Set the initial position of the game.

WARNING: this resets the main variation.

Parameters:
Name Type Attributes Default Description
initialPosition Position
fullMoveNumber number <optional>
1

mainVariation() → {Variation}

The main variation of the game.

Returns:
Variation

playerElo(color)nullable {string}

Get the player elo.

Parameters:
Name Type Description
color Color
Returns:
string

playerElo(color, valuenullable)

Set the player elo.

Parameters:
Name Type Attributes Description
color Color
value * <nullable>

If null or undefined, the existing value (if any) is erased.

playerName(color)nullable {string}

Get the player name.

Parameters:
Name Type Description
color Color
Returns:
string

playerName(color, valuenullable)

Set the player name.

Parameters:
Name Type Attributes Description
color Color
value * <nullable>

If null or undefined, the existing value (if any) is erased.

playerTitle(color)nullable {string}

Get the player title.

Parameters:
Name Type Description
color Color
Returns:
string

playerTitle(color, valuenullable)

Set the player title.

Parameters:
Name Type Attributes Description
color Color
value * <nullable>

If null or undefined, the existing value (if any) is erased.

result() → {GameResult}

Get the result of the game.

Returns:
GameResult

result(value)

Set the result of the game.

Parameters:
Name Type Description
value GameResult

round()nullable {string}

Get the round.

Returns:
string

round(valuenullable)

Set the round.

Parameters:
Name Type Attributes Description
value * <nullable>

If null or undefined, the existing value (if any) is erased.

site()nullable {string}

Get where the game takes place.

Returns:
string

site(valuenullable)

Set where the game takes place.

Parameters:
Name Type Attributes Description
value * <nullable>

If null or undefined, the existing value (if any) is erased.

variant() → {GameVariant}

Get the GameVariant of the game.

Returns:
GameVariant