@echecs/position
    Preparing search index...

    Class 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.

    Index

    Constructors

    Properties

    castlingRights: CastlingRights

    Which castling moves remain available.

    enPassantSquare: EnPassantSquare | 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

    • 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

      Returns Square[]