Piece positions on a board.

Properties are sets of squares, like board.occupied for all occupied squares, board[color] for all pieces of that color, and board[role] for all pieces of that role. When modifying the properties directly, take care to keep them consistent.

Implements

Properties

bishop: SquareSet
black: SquareSet
king: SquareSet
knight: SquareSet
occupied: SquareSet

All occupied squares.

pawn: SquareSet
promoted: SquareSet

All squares occupied by pieces known to be promoted. This information is relevant in chess variants like Crazyhouse.

queen: SquareSet
rook: SquareSet
white: SquareSet

Methods

  • Returns Iterator<[number, Piece], any, any>

  • Parameters

    • square: number

    Returns undefined | "black" | "white"

  • Parameters

    • square: number

    Returns
        | undefined
        | "pawn"
        | "knight"
        | "bishop"
        | "rook"
        | "queen"
        | "king"

  • Parameters

    • square: number

    Returns boolean

  • Finds the unique king of the given color, if any.

    Parameters

    • color: "black" | "white"

    Returns undefined | number

  • Parameters

    • color: "black" | "white"
    • role:
          | "pawn"
          | "knight"
          | "bishop"
          | "rook"
          | "queen"
          | "king"

    Returns SquareSet

  • Resets all pieces to the default starting position for standard chess.

    Returns void

  • Put piece onto square, potentially replacing an existing piece. Returns the existing piece, if any.

    Parameters

    • square: number
    • piece: Piece

    Returns undefined | Piece

  • Removes and returns the piece from the given square, if any.

    Parameters

    • square: number

    Returns undefined | Piece