import type { Move, Ban, Action, ActionResult, HistoryEntry, Player, ActionType, SerializedAction, SyncState, IndicatorConfig } from './types.js'; /** * BanChess - A chess variant where moves are banned before each turn * * In Ban Chess, before each move, the opponent bans one of your possible moves. * This creates a strategic layer where you must anticipate which moves will be banned. * * @example * ```typescript * const game = new BanChess(); * * // Black bans White's e2-e4 * game.play({ ban: { from: 'e2', to: 'e4' } }); * * // White plays d2-d4 instead * game.play({ move: { from: 'd2', to: 'd4' } }); * ``` */ export declare class BanChess { /** Current version of the BanChess library */ static readonly VERSION = "4.0.1"; private chess; private _currentBannedMove; private _history; private _ply; private _indicatorConfig; /** * Creates a new BanChess game instance * @param fen - Optional FEN string to load a position (with ban state as 7th field) * @param pgn - Optional PGN string to load a game (with ban annotations) * @example * ```typescript * // Start from initial position * const game = new BanChess(); * * // Load from FEN with ban state * const game2 = new BanChess('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 b:e2e4'); * * // Load from PGN * const game3 = new BanChess(undefined, '1. {banning: e2e4} d4'); * ``` */ constructor(fen?: string, pgn?: string); /** * Gets the current ply number (1-based) * @returns Current ply number * @example * ```typescript * const game = new BanChess(); * console.log(game.getPly()); // 1 (first ply: Black bans) * ``` */ getPly(): number; /** * Gets the color of the player who performs the action at the current ply * @returns 'white' or 'black' * @example * ```typescript * const game = new BanChess(); * console.log(game.getActivePlayer()); // 'black' (ply 1: Black bans) * ``` */ getActivePlayer(): Player; /** * Gets the type of action for the current ply * @returns 'ban' for odd plies, 'move' for even plies * @example * ```typescript * const game = new BanChess(); * console.log(game.getActionType()); // 'ban' (ply 1: restriction) * ``` */ getActionType(): ActionType; /** * Gets the color of the player who needs to perform the next action (ban or move) * @returns 'white' or 'black' * @example * ```typescript * const game = new BanChess(); * console.log(game.turn); // 'black' (Black bans first) * ``` * @deprecated Use getActivePlayer() instead for clearer ply-based logic */ get turn(): Player; /** * Gets the currently banned move, if any * @returns The banned move or null if no move is currently banned * @example * ```typescript * game.play({ ban: { from: 'e2', to: 'e4' } }); * console.log(game.currentBannedMove); // { from: 'e2', to: 'e4' } * ``` */ get currentBannedMove(): Ban | null; /** * Determines what type of action should be played next * @returns 'ban' if a ban is expected, 'move' if a move is expected * @example * ```typescript * const game = new BanChess(); * console.log(game.nextActionType()); // 'ban' (game starts with a ban) * game.play({ ban: { from: 'e2', to: 'e4' } }); * console.log(game.nextActionType()); // 'move' (after ban, a move is expected) * ``` * @deprecated Use getActionType() instead for clearer ply-based logic */ nextActionType(): ActionType; /** * Plays an action (either a ban or a move) in the game * * @param action - The action to play: `{ ban: Ban }` or `{ move: Move }` * * @returns {ActionResult} Comprehensive result with game state: * * @returns.success - `true` if action was valid and executed * @returns.action - The action that was played * @returns.san - Standard Algebraic Notation with indicators (+, #, =) * @returns.newFen - Resulting position in extended FEN format * @returns.error - Error message if action failed * @returns.flags - Game state flags: * - `check`: King is in check * - `checkmate`: Game ended in checkmate * - `stalemate`: Game ended in stalemate * - `draw`: Game is a draw (50-move, repetition, insufficient material) * - `gameOver`: Game has ended for any reason * - `insufficientMaterial`: Draw by insufficient material * - `threefoldRepetition`: Draw by repetition * - `fiftyMoveRule`: Draw by 50-move rule * - `banCausedCheckmate`: Ban removed only escape from check * - `banCausedStalemate`: Ban removed only legal move * * @example * ```typescript * // Ban a move (Black starts by banning) * const banResult = game.play({ ban: { from: 'e2', to: 'e4' } }); * console.log('Banned:', banResult.san); // 'e2e4' * console.log('Flags:', banResult.flags); * // { gameOver: false, check: false, ... } * * // Make a move * const moveResult = game.play({ move: { from: 'd2', to: 'd4' } }); * console.log('Move:', moveResult.san); // 'd4' * console.log('In check?', moveResult.flags?.check); // false * * // Checkmate example * const mateResult = game.play({ move: { from: 'd8', to: 'h4' } }); * console.log('Move:', mateResult.san); // 'Qh4#' * console.log('Checkmate?', mateResult.flags?.checkmate); // true * console.log('Game over?', mateResult.flags?.gameOver); // true * * // Ban causing checkmate (removes only escape) * const banMate = game.play({ ban: { from: 'g1', to: 'h1' } }); * console.log('Ban:', banMate.san); // 'g1h1#' * console.log('Ban caused checkmate?', banMate.flags?.banCausedCheckmate); // true * ``` */ play(action: Action): ActionResult; /** * Handles playing a ban action * @param ban - The ban to apply * @returns Result of the ban action * @private */ private playBan; /** * Handles playing a move action * @param move - The move to play * @returns Result of the move action * @private */ private playMove; /** * Checks if a move is currently banned * @param move - The move to check * @returns true if the move is banned, false otherwise * @private */ private isBannedMove; /** * Gets all legal actions for the current ply (bans or moves) * @returns Array of legal actions based on current ply type * @example * ```typescript * const game = new BanChess(); * const actions = game.getLegalActions(); // Returns all possible bans for ply 1 * ``` */ getLegalActions(): Action[]; /** * Gets all legal moves in the current position (excluding banned moves) * @returns Array of legal moves, empty if it's time to ban or game is over * @example * ```typescript * game.play({ ban: { from: 'e2', to: 'e4' } }); * const moves = game.legalMoves(); * // Returns all White's opening moves except e2-e4 * ``` * @deprecated Use getLegalActions() instead for unified action handling */ legalMoves(): Move[]; /** * Gets all legal bans (opponent's possible moves that can be banned) * @returns Array of moves that can be banned, empty if it's time to move or game is over * @example * ```typescript * const game = new BanChess(); * const bans = game.legalBans(); * // Returns all of White's possible opening moves * ``` * @deprecated Use getLegalActions() instead for unified action handling */ legalBans(): Move[]; /** * Checks if the current player's king is in check * @returns true if in check, false otherwise */ inCheck(): boolean; /** * Checks if the current position is checkmate * @returns true if checkmate, false otherwise * @example * ```typescript * // If king in check with only one escape move, * // opponent can achieve checkmate by banning that move * ``` */ inCheckmate(): boolean; /** * Checks if the current position is stalemate * @returns true if stalemate (no legal moves but not in check), false otherwise */ inStalemate(): boolean; /** * Checks if the game is over (checkmate, stalemate, or draw) * @returns true if game is over, false otherwise */ gameOver(): boolean; /** * Checks if the game is a draw (by repetition, 50-move rule, or insufficient material) * Note: In Ban Chess, draws are less common due to the banning mechanic * @returns true if the position is a draw */ inDraw(): boolean; /** * Checks for threefold repetition * @returns true if the same position has occurred three times */ inThreefoldRepetition(): boolean; /** * Checks if there is insufficient material to checkmate * @returns true if neither side can checkmate */ insufficientMaterial(): boolean; /** * Returns the color of the player who needs to perform the next action (ban or move) * @returns The color of the current player * @deprecated Use the `turn` getter instead */ currentPlayer(): Player; /** * Configure where game state indicators (+, #, =) appear * @param config - Configuration for indicator display * @example * ```typescript * // Disable indicators in PGN but keep in SAN * game.setIndicatorConfig({ pgn: false, san: true }); * ``` */ setIndicatorConfig(config: IndicatorConfig): void; /** * Get current indicator configuration * @returns Current indicator configuration */ getIndicatorConfig(): IndicatorConfig; /** * Returns the color of the player whose piece will move next * @returns 'white' or 'black' - whose pieces will move in the next move action * @example * ```typescript * // At game start, Black bans first, but White moves first * const game = new BanChess(); * console.log(game.nextMoveColor()); // 'white' * ``` */ nextMoveColor(): Player; /** * Gets PGN-style indicator for current game state * @private */ private getGameIndicator; /** * Gets current game state flags * @returns Current game state flags */ private getGameFlags; /** * Gets the current position as an extended FEN string * @returns FEN string with 7th field for ply/ban state with optional PGN indicator * @example * ```typescript * const game = new BanChess(); * game.play({ ban: { from: 'e2', to: 'e4' } }); * console.log(game.fen()); * // "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1 2:e2e4" * * // Position with check * // "rnb1kbnr/pppp1ppp/4p3/8/5PP1/8/PPPPP2P/RNBQKBNR w KQkq - 0 3 6+" * * // Checkmate position * // "8/8/8/8/8/7k/6q1/7K w - - 0 1 10#" * ``` */ fen(): string; /** * Gets the game notation in PGN format with ban annotations * @returns PGN string with bans shown as comments like {banning: e2e4} * Ban annotations include: * - `+` when the ban forces a position where all legal moves result in check * - `#` when the ban causes checkmate (banning the only escape from check) * - `=` when the ban causes stalemate (banning the only legal move when not in check) * * Note: The PGN format uses comments ({banning: ...}) for compatibility with standard * PGN parsers, while the serialization format uses the more compact b:e2e4 notation. * This distinction may be unified in future versions based on community feedback. * * @example * ```typescript * const game = new BanChess(); * game.play({ ban: { from: 'e2', to: 'e4' } }); * game.play({ move: { from: 'd2', to: 'd4' } }); * console.log(game.pgn()); // "1. {banning: e2e4} d4" * ``` */ pgn(): string; /** * Gets the complete game history * @returns Array of history entries with all actions, positions, and metadata * @example * ```typescript * const history = game.history(); * history.forEach(entry => { * console.log(`${entry.player} ${entry.actionType}: ${JSON.stringify(entry.action)}`); * }); * ``` */ history(): HistoryEntry[]; /** * Resets the game to the initial position * @example * ```typescript * game.reset(); * console.log(game.fen()); // Starting position with "b:ban" state * ``` */ reset(): void; /** * Undoes the last action (ban or move) * @returns true if undo was successful, false if there's nothing to undo * @example * ```typescript * game.play({ ban: { from: 'e2', to: 'e4' } }); * game.play({ move: { from: 'd2', to: 'd4' } }); * game.undo(); // Undoes the move d2-d4 * game.undo(); // Undoes the ban e2-e4 * ``` */ undo(): boolean; /** * Returns an ASCII representation of the current board position * Shows the banned move with brackets around the affected squares * @returns ASCII string representation of the board * @example * ```typescript * console.log(game.ascii()); * // After banning e2-e4: * // +------------------------+ * // | r n b q k b n r | * // | p p p p p p p p | * // | . . . . . . . . | * // | . . . . [.] . . . | ← e4 is banned destination * // | . . . . . . . . | * // | . . . . . . . . | * // | P P P P [P] P P P | ← e2 is banned source * // | R N B Q K B N R | * // +------------------------+ * // Banned: e2→e4 * ``` */ ascii(): string; /** * Serialize an action to a compact string format for network transmission * Includes game state indicators: + for check, # for checkmate, = for stalemate * @param action - The action to serialize * @param gameStateIndicator - Optional indicator for check/checkmate/stalemate * @returns Serialized action string (e.g., "b:e2e4#" for checkmate-causing ban) * @example * ```typescript * const ban = { ban: { from: 'e2', to: 'e4' } }; * console.log(BanChess.serializeAction(ban)); // "b:e2e4" * console.log(BanChess.serializeAction(ban, '#')); // "b:e2e4#" (checkmate) * * const promotion = { move: { from: 'e7', to: 'e8', promotion: 'q' } }; * console.log(BanChess.serializeAction(promotion, '+')); // "m:e7e8q+" * ``` */ static serializeAction(action: Action, gameStateIndicator?: '+' | '#' | '='): SerializedAction; /** * Deserialize a string to an Action object * Handles game state indicators: + for check, # for checkmate, = for stalemate * @param serialized - The serialized action string * @returns The Action object and any game state indicator * @throws Error if the format is invalid * @example * ```typescript * const ban = BanChess.deserializeAction('b:e2e4#'); * // Returns: { ban: { from: 'e2', to: 'e4' } } * * const move = BanChess.deserializeAction('m:e7e8q+'); * // Returns: { move: { from: 'e7', to: 'e8', promotion: 'q' } } * ``` */ static deserializeAction(serialized: SerializedAction): Action; /** * Get the last action as a serialized string with game state indicators * @returns The last action in serialized format, or null if no actions * @example * ```typescript * game.play({ ban: { from: 'e2', to: 'e4' } }); * console.log(game.getLastActionSerialized()); // "b:e2e4" * ``` */ getLastActionSerialized(): SerializedAction | null; /** * Get a sync state object for network transmission * @returns Current state with minimal data for synchronization * @example * ```typescript * const state = game.getSyncState(); * // Send state over network * socket.emit('gameState', state); * ``` */ getSyncState(): SyncState; /** * Apply a serialized action to the current game state * @param serialized - The serialized action to apply * @returns The result of applying the action * @example * ```typescript * // Receive action from network * socket.on('action', (serialized: string) => { * const result = game.playSerializedAction(serialized); * if (!result.success) { * console.error('Invalid action:', result.error); * } * }); * ``` */ playSerializedAction(serialized: SerializedAction): ActionResult; /** * Load game state from a sync state object * @param syncState - The sync state to load * @example * ```typescript * // Receive state from network * socket.on('syncState', (state: SyncState) => { * game.loadFromSyncState(state); * }); * ``` */ loadFromSyncState(syncState: SyncState): void; /** * Get a unified action log with both bans and moves in a single array * Bans use "b:fromto" format, moves use SAN notation with indicators * @returns Array of actions in chronological order * @example * ```typescript * const log = game.getActionLog(); * // ["b:e2e4", "d4", "b:e7e5", "d5", "b:d2d4", "Nf3", "b:h7h6", "Qh4#"] * ``` */ getActionLog(): string[]; /** * Get a compact string representation of all actions in the game * @returns Array of serialized actions in chronological order with game state indicators * @example * ```typescript * const actions = game.getActionHistory(); * // ["b:e2e4", "m:d2d4", "b:e7e5+", "m:d7d5", "m:Qh5#", ...] * ``` */ getActionHistory(): SerializedAction[]; /** * Replay a game from a series of serialized actions * @param actions - Array of serialized actions to replay * @param startingFen - Optional starting FEN (defaults to initial position) * @returns A new BanChess instance with the replayed game * @throws Error if any action fails to replay * @example * ```typescript * const actions = ['b:e2e4', 'm:d2d4', 'b:e7e5', 'm:d7d5']; * const game = BanChess.replayFromActions(actions); * console.log(game.pgn()); // Reconstructed game * ``` */ static replayFromActions(actions: SerializedAction[], startingFen?: string): BanChess; /** * Loads a game position from an extended FEN string * @param fen - FEN string with optional 7th field for ply number and ban state * @private * @throws Error if the Ban Chess FEN format is invalid */ private loadFromFEN; /** * Loads a game from PGN notation with ban annotations * @param pgn - PGN string with ban annotations in {banning: ...} format * @private */ private loadFromPGN; } //# sourceMappingURL=BanChess.d.ts.map