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.
185 lines (184 loc) • 6.82 kB
TypeScript
import { GobanEngine } from "./GobanEngine";
import { BoardState } from "./BoardState";
import { AdHocPackedMove } from "./formats/AdHocFormat";
import { JGOFMove, JGOFNumericPlayerColor, JGOFPlayerSummary } from "./formats/JGOF";
export interface MarkInterface {
triangle?: boolean;
square?: boolean;
circle?: boolean;
cross?: boolean;
blue_move?: boolean;
letter?: string;
subscript?: string;
transient_letter?: string;
score?: string;
chat_triangle?: boolean;
sub_triangle?: boolean;
remove?: boolean;
stone_removed?: boolean;
mark_x?: boolean;
hint?: boolean;
black?: boolean;
white?: boolean;
color?: string;
needs_sealing?: boolean;
[label: string]: string | boolean | undefined;
}
export type MoveTreePenMarks = Array<{
color: string;
points: Array<number>;
}>;
export interface MoveTreeJson {
x: number;
y: number;
pen_marks?: MoveTreePenMarks;
marks?: Array<{
x: number;
y: number;
marks: MarkInterface;
}>;
text?: string;
trunk_next?: MoveTreeJson;
branches?: Array<MoveTreeJson>;
correct_answer?: boolean;
wrong_answer?: boolean;
}
export interface MoveTreeChatLineBody {
type: "analysis";
name: string;
from: number;
moves: AdHocPackedMove | string;
}
export interface MoveTreeChatLine {
username: string;
body: MoveTreeChatLineBody;
}
interface BoardStateWithIsobranchHash extends BoardState {
/**
* The isobranch hash is a hash of the board state. This field is used by
* the move tree to detect isomorphic branches. This field is populated
* when recomputeIsoBranches is called.
* */
isobranch_hash?: string;
}
export declare class MoveTree {
static readonly stone_radius = 11;
static readonly stone_padding = 3;
static readonly stone_square_size: number;
label: string;
move_number: number;
readonly pretty_coordinates: string;
parent: MoveTree | null;
readonly id: number;
trunk_next?: MoveTree;
branches: Array<MoveTree>;
correct_answer: boolean;
wrong_answer: boolean;
private hint_next?;
player: JGOFNumericPlayerColor;
line_color: number;
trunk: boolean;
text: string;
private readonly engine;
x: number;
y: number;
edited: boolean;
state: BoardStateWithIsobranchHash;
pen_marks: MoveTreePenMarks;
player_update: JGOFPlayerSummary | undefined;
played_by: number | undefined;
active_path_number: number;
layout_cx: number;
layout_cy: number;
layout_x: number;
layout_y: number;
label_metrics?: any;
private chat_log?;
private marks?;
private stashed_marks;
isobranches: any;
private isobranch_hash?;
constructor(engine: GobanEngine, trunk: boolean, x: number, y: number, edited: boolean, player: JGOFNumericPlayerColor, move_number: number, parent: MoveTree | null, state: BoardState);
/** Serializes our MoveTree into a MoveTreeJson object */
toJson(): MoveTreeJson;
/** Loads the state of this MoveTree node from a MoveTreeJson object */
loadJsonForThisNode(json: MoveTreeJson): void;
/** Recomputes the isobranches for the entire tree. This needs to be called on the root node. */
recomputeIsobranches(): void;
lookupMove(x: number, y: number, player: number, edited: boolean): MoveTree | null;
move(x: number, y: number, trunk: boolean, edited: boolean, player: JGOFNumericPlayerColor, move_number: number, state: any): MoveTree;
traverse(fn: (node: MoveTree) => void): void;
fold<T>(acc: T, plus: (acc: T, node: MoveTree) => T): T;
size(): number;
next(dont_follow_hints?: boolean): MoveTree | null;
prev(): MoveTree | null;
index(idx: number): MoveTree;
is(other?: MoveTree): boolean;
hasTheSameRootMoveAs(other: MoveTree): boolean;
findChildWhich(predicate: (node: MoveTree) => boolean): MoveTree | null;
containsOtherTreeAsSubset(other: MoveTree): boolean;
containsOtherTreeAsChild(other: MoveTree): boolean;
hasAllChildrenOf(other: MoveTree): boolean;
remove(): MoveTree;
getRoot(): MoveTree;
removeIfNoChildren(): void;
getChatLog(): any[];
getAllMarks(): MarkInterface[][];
setAllMarks(marks: MarkInterface[][]): void;
clearMarks(): MarkInterface[][];
/** Saves the current marks in our stash, restore them with popMarks */
stashMarks(): void;
/** Restores previously stashed marks */
popStashedMarks(): void;
/** Returns true if there are any marks that have been set */
hasMarks(): boolean;
/** Calls a callback for each positions that has a mark on it */
foreachMarkedPosition(fn: (i: number, j: number) => void): void;
isAncestorOf(other: MoveTree | null): boolean;
passed(): boolean;
debug(depth: number): string;
toSGF(): string;
get stoneColor(): "black" | "white" | "empty";
toJGOFMove(): JGOFMove;
getBranchPoint(): MoveTree;
getMoveIndex(): number;
getDistance(node: MoveTree): number;
getMoveNumberDifferenceFromTrunk(): number;
getMarks(x: number, y: number): MarkInterface;
setActivePath(path_number: number): void;
getMoveStringToThisPoint(): string;
/**** Layout & Rendering ****/
static active_path_number: number;
static current_line_color: number;
static line_colors: Array<string>;
static isobranch_colors: {
strong: string;
weak: string;
};
layout(x: number, min_y: number, layout_hash: {
[coords: string]: MoveTree;
}, line_color: number): number;
getNodeAtLayoutPosition(layout_x: number, layout_y: number): MoveTree | null;
findStrongIsobranches(): Array<MoveTree>;
nextSibling(): MoveTree | null;
prevSibling(): MoveTree | null;
getPositionInParent(): number;
private isBranchWithCorrectAnswer;
private isBranchWithWrongAnswer;
hoistFirstBranchToTrunk(): void;
/**
* Find branches containing node with correct_answer === true
*/
findBranchesWithCorrectAnswer(): Array<MoveTree>;
/**
* Find branches containing node with wrong_answer === true
*/
findBranchesWithWrongAnswer(): Array<MoveTree>;
clearBranchesExceptFor(node: MoveTree): void;
static markupSGFChatMessage(message: MoveTreeChatLineBody | string, width: number, height: number): string;
static fmtUsername(username: string): string;
static escapedSGFChat(username: string, message: MoveTreeChatLineBody | string, width: number, height: number): string;
static markupSGFChat(username: string, message: MoveTreeChatLineBody | string, width: number, height: number): string;
static markupSGFChatWithoutNode(username: string, message: MoveTreeChatLineBody | string, width: number, height: number): string;
}
export {};