import { Result } from '@badrap/result'; import { Board } from './board.js'; import { Setup } from './setup.js'; import { SquareSet } from './squareSet.js'; import { Color, Move, Outcome, Piece, Rules, Square } from './types.js'; /** * Data structure of error codes characterizing invalid board positions. */ export declare enum IllegalSetup { Empty = "ERR_EMPTY", OppositeCheck = "ERR_OPPOSITE_CHECK", Kings = "ERR_KINGS", Advisors = "ERR_ADVISORS", Elephants = "ERR_ELEPHANTS", Horses = "ERR_HORSES", Chariots = "ERR_CHARIOTS", Cannons = "ERR_CANNONS", Pawns = "ERR_PAWNS", FacingKings = "ERR_FACING_KINGS" } export declare class PositionError extends Error { } /** * Determine squares from which a horse can attack the given `square`. */ export declare const horseInvAttacks: (square: Square, occupied: SquareSet) => SquareSet; /** * Returns a bitboard of squares from which a pawn of color `color` could attack the given `square`. */ export declare const pawnInvAttacks: (color: Color, square: Square) => SquareSet; /** * Data structure to cache additional useful information of a position. Currently it stores * - king position * - a bitboard containing all pieces giving a check. * * Note the context is dependent on whose turn is to play. */ export interface Context { king: Square | undefined; checkers: SquareSet; } export declare const defaultPosition: (rules: Rules) => Position; /** * State description of the current position, storing the board situation, whose turn is to play, * how many half-moves have gone without captures and how many total moves since the beginning. */ export declare abstract class Position { readonly rules: Rules; board: Board; turn: Color; halfmoves: number; fullmoves: number; protected constructor(rules: Rules); reset(): void; protected setupUnchecked(setup: Setup): void; attackers(square: Square, attacker: Color, occupied: SquareSet): SquareSet; /** Get the current context. */ ctx(): Context; clone(): Position; /** * Check the given position is legal. */ protected validate(): Result; /** * Return all pseudomove a given `piece` placed on `square` can move. That is, return all possible * moves without checking for pins or discovered checks. */ pseudoDests(piece: Piece, square: Square): SquareSet; /** generate all legal for a piece on given square */ dests(square: Square, ctx?: Context): SquareSet; toSetup(): Setup; /** * Check if the given side has insufficient material to checkmate. * Note! This is currently a simplified version and not all cases of insufficient material are detected. */ hasInsufficientMaterial(c: Color): boolean; /** Returns `true` if neither side can checkmate. */ isInsufficientMaterial(): boolean; hasDests(ctx?: Context): boolean; /** Check if a move is legal */ isLegal(move: Move, ctx?: Context): boolean; /** Check if in the given position the two kings are facing each other with no piece in between. */ isFacingKings(): boolean; isCheck(ctx?: Context): boolean; is50Moves(): boolean; isEnd(ctx?: Context): boolean; isCheckmate(ctx?: Context): boolean; isStalemate(ctx?: Context): boolean; outcome(ctx?: Context): Outcome | undefined; /** * Determine a vector of legal destinations for each piece of the player in turn. */ allDests(ctx?: Context): Map; /** * Play a move, i.e. update the board and move counters. * This method assumes the move is valid and does not perform any validation. */ play(move: Move): void; } /** Concrete class for standard xiangqi. */ export declare class Xiangqi extends Position { private constructor(); static default(): Xiangqi; static fromSetup(setup: Setup): Result; clone(): Xiangqi; } /** Check if two positions are equal ignoring the number of moves and half-moves. */ export declare const equalsIgnoreMoves: (left: Position, right: Position) => boolean; /** Check the given side does not have extra pieces. */ export declare const isStandardMaterialSide: (board: Board, color: Color) => boolean; /** Check neither side doesnt' have any extra pieces. */ export declare const isStandardMaterial: (pos: Xiangqi) => boolean; /** * Check if there is a check in the current position and return `true` if the check is impossible * If it's not a check, return `false`. * Note! Currently, this returns true only in the case of a check with more than 4 checkers. */ export declare const isImpossibleCheck: (pos: Position) => boolean;