import { Colors, Pieces, Squares } from '../types/Types'; import { Castling } from './Castling'; import { Piece } from './Piece'; import { SimpleMove } from './SimpleMove'; export declare enum SanCheckLevel { NoCheckTest = 0, CheckText = 1, MateTest = 2 } export declare enum GenerateMode { Captures = 1, NonCaptures = 2, All = 3 } /** * Chess position */ export declare class Position { private brd; private capt; private plyCnt; private strictCastling; private pinned; private list; private listPos; private pieceCount; private material; private numOnRank; private numOnFyle; private numOnLeftDiag; private numOnRightDiag; private numOnSquareColor; private wm; private castling; EpTarget?: Squares.Square; HalfMoveCount: number; /** * @constructor */ constructor(fen?: string); clear(): void; /** * Copy position * @param source {Position} */ copyFrom(source: Position): void; /** * Clone position object * @returns ChessPosition */ clone(): Position; get WhoMove(): Colors.BW; set WhoMove(value: Colors.BW); /** * Byte board */ get Board(): (Pieces.Piece | Pieces.Empty)[]; get Captured(): number[]; /** * Castling */ get Castling(): Castling; /** * Get piece on square */ getPiece: (sq: number) => (Pieces.Piece | Pieces.Empty); /** * */ getPieceNum: (sq: number) => number; /** * Return true if count of specified piece great than zero. */ hasPiece(p: number): boolean; /** * Return count of specified piece. */ getPieceCount(p: number): number; /** * Add piece to square * @param p * @param sq * @returns Boolean */ addPiece(p: Pieces.Piece, sq: Squares.Square): boolean; /** * Remove piece from square * @param p * @param sq * @returns Boolean */ removePiece(p: Pieces.Piece, sq: Squares.Square): boolean; /** * Return current halfmove humber */ get PlyCount(): number; /** * Return current halfmove humber */ set PlyCount(val: number); /** * Make the move on the board and update all the necessary * fields in the simpleMove structure so it can be undone. * @param sm {SimpleMove} */ doSimpleMove(sm: SimpleMove): void; /** * Take back a simple move that has been made with DoSimpleMove(). * @param sm {SimpleMove} */ undoSimpleMove(sm: SimpleMove): void; makeSanString(sm: SimpleMove, flag?: SanCheckLevel): string; /** * Generate the legal moves list. * If the specified pieceType is not NOPIECE, then only legal moves for that type of piece * are generated. */ generateMoves(pieceType?: Pieces.PieceType, genType?: number, maybeInCheck?: boolean): SimpleMove[]; isLegalMove(sm: SimpleMove): boolean; /** * Добавить фигуру на доску * @param p * @param sq */ private addToBoard; /** * Убрать фигуру с доски * @param p * @param sq */ private removeFromBoard; private fyleCount; private rankCount; private leftDiagCount; private rightDiagCount; private squareColorCount; /** * Клетка на которой находится король * @param c * @returns Number */ private getKingSquare; /** * Клетка на которой находится король противника * @param c * @returns Number */ private getEnemyKingSquare; /** * Посчитать количество шахов */ private calcNumChecks; /** * Король под шахом */ isKingInCheck(): boolean; /** * Рассчитать количество атак для указанной стороны. * Эта функция также добавляет список атакующих клеток в параметре fromSqs, если он не undefined. */ private calcAttacks; private calcPins; private calcPinsDir; /** * Add legal move * * @param mlist * @param from * @param to * @param promo * @returns */ private addLegalMove; /** * Generate slider moves along a direction, for a sliding * piece of the specified color from the specified square. * If sqset != undefined, moves must be to a square in sqset. * * @param mlist * @param color * @param fromSq * @param dir * @param sqset * @param capturesOnly * @returns */ private genSliderMoves; /** * Generate knight moves. * If sqset != undefined, moves must be to a square in sqset. * * @param mlist * @param color * @param fromSq * @param sqset * @param capturesOnly * @returns */ private genKnightMoves; /** * Generate the legal castling moves. * Assumes the side to move is NOT in check, so the caller * should verify this first. * * @param mlist * @returns */ private genCastling; /** * Generate the legal King moves. Castling is generated as well, if * the specified flag is true. * * @param mlist * @param genType * @param castling * @returns */ private genKingMoves; /** * Add promotion moves. * Called by GenPawnMoves() when a pawn can be promoted. * * @param mlist * @param from * @param dest * @returns */ private addPromotions; /** * Used to verify that an enpassant pawn capture is valid. * This is needed because illegal enpassant captures can appear legal * according to calculations of pinned pieces. * For example, consider WK d5, WP e5, BP f5 (just moved there), * BR h5 and the enpassant capture exf6 would be illegal. * * @param from * @param to * @returns */ private isValidEnPassant; private isPossibleCapture; /** * Generate legal pawn moves. * If dir != NULL_DIR, pawn MUST move in direction dir or its opposite. * If sqset != undefined, pawn MUST move to a square in sqset. * The dir and sq parameters are for pinned pawns and check evasions. * * @param mlist * @param from * @param dir * @param sqset * @param genType * @returns */ private genPawnMoves; /** * Generate legal moves for the side to move when the King is in check. * * @param mlist * @param mask * @param genType * @param checkSquares * @returns */ private genCheckEvasions; /** * Generates moves for a non pawn, non king piece. * If sqset != undefined, moves must be to a square in sqset. */ private genPieceMoves; private matchLegalMove; protected matchKingMove(mlist: SimpleMove[], target: Squares.Square): boolean; /** * * Given a move in coordinate notation, e.g. "e2e4" or "g1f3", generates the legal move it represents. * If "reverse" is true, coordinates in reverse order are acceptable, e.g. "f3g1" for 1.Nf3. * @param str * @param reverse */ readCoord(str: string): Squares.FromTo | false; /** * * Given a move in coordinate notation, e.g. "e2e4" or "g1f3", generates the legal move it represents. * If "reverse" is true, coordinates in reverse order are acceptable, e.g. "f3g1" for 1.Nf3. * If the coordinates are valid - look for them among the valid moves and return SimpleMove * @param str * @param reverse */ readCoordMove(str: string, reverse?: boolean): SimpleMove | null; } export declare const ChessPositionStd: Position;