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)

97 lines (96 loc) 4.28 kB
import { NumberMatrix } from "./util"; import { StoneString } from "./StoneString"; import type { GobanBase } from "../GobanBase"; import { GobanEngine, PlayerScore, GobanEngineRules } from "./GobanEngine"; import { JGOFMove, JGOFNumericPlayerColor, JGOFSealingIntersection } from "./formats/JGOF"; import { BoardState } from "./BoardState"; export interface ScoreEstimateRequest { player_to_move: "black" | "white"; width: number; height: number; board_state: JGOFNumericPlayerColor[][]; rules: GobanEngineRules; black_prisoners?: number; white_prisoners?: number; komi?: number; jwt: string; /** Whether to run autoscoring logic. If true, player_to_move is * essentially ignored as we compute estimates with each player moving * first in turn. */ autoscore?: boolean; } export interface ScoreEstimateResponse { /** Matrix of ownership estimates ranged from -1 (white) to 1 (black) */ ownership: number[][]; /** Estimated score */ score?: number; /** Estimated win rate */ win_rate?: number; /** Board state after autoscoring logic has been run. Only defined if autoscore was true in the request. */ autoscored_board_state?: JGOFNumericPlayerColor[][]; /** Intersections that are dead or dame. Only defined if autoscore was true in the request. */ autoscored_removed?: JGOFMove[]; /** Coordinates that still need sealing */ autoscored_needs_sealing?: JGOFSealingIntersection[]; } /** * The interface that local estimators should follow. * * @param board representation of the board with any dead stones already * removed (black = 1, empty = 0, white = -1) * @param color_to_move the player whose turn it is * @param trials number of playouts. Not applicable to all estimators, but * higher generally means higher accuracy and higher compute cost * @param tolerance (0.0-1.0) confidence required to mark an intersection not neutral. */ type LocalEstimator = (board: number[][], color_to_move: "black" | "white", trials: number, tolerance: number) => NumberMatrix; export declare function set_local_ownership_estimator(estimator: LocalEstimator): void; export declare class ScoreEstimator extends BoardState { white: PlayerScore; black: PlayerScore; engine: GobanEngine; private groups; tolerance: number; amount: number; ownership: Array<Array<number>>; territory: Array<Array<number>>; trials: number; winner: string; color_to_move: "black" | "white"; estimated_hard_score: number; when_ready: Promise<void>; prefer_remote: boolean; autoscored_state?: JGOFNumericPlayerColor[][]; autoscored_removed?: JGOFMove[]; autoscore: boolean; autoscored_needs_sealing?: JGOFSealingIntersection[]; constructor(engine: GobanEngine, goban_callback: GobanBase | undefined, trials: number, tolerance: number, prefer_remote?: boolean, autoscore?: boolean, removal?: boolean[][]); estimateScore(trials: number, tolerance: number, autoscore: boolean): Promise<void>; private estimateScoreRemote; private estimateScoreLocal; updateEstimate(estimated_score: number, ownership: Array<Array<number>>, score?: number): void; getProbablyDead(): string; handleClick(i: number, j: number, mod_key: boolean, press_duration_ms: number): void; setRemoved(x: number, y: number, removed: boolean): void; clearRemoved(): void; clearAutoScore(): void; getStoneRemovalString(): string; getGroup(x: number, y: number): StoneString; /** * Computes a rough estimation of ownership and score. */ score(): ScoreEstimator; } /** * Adjust Estimate to account for Ruleset (i.e. territory vs area) and captures * @param engine Go engine is required because the ruleset is taken into account * @param board the current board state * @param area_map Representation of the ownership, 1=Black, -1=White, 0=Undecided * using Area rules * @param score estimated score (not accounting for captures) */ export declare function adjust_estimate(engine: GobanEngine, board: Array<Array<JGOFNumericPlayerColor>>, area_map: number[][], score: number): { score: number; ownership: import("./util").Matrix<number>; }; export {};