UNPKG

kokopu

Version:

A JavaScript/TypeScript library implementing the chess game rules and providing tools to read/write the standard chess file formats.

150 lines (149 loc) 5.9 kB
/*! * -------------------------------------------------------------------------- * * * * Kokopu - A JavaScript/TypeScript chess library. * * <https://www.npmjs.com/package/kokopu> * * Copyright (C) 2018-2026 Yoann Le Montagner <yo35 -at- melix.net> * * * * Kokopu is free software: you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public License * * as published by the Free Software Foundation, either version 3 of * * the License, or (at your option) any later version. * * * * Kokopu is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General * * Public License along with this program. If not, see * * <http://www.gnu.org/licenses/>. * * * * -------------------------------------------------------------------------- */ import { Color } from '../base_types'; import { GamePOJO } from '../game_pojo'; import { MoveDescriptor } from '../move_descriptor'; import { Node, Variation } from '../node_variation'; import { Position } from '../position'; import { POJOExceptionBuilder } from './pojo_util'; /** * Container for the data at the root of the `NodeData` / `VariationData` tree. */ export declare class MoveTreeRoot { _position: Position; _fullMoveNumber: number; _mainVariationData: VariationData; constructor(); clearTree(): void; mainVariation(): VariationImpl; findById(id: string, allowAliases: boolean): VariationImpl | NodeImpl | undefined; getPojo(pojo: GamePOJO): void; setPojo(pojo: Partial<Record<string, unknown>>, exceptionBuilder: POJOExceptionBuilder): void; } /** * Attributes shared between `NodeData` and `VariationData`. */ interface AbstractNodeData { nags: Set<number>; tags: Map<string, string>; comment?: string; isLongComment: boolean; } /** * Internal structure representing a `Node`. */ interface NodeData extends AbstractNodeData { parentVariation: VariationData; child?: NodeData; variations: VariationData[]; moveColor: Color; fiftyMoveClock: number; fullMoveNumber: number; moveDescriptor: MoveDescriptor | null; notation: string | null; } /** * Internal structure representing a `Variation`. */ interface VariationData extends AbstractNodeData { parent: NodeData | MoveTreeRoot; child?: NodeData; isLongVariation: boolean; } /** * Implementation class for `Node`. */ declare class NodeImpl extends Node { private _data; private _positionBefore; constructor(data: NodeData, positionBefore: Position); id(): string; followingId(distance: number): string; nags(): number[]; hasNag(nag: number): boolean; addNag(nag: number): Set<number>; removeNag(nag: number): boolean; clearNags(): void; filterNags(filter: (nag: number) => boolean): void; tags(): string[]; tag(tagKey: string, value?: string | undefined): string | undefined; clearTags(): void; filterTags(filter: (tagKey: string, tagValue: string) => boolean): void; comment(value?: string | undefined, isLongComment?: boolean): string | undefined; isLongComment(): boolean; parentVariation(): VariationImpl; previous(): NodeImpl | undefined; next(): NodeImpl | undefined; notation(): string; figurineNotation(): string; positionBefore(): Position; position(): Position; fen(): string; fiftyMoveClock(): number; fullMoveNumber(): number; moveColor(): Color; variations(): Variation[]; play(move: string): NodeImpl; removePrecedingMoves(): void; removeFollowingMoves(): void; addVariation(longVariation?: boolean): VariationImpl; removeVariation(variationIndex: number): void; swapVariations(variationIndex1: number, variationIndex2: number): void; promoteVariation(variationIndex: number): void; } /** * Implementation class for `Variation`. */ declare class VariationImpl extends Variation { private _data; private _initialPosition; constructor(data: VariationData, initialPosition: Position); id(): string; followingId(distance: number): string; nags(): number[]; hasNag(nag: number): boolean; addNag(nag: number): Set<number>; removeNag(nag: number): boolean; clearNags(): void; filterNags(filter: (nag: number) => boolean): void; tags(): string[]; tag(tagKey: string, value?: string | undefined): string | undefined; clearTags(): void; filterTags(filter: (tagKey: string, tagValue: string) => boolean): void; comment(value?: string | undefined, isLongComment?: boolean): string | undefined; isLongComment(): boolean; parentNode(): NodeImpl | undefined; first(): NodeImpl | undefined; nodes(): Node[]; plyCount(): number; isLongVariation(): boolean; initialPosition(): Position; initialFEN(): string; initialFiftyMoveClock(): number; initialFullMoveNumber(): number; finalPosition(): Position; finalFEN(): string; play(move: string): NodeImpl; clearMoves(): void; } export {};