goban-engine
Version:
This contains the built Go engine that is used by the Goban package. There are no display components in this package, only the logic for playing the game of Go, making it suitable for usage in node.js or other server-side environments.
252 lines (251 loc) • 11.7 kB
TypeScript
import { GobanEngine, GobanEnginePhase, ReviewMessage, PuzzlePlacementSetting, Score, ConditionalMoveTree } from "../engine";
import { NumberMatrix } from "../engine/util";
import { MoveTree, MarkInterface } from "../engine/MoveTree";
import { ScoreEstimator } from "../engine/ScoreEstimator";
import { niceInterval } from "../engine/util";
import { JGOFIntersection, JGOFPlayerClock, JGOFNumericPlayerColor } from "../engine/formats/JGOF";
import { AdHocClock, AdHocPauseControl } from "../engine/formats/AdHocFormat";
import { StallingScoreEstimate } from "../engine/protocol";
import { GobanBase, AnalysisTool, AnalysisSubTool, GobanModes, GobanChatLog, GobanBounds, GobanConfig, JGOFClockWithTransmitting } from "../GobanBase";
export declare const SCORE_ESTIMATION_TRIALS = 1000;
export declare const SCORE_ESTIMATION_TOLERANCE = 0.3;
export declare const MARK_TYPES: Array<keyof MarkInterface>;
export interface ColoredCircle {
move: JGOFIntersection;
color: string;
border_width?: number;
border_color?: string;
}
export interface MoveCommand {
game_id: number;
move: string;
blur?: number;
clock?: JGOFPlayerClock;
}
/**
* This class serves as a functionality layer encapsulating core interactions
* we do with a Goban, we have it as a separate base class simply to help with
* code organization and to keep our Goban class size down.
*/
export declare abstract class GobanInteractive extends GobanBase {
abstract sendTimedOut(): void;
abstract sent_timed_out_message: boolean;
protected abstract sendMove(mv: MoveCommand, cb?: () => void): boolean;
conditional_starting_color: "black" | "white" | "invalid";
conditional_tree: ConditionalMoveTree;
double_click_submit: boolean;
variation_stone_opacity: number;
draw_bottom_labels: boolean;
draw_left_labels: boolean;
draw_right_labels: boolean;
draw_top_labels: boolean;
height: number;
last_clock?: AdHocClock;
last_emitted_clock?: JGOFClockWithTransmitting;
clock_should_be_paused_for_move_submission: boolean;
previous_mode: string;
one_click_submit: boolean;
pen_marks: Array<any>;
readonly game_id: number;
readonly review_id: number;
showing_scores: boolean;
stalling_score_estimate?: StallingScoreEstimate;
width: number;
pause_control?: AdHocPauseControl;
paused_since?: number;
chat_log: GobanChatLog;
protected last_paused_state: boolean | null;
protected last_paused_by_player_state: boolean | null;
protected analysis_removal_state?: boolean;
protected analysis_removal_last_position: {
i: number;
j: number;
};
protected marked_analysis_score?: boolean[][];
private _mode;
get mode(): GobanModes;
set mode(mode: GobanModes);
private _title;
get title(): string;
set title(title: string);
private _submit_move?;
get submit_move(): (() => void) | undefined;
set submit_move(submit_move: (() => void) | undefined);
private _analyze_tool;
get analyze_tool(): AnalysisTool;
set analyze_tool(analyze_tool: AnalysisTool);
private _analyze_subtool;
get analyze_subtool(): AnalysisSubTool;
set analyze_subtool(analyze_subtool: AnalysisSubTool);
private _score_estimator;
get score_estimator(): ScoreEstimator | null;
set score_estimator(score_estimate: ScoreEstimator | null);
private _review_owner_id?;
get review_owner_id(): number | undefined;
set review_owner_id(review_owner_id: number | undefined);
private _review_controller_id?;
get review_controller_id(): number | undefined;
set review_controller_id(review_controller_id: number | undefined);
config: GobanConfig;
last_move_radius: number;
circle_radius: number;
square_size: number;
stone_font_scale: number;
protected __board_redraw_pen_layer_timer: any;
protected __clock_timer?: ReturnType<typeof setTimeout>;
protected __draw_state: string[][];
protected __last_pt: {
i: number;
j: number;
valid: boolean;
};
protected __update_move_tree: any;
protected analysis_move_counter: number;
protected stone_removal_auto_scoring_done?: boolean;
protected bounded_height: number;
protected bounded_width: number;
protected bounds: GobanBounds;
protected conditional_path: string;
protected current_cmove?: ConditionalMoveTree;
protected currently_my_cmove: boolean;
protected dirty_redraw: any;
protected disconnectedFromGame: boolean;
protected display_width?: number;
protected done_loading_review: boolean;
protected dont_draw_last_move: boolean;
protected edit_color?: "black" | "white";
protected errorHandler: (e: Error) => void;
protected heatmap?: NumberMatrix;
protected colored_circles?: Array<Array<ColoredCircle | undefined>>;
protected game_type: string;
protected getPuzzlePlacementSetting?: () => PuzzlePlacementSetting;
protected highlight_movetree_moves: boolean;
protected interactive: boolean;
protected isInPushedAnalysis: () => boolean;
protected leavePushedAnalysis: () => void;
protected isPlayerController: () => boolean;
protected isPlayerOwner: () => boolean;
protected label_character: string;
protected label_mark: string;
protected last_hover_square?: JGOFIntersection;
protected last_move?: MoveTree;
protected last_phase?: GobanEnginePhase;
protected last_review_message: ReviewMessage;
protected last_sound_played_for_a_stone_placement?: string;
protected last_stone_sound: number;
protected move_selected?: JGOFIntersection;
protected no_display: boolean;
protected onError?: (error: Error) => void;
protected on_game_screen: boolean;
protected original_square_size: number | ((goban: GobanBase) => number) | "auto";
protected player_id: number;
protected puzzle_autoplace_delay: number;
protected restrict_moves_to_movetree: boolean;
protected review_had_gamedata: boolean;
protected scoring_mode: boolean | "stalling-scoring-mode";
protected shift_key_is_down: boolean;
protected show_variation_move_numbers: boolean;
protected stone_placement_enabled: boolean;
protected sendLatencyTimer?: ReturnType<typeof niceInterval>;
protected abstract setTitle(title: string): void;
protected abstract enableDrawing(): void;
protected abstract disableDrawing(): void;
protected preloaded_data?: GobanConfig;
constructor(config: GobanConfig, preloaded_data?: GobanConfig);
/** Goban calls some abstract methods as part of the construction
* process. Because our subclasses might (and do) need to do some of their
* own config before these are called, we set this function to be called
* by our subclass after it's done it's own internal config stuff.
*/
protected post_config_constructor(): GobanEngine;
protected getCoordinateDisplaySystem(): "A1" | "1-1";
protected getShowUndoRequestIndicator(): boolean;
protected getShowVariationMoveNumbers(): boolean;
protected getStoneFontScale(): number;
static getMoveTreeNumbering(): string;
static getCDNReleaseBase(): string;
static getSoundEnabled(): boolean;
static getSoundVolume(): number;
protected defaultConfig(): any;
isAnalysisDisabled(perGameSettingAppliesToNonPlayers?: boolean): boolean;
protected getLocation(): string;
destroy(): void;
protected scheduleRedrawPenLayer(): void;
protected getWidthForSquareSize(square_size: number): number;
protected xy2ij(x: number, y: number, anti_slip?: boolean): {
i: number;
j: number;
valid: boolean;
};
setAnalyzeTool(tool: AnalysisTool, subtool: AnalysisSubTool | undefined | null): void;
protected setSubmit(fn?: () => void): void;
markDirty(): void;
set(x: number, y: number, player: JGOFNumericPlayerColor): void;
protected updateMoveTree(): void;
protected updateOrRedrawMoveTree(): void;
setBounds(bounds: GobanBounds): void;
load(config: GobanConfig): GobanEngine;
setForRemoval(x: number, y: number, removed: boolean, emit_stone_removal_updated?: boolean): void;
showScores(score: Score, only_show_territory?: boolean): void;
hideScores(): void;
showStallingScoreEstimate(sse: StallingScoreEstimate): void;
updatePlayerToMoveTitle(): void;
disableStonePlacement(): void;
enableStonePlacement(): void;
showFirst(dont_update_display?: boolean): void;
showPrevious(dont_update_display?: boolean): void;
showNext(dont_update_display?: boolean): void;
prevSibling(): void;
nextSibling(): void;
jumpToLastOfficialMove(): void;
protected setLastOfficialMove(): void;
protected isLastOfficialMove(): boolean;
updateTitleAndStonePlacement(): void;
setConditionalTree(conditional_tree?: ConditionalMoveTree): void;
followConditionalPath(move_path: string): void;
protected followConditionalSegment(x: number, y: number): void;
private deleteConditionalSegment;
deleteConditionalPath(move_path: string): void;
getCurrentConditionalPath(): string;
setToPreviousMode(dont_jump_to_official_move?: boolean): boolean;
setModeDeferred(mode: GobanModes): void;
setMode(mode: GobanModes, dont_jump_to_official_move?: boolean): boolean;
setEditColor(color: "black" | "white"): void;
protected playMovementSound(): void;
/** This is a callback that gets called by GobanEngine.getState to save and
* board state as it pushes and pops state. Our renderers can override this
* to save state they need. */
setMarks(marks: {
[mark: string]: string;
}, dont_draw?: boolean): void;
setHeatmap(heatmap?: NumberMatrix, dont_draw?: boolean): void;
setColoredCircles(circles?: Array<ColoredCircle>, dont_draw?: boolean): void;
setColoredMarks(colored_marks: {
[key: string]: {
move: string;
color: string;
};
}): void;
protected setMarkColor(x: number, y: number, color: string): void;
protected setLetterMark(x: number, y: number, mark: string, drawSquare?: boolean): void;
setSubscriptMark(x: number, y: number, mark: string, drawSquare?: boolean): void;
setCustomMark(x: number, y: number, mark: string, drawSquare?: boolean): void;
deleteCustomMark(x: number, y: number, mark: string, drawSquare?: boolean): void;
editPlaceByPrettyCoordinates(coordinates: string, color: JGOFNumericPlayerColor, isTrunkMove?: boolean): void;
placeByPrettyCoordinates(coordinates: string): void;
setMarkByPrettyCoordinates(coordinates: string, mark: number | string, dont_draw?: boolean): void;
setMark(x: number, y: number, mark: number | string, dont_draw?: boolean): void;
protected setTransientMark(x: number, y: number, mark: number | string, dont_draw?: boolean): void;
getMarks(x: number, y: number): MarkInterface;
protected toggleMark(x: number, y: number, mark: number | string, force_label?: boolean, force_put?: boolean): boolean;
protected incrementLabelCharacter(): void;
protected setLabelCharacterFromMarks(set_override?: "numbers" | "letters"): void;
setLabelCharacter(ch: string): void;
clearMark(x: number, y: number, mark: string | number): void;
protected clearTransientMark(x: number, y: number, mark: string | number): void;
updateScoreEstimation(): void;
isCurrentUserAPlayer(): boolean;
setScoringMode(tf: boolean, prefer_remote?: boolean): MoveTree;
private last_emitted_captured_stones;
debouncedEmitCapturedStones(removed_stones: Array<JGOFIntersection>): void;
}