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

Constructors

Methods

  • Get the name of the annotator.

    Returns undefined | string

  • Set the name of the annotator.

    Parameters

    • value: undefined | string

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

    Returns void

  • 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

  • Clear all the headers (player names, elos, titles, event name, date, etc...).

    The Game.result header is reseted to its default value. The initial position and moves are not modified.

    Returns void

  • Get the date of the game.

    Returns undefined | DateValue

  • Set the date of the game.

    Parameters

    • value: undefined | Date | DateValue

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

    Returns void

  • Set the date of the game.

    If the month and/or the day of month are missing, the date of the game will be partially defined (see DateValue for more details regarding partially defined dates).

    Parameters

    • year: number
    • Optionalmonth: number
    • Optionalday: number

    Returns void

  • Get the date of the game as a standard JavaScript Date object.

    If the day of month is undefined for the current game, the returned Date object points at the first day of the corresponding month. If neither the day of month nor the month are undefined for the current game, the returned Date object points at the first day of the corresponding year.

    Returns undefined | Date

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

    Parameters

    • Optionallocales: string | string[]

      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 undefined | string

  • Get the ECO code.

    Returns undefined | string

  • Set the ECO code.

    Parameters

    • value: undefined | string

      If undefined, the existing value (if any) is erased. Must be a valid ECO code (from 'A00' to 'E99').

    Returns void

  • Get the event.

    Returns undefined | string

  • Set the event.

    Parameters

    • value: undefined | string

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

    Returns void

  • FEN representation of the chess position at the end of the game.

    The fifty-move clock and full-move number are set according to the move history in the string returned by this method.

    Returns string

  • Chess position at the end of the game.

    Returns Position

  • Return the node or variation corresponding to the given ID (see Node.id and Variation.id to retrieve the ID of a node or variation).

    For the main variation, IDs are built as follows:

    • 'start' is the ID of the main variation,
    • '3w' is for instance the ID of the node whose Node.fullMoveNumber is 3 and Node.moveColor is white (i.e. the 3rd white move if the game starts from the usual initial position),
    • 'end' is an alias corresponding to the last node in the main variation (or the main variation itself if it is empty).

    For sub-variations, IDs are built as in the following examples:

    • '2b-v0-start' is the ID of the sub-variation at index 0 on node '2b' (in the main variation),
    • '5w-v3-11b' is the ID of the node whose Node.fullMoveNumber is 11 and Node.moveColor is black within the sub-variation at index 3 on node '5w' (in the main variation),
    • '5w-v3-end' is an alias corresponding to the last node in this sub-variation (or the sub-variation itself if it is empty).

    Parameters

    • id: string
    • allowAliases: boolean = true

      If true, search id among both IDs and ID aliases. If false, search among IDs only.

    Returns undefined | Node | Variation

    undefined if the given ID does not correspond to an existing Node and Variation.

  • Get the round, sub-round and sub-sub-round as a human-readable string, the 3 components being separated by dot characters.

    Returns undefined | string

  • FEN representation of the chess position at the beginning of the game.

    The fifty-move clock and full-move number are set according to the move history in the string returned by this method.

    Returns string

  • Full-move number at which the game starts.

    Returns number

  • Get the initial position of the game.

    Returns Position

  • Set the initial position of the game.

    Parameters

    • initialPosition: Position
    • OptionalfullMoveNumber: number

      1 by default

    Returns void

  • Return the nodes corresponding to the moves of the main variation.

    Parameters

    • withSubVariations: boolean = false

      If true, the nodes of the sub-variations are also included in the result.

    Returns Node[]

  • Get the name of the opening.

    Returns undefined | string

  • Set the name of the opening.

    Parameters

    • value: undefined | string

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

    Returns void

  • Get the name of the opening sub-variation.

    Returns undefined | string

  • Set the name of the opening sub-variation.

    Parameters

    • value: undefined | string

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

    Returns void

  • Get the name of the opening variation.

    Returns undefined | string

  • Set the name of the opening variation.

    Parameters

    • value: undefined | string

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

    Returns void

  • Get the elo of the player corresponding to the given color.

    If defined, the returned value is guaranteed to be an integer >= 0.

    Parameters

    Returns undefined | number

  • Set the elo of the player corresponding to the given color.

    Parameters

    • color: Color
    • value: undefined | number

      If undefined, the existing value (if any) is erased. Must be an integer >= 0.

    Returns void

  • Get the name of the player corresponding to the given color.

    Parameters

    Returns undefined | string

  • Set the name of the player corresponding to the given color.

    Parameters

    • color: Color
    • value: undefined | string

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

    Returns void

  • Get the title of the player corresponding to the given color.

    Parameters

    Returns undefined | string

  • Set the title of the player corresponding to the given color.

    Parameters

    • color: Color
    • value: undefined | string

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

    Returns void

  • Number of half-moves in the main variation.

    For instance, after 1.e4 e5 2.Nf3, the number of half-moves if 3 (2 white moves + 1 black move).

    Returns number

  • Return the POJO representation of the current Game. To be used for JSON serialization, deep cloning, etc...

    Returns GamePOJO

  • Get the result of the game.

    Returns GameResult

  • Set the result of the game.

    Parameters

    Returns void

  • Get the round.

    Returns undefined | number

  • Set the round.

    Parameters

    • value: undefined | number

      If undefined, the existing value (if any) is erased. Must be an integer >= 0.

    Returns void

  • Get where the game takes place.

    Returns undefined | string

  • Set where the game takes place.

    Parameters

    • value: undefined | string

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

    Returns void

  • Get the sub-round.

    Returns undefined | number

  • Set the sub-round.

    Parameters

    • value: undefined | number

      If undefined, the existing value (if any) is erased. Must be an integer >= 0.

    Returns void

  • Get the sub-sub-round.

    Returns undefined | number

  • Set the sub-sub-round.

    Parameters

    • value: undefined | number

      If undefined, the existing value (if any) is erased. Must be an integer >= 0.

    Returns void

  • Get the reason of the conclusion of the game. Examples of possible values:

    • 'normal': game terminated in a normal fashion,
    • 'time forfeit': loss due to losing player's failure to meet time control requirements,
    • 'adjudication': result due to third party adjudication process,
    • 'death': losing player called to greater things, one hopes,
    • 'emergency': game concluded due to unforeseen circumstances,
    • etc...

    This list is not exhaustive and any string is valid value for this field.

    Returns undefined | string

  • Set the name of the opening sub-variation.

    Parameters

    • value: undefined | string

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

    Returns void

  • Decode the POJO passed in argument, assuming it follows the schema defined by GamePOJO.

    Parameters

    • pojo: unknown

    Returns Game

    exception.InvalidPOJO if the given object cannot be decoded, either because it does not follow the schema defined by GamePOJO, or because it would result in an inconsistent game (e.g. if it contains some invalid moves).