@echecs/san - v2.0.2
    Preparing search index...

    Interface Position

    An immutable chess position — board state, turn, castling rights, en passant square, and move counters.

    Query the position with getters and methods. Produce new positions with derive.

    interface Position {
        castlingRights: CastlingRights;
        enPassantSquare:
            | "a3"
            | "a6"
            | "b3"
            | "b6"
            | "c3"
            | "c6"
            | "d3"
            | "d6"
            | "e3"
            | "e6"
            | "f3"
            | "f6"
            | "g3"
            | "g6"
            | "h3"
            | "h6"
            | undefined;
        fullmoveNumber: number;
        halfmoveClock: number;
        turn: Color;
        get hash(): string;
        get isCheck(): boolean;
        get isInsufficientMaterial(): boolean;
        get isValid(): boolean;
        at(
            square:
                | "a1"
                | "a2"
                | "a3"
                | "a4"
                | "a5"
                | "a6"
                | "a7"
                | "a8"
                | "b1"
                | "b2"
                | "b3"
                | "b4"
                | "b5"
                | "b6"
                | "b7"
                | "b8"
                | "c1"
                | "c2"
                | "c3"
                | "c4"
                | "c5"
                | "c6"
                | "c7"
                | "c8"
                | "d1"
                | "d2"
                | "d3"
                | "d4"
                | "d5"
                | "d6"
                | "d7"
                | "d8"
                | "e1"
                | "e2"
                | "e3"
                | "e4"
                | "e5"
                | "e6"
                | "e7"
                | "e8"
                | "f1"
                | "f2"
                | "f3"
                | "f4"
                | "f5"
                | "f6"
                | "f7"
                | "f8"
                | "g1"
                | "g2"
                | "g3"
                | "g4"
                | "g5"
                | "g6"
                | "g7"
                | "g8"
                | "h1"
                | "h2"
                | "h3"
                | "h4"
                | "h5"
                | "h6"
                | "h7"
                | "h8",
        ): Piece
        | undefined;
        derive(changes?: DeriveOptions): Position;
        pieces(
            color?: Color,
        ): Map<
            | "a1"
            | "a2"
            | "a3"
            | "a4"
            | "a5"
            | "a6"
            | "a7"
            | "a8"
            | "b1"
            | "b2"
            | "b3"
            | "b4"
            | "b5"
            | "b6"
            | "b7"
            | "b8"
            | "c1"
            | "c2"
            | "c3"
            | "c4"
            | "c5"
            | "c6"
            | "c7"
            | "c8"
            | "d1"
            | "d2"
            | "d3"
            | "d4"
            | "d5"
            | "d6"
            | "d7"
            | "d8"
            | "e1"
            | "e2"
            | "e3"
            | "e4"
            | "e5"
            | "e6"
            | "e7"
            | "e8"
            | "f1"
            | "f2"
            | "f3"
            | "f4"
            | "f5"
            | "f6"
            | "f7"
            | "f8"
            | "g1"
            | "g2"
            | "g3"
            | "g4"
            | "g5"
            | "g6"
            | "g7"
            | "g8"
            | "h1"
            | "h2"
            | "h3"
            | "h4"
            | "h5"
            | "h6"
            | "h7"
            | "h8",
            Piece,
        >;
        reach(
            square:
                | "a1"
                | "a2"
                | "a3"
                | "a4"
                | "a5"
                | "a6"
                | "a7"
                | "a8"
                | "b1"
                | "b2"
                | "b3"
                | "b4"
                | "b5"
                | "b6"
                | "b7"
                | "b8"
                | "c1"
                | "c2"
                | "c3"
                | "c4"
                | "c5"
                | "c6"
                | "c7"
                | "c8"
                | "d1"
                | "d2"
                | "d3"
                | "d4"
                | "d5"
                | "d6"
                | "d7"
                | "d8"
                | "e1"
                | "e2"
                | "e3"
                | "e4"
                | "e5"
                | "e6"
                | "e7"
                | "e8"
                | "f1"
                | "f2"
                | "f3"
                | "f4"
                | "f5"
                | "f6"
                | "f7"
                | "f8"
                | "g1"
                | "g2"
                | "g3"
                | "g4"
                | "g5"
                | "g6"
                | "g7"
                | "g8"
                | "h1"
                | "h2"
                | "h3"
                | "h4"
                | "h5"
                | "h6"
                | "h7"
                | "h8",
            piece: Piece,
        ): (
            | "a1"
            | "a2"
            | "a3"
            | "a4"
            | "a5"
            | "a6"
            | "a7"
            | "a8"
            | "b1"
            | "b2"
            | "b3"
            | "b4"
            | "b5"
            | "b6"
            | "b7"
            | "b8"
            | "c1"
            | "c2"
            | "c3"
            | "c4"
            | "c5"
            | "c6"
            | "c7"
            | "c8"
            | "d1"
            | "d2"
            | "d3"
            | "d4"
            | "d5"
            | "d6"
            | "d7"
            | "d8"
            | "e1"
            | "e2"
            | "e3"
            | "e4"
            | "e5"
            | "e6"
            | "e7"
            | "e8"
            | "f1"
            | "f2"
            | "f3"
            | "f4"
            | "f5"
            | "f6"
            | "f7"
            | "f8"
            | "g1"
            | "g2"
            | "g3"
            | "g4"
            | "g5"
            | "g6"
            | "g7"
            | "g8"
            | "h1"
            | "h2"
            | "h3"
            | "h4"
            | "h5"
            | "h6"
            | "h7"
            | "h8"
        )[];
    }
    Index

    Properties

    castlingRights: CastlingRights

    Which castling moves remain available.

    enPassantSquare:
        | "a3"
        | "a6"
        | "b3"
        | "b6"
        | "c3"
        | "c6"
        | "d3"
        | "d6"
        | "e3"
        | "e6"
        | "f3"
        | "f6"
        | "g3"
        | "g6"
        | "h3"
        | "h6"
        | undefined

    En passant target square (rank 3 or 6), if any.

    fullmoveNumber: number

    Game turn counter — increments after each black move.

    halfmoveClock: number

    Half-moves since last pawn advance or capture (fifty-move rule).

    turn: Color

    Side to move.

    Accessors

    • get hash(): string

      Zobrist hash of the position as a 16-character hex string. Computed once and cached. Uses the Polyglot standard keys from @echecs/zobrist.

      Returns string

    • get isCheck(): boolean

      Whether the side to move is in check. Computed once and cached.

      Returns boolean

    • get isInsufficientMaterial(): boolean

      Whether the position is a draw by insufficient material (FIDE rules): K vs K, K+B vs K, K+N vs K, or K+B(s) vs K+B(s) with same-color bishops.

      Returns boolean

    • get isValid(): boolean

      Whether the position is legally reachable: exactly one king per side, no pawns on ranks 1 or 8, and the side not to move is not in check.

      Returns boolean

    Methods

    • Returns the piece on the given square, or undefined if empty.

      Parameters

      • square:
            | "a1"
            | "a2"
            | "a3"
            | "a4"
            | "a5"
            | "a6"
            | "a7"
            | "a8"
            | "b1"
            | "b2"
            | "b3"
            | "b4"
            | "b5"
            | "b6"
            | "b7"
            | "b8"
            | "c1"
            | "c2"
            | "c3"
            | "c4"
            | "c5"
            | "c6"
            | "c7"
            | "c8"
            | "d1"
            | "d2"
            | "d3"
            | "d4"
            | "d5"
            | "d6"
            | "d7"
            | "d8"
            | "e1"
            | "e2"
            | "e3"
            | "e4"
            | "e5"
            | "e6"
            | "e7"
            | "e8"
            | "f1"
            | "f2"
            | "f3"
            | "f4"
            | "f5"
            | "f6"
            | "f7"
            | "f8"
            | "g1"
            | "g2"
            | "g3"
            | "g4"
            | "g5"
            | "g6"
            | "g7"
            | "g8"
            | "h1"
            | "h2"
            | "h3"
            | "h4"
            | "h5"
            | "h6"
            | "h7"
            | "h8"

      Returns Piece | undefined

    • Returns a new position with the given changes applied. Fields not provided are carried over from the source.

      Parameters

      • Optionalchanges: DeriveOptions

      Returns Position

    • Returns a map of all pieces on the board, optionally filtered by color.

      Parameters

      • Optionalcolor: Color

      Returns Map<
          | "a1"
          | "a2"
          | "a3"
          | "a4"
          | "a5"
          | "a6"
          | "a7"
          | "a8"
          | "b1"
          | "b2"
          | "b3"
          | "b4"
          | "b5"
          | "b6"
          | "b7"
          | "b8"
          | "c1"
          | "c2"
          | "c3"
          | "c4"
          | "c5"
          | "c6"
          | "c7"
          | "c8"
          | "d1"
          | "d2"
          | "d3"
          | "d4"
          | "d5"
          | "d6"
          | "d7"
          | "d8"
          | "e1"
          | "e2"
          | "e3"
          | "e4"
          | "e5"
          | "e6"
          | "e7"
          | "e8"
          | "f1"
          | "f2"
          | "f3"
          | "f4"
          | "f5"
          | "f6"
          | "f7"
          | "f8"
          | "g1"
          | "g2"
          | "g3"
          | "g4"
          | "g5"
          | "g6"
          | "g7"
          | "g8"
          | "h1"
          | "h2"
          | "h3"
          | "h4"
          | "h5"
          | "h6"
          | "h7"
          | "h8",
          Piece,
      >

    • From square, return all squares the given piece can reach on the current board. Filters out same-color pieces. For sliding pieces, stops before friendlies and includes enemy pieces. For pawns, includes pushes (blocked by any piece), captures (enemy only), and en passant.

      Parameters

      • square:
            | "a1"
            | "a2"
            | "a3"
            | "a4"
            | "a5"
            | "a6"
            | "a7"
            | "a8"
            | "b1"
            | "b2"
            | "b3"
            | "b4"
            | "b5"
            | "b6"
            | "b7"
            | "b8"
            | "c1"
            | "c2"
            | "c3"
            | "c4"
            | "c5"
            | "c6"
            | "c7"
            | "c8"
            | "d1"
            | "d2"
            | "d3"
            | "d4"
            | "d5"
            | "d6"
            | "d7"
            | "d8"
            | "e1"
            | "e2"
            | "e3"
            | "e4"
            | "e5"
            | "e6"
            | "e7"
            | "e8"
            | "f1"
            | "f2"
            | "f3"
            | "f4"
            | "f5"
            | "f6"
            | "f7"
            | "f8"
            | "g1"
            | "g2"
            | "g3"
            | "g4"
            | "g5"
            | "g6"
            | "g7"
            | "g8"
            | "h1"
            | "h2"
            | "h3"
            | "h4"
            | "h5"
            | "h6"
            | "h7"
            | "h8"
      • piece: Piece

      Returns (
          | "a1"
          | "a2"
          | "a3"
          | "a4"
          | "a5"
          | "a6"
          | "a7"
          | "a8"
          | "b1"
          | "b2"
          | "b3"
          | "b4"
          | "b5"
          | "b6"
          | "b7"
          | "b8"
          | "c1"
          | "c2"
          | "c3"
          | "c4"
          | "c5"
          | "c6"
          | "c7"
          | "c8"
          | "d1"
          | "d2"
          | "d3"
          | "d4"
          | "d5"
          | "d6"
          | "d7"
          | "d8"
          | "e1"
          | "e2"
          | "e3"
          | "e4"
          | "e5"
          | "e6"
          | "e7"
          | "e8"
          | "f1"
          | "f2"
          | "f3"
          | "f4"
          | "f5"
          | "f6"
          | "f7"
          | "f8"
          | "g1"
          | "g2"
          | "g3"
          | "g4"
          | "g5"
          | "g6"
          | "g7"
          | "g8"
          | "h1"
          | "h2"
          | "h3"
          | "h4"
          | "h5"
          | "h6"
          | "h7"
          | "h8"
      )[]