UNPKG

svelte4-chess

Version:

Fully playable chess component for Svelte 4. Powered by Chess.js logic, Chessground chessboard and optionally Stockfish chess AI.

77 lines (76 loc) 2.65 kB
import type { Chessground } from "svelte4-chessground"; import type { Square, PieceSymbol, Color, Move as CjsMove } from "chess.js"; export type { Square, PieceSymbol, Color }; import type { Engine } from "./engine.js"; import { type Config } from "chessground/config"; export type Move = CjsMove & { check: boolean; checkmate: boolean; }; export type GameOver = { reason: "checkmate" | "stalemate" | "repetition" | "insufficient material" | "fifty-move rule"; result: 1 | 0 | 0.5; }; export declare class Api { private cg; private stateChangeCallback; private promotionCallback; private moveCallback; private gameOverCallback; private _orientation; private ownColor; private engine; private chessJS; private gameIsOver; private initialised; constructor(cg: Chessground, fen?: string, stateChangeCallback?: (api: Api) => void, // called when the game state (not visuals) changes promotionCallback?: (sq: Square) => Promise<PieceSymbol>, // called before promotion moveCallback?: (move: Move) => void, // called after move gameOverCallback?: (gameOver: GameOver) => void, // called after game-ending move _orientation?: Color, ownColor?: "white" | "black", engine?: Engine | undefined); setOwnColor(color: "white" | "black"): void; init(): Promise<void>; load(fen: string): void; _chessgroundMoveCallback(orig: Square | "a0", dest: Square | "a0"): Promise<void>; private _moveIsPromotion; set(config: Config): void; move(moveSanOrObj: string | { from: string; to: string; promotion?: string; }): void; moveLan(moveLan: string): void; private _postMoveAdmin; playEngineMove(): Promise<void>; private _enginePlaysNextMove; private _updateChessgroundWithPossibleMoves; private _checkForGameOver; possibleMovesDests(): Map<any, any>; reset(): void; undo(): Move | null; toggleOrientation(): void; orientation(): Color; isGameOver(): boolean; fen(): string; turn(): Color; moveNumber(): number; inCheck(): boolean; history(): string[]; history({ verbose }: { verbose: true; }): Move[]; history({ verbose }: { verbose: false; }): string[]; history({ verbose }: { verbose: boolean; }): string[] | Move[]; board(): ({ square: Square; type: PieceSymbol; color: Color; } | null)[][]; static _colorToCgColor(chessjsColor: Color): "white" | "black"; static _cgColorToColor(chessgroundColor: "white" | "black"): Color; static _cjsMoveToMove(cjsMove: CjsMove): Move; }