UNPKG

goban

Version:

[![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/online-go/goban)

96 lines (95 loc) 3.83 kB
import { GobanEvents } from "../GobanBase"; import { EventEmitter } from "eventemitter3"; import { JGOFIntersection, JGOFNumericPlayerColor } from "./formats/JGOF"; import type { GobanBase } from "../GobanBase"; import { RawStoneString } from "./StoneString"; export interface BoardConfig { width?: number; height?: number; board?: JGOFNumericPlayerColor[][]; removal?: boolean[][]; player?: JGOFNumericPlayerColor; board_is_repeating?: boolean; white_prisoners?: number; black_prisoners?: number; isobranch_hash?: string; } export interface ScoringLocations { black: { territory: number; stones: number; locations: JGOFIntersection[]; }; white: { territory: number; stones: number; locations: JGOFIntersection[]; }; } export declare class BoardState extends EventEmitter<GobanEvents> implements BoardConfig { readonly height: number; readonly width: number; board: JGOFNumericPlayerColor[][]; removal: boolean[][]; protected goban_callback?: GobanBase; player: JGOFNumericPlayerColor; board_is_repeating: boolean; white_prisoners: number; black_prisoners: number; /** * Constructs a new board with the given configuration. If height/width * are not provided, they will be inferred from the board array, or will * default to 19x19 if no board is provided. * * Any state matrices (board, removal, etc..) provided will be cloned * and must have the same dimensionality. */ constructor(config: BoardConfig, goban_callback?: GobanBase); /** Clone the entire BoardState */ cloneBoardState(): BoardState; /** Returns a clone of .board */ cloneBoard(): JGOFNumericPlayerColor[][]; /** * Toggles a group of stones for removal or restoration. * * By default, if we are marking a group for removal but the group is * almost certainly alive (two eyes, etc), this will result in a no-op, * unless force_removal is set to true. */ toggleSingleGroupRemoval(x: number, y: number, force_removal?: boolean): { removed: boolean; group: RawStoneString; }; /** Sets a position as being removed or not removed. If * `emit_stone_removal_updated` is set to false, the * "stone-removal.updated" event will not be emitted, and it is up to the * caller to emit this event appropriately. */ setRemoved(x: number, y: number, removed: boolean, emit_stone_removal_updated?: boolean): void; /** Clear all stone removals */ clearRemoved(): void; /** * Returns an array of groups connected to the given group. This is a bit * faster than using StoneGroupBuilder because we only compute the values * we need. */ getNeighboringRawStoneStrings(raw_stone_string: RawStoneString): RawStoneString[]; /** Returns an array of x/y pairs of all the same color */ getRawStoneString(x: number, y: number, clearMarks: boolean): RawStoneString; private _floodFillMarkFilled; countLiberties(raw_stone_string: RawStoneString): number; /** * Compute the liberty map for the current board. * This is used by kidsgo */ computeLibertyMap(): Array<Array<number>>; foreachNeighbor(pt_or_raw_stone_string: JGOFIntersection | RawStoneString, callback: (x: number, y: number) => void): void; /** Returns true if the `.board` field from the other board is equal to this one */ boardEquals(other: BoardState): boolean; /** * Computes scoring locations for the board. If `area_scoring` is true, we * will use area scoring rules, otherwise we will use territory scoring rules * (which implies omitting territory in seki). */ computeScoringLocations(area_scoring: boolean): ScoringLocations; }