@pech/chess-core
v1.0.2
Published
A fast, type-safe chess library with immutable state and bitboard representation
Maintainers
Readme
chess-core
A fast, type-safe chess library for JavaScript and TypeScript. Immutable state, bitboard representation, and a pure functional API.
Documentation — visit for guides, examples, and the full API reference.
Interactive example — see chess-core combined with chess-board for a draggable board with legal moves and position updates.
Features
- Bitboard-based move generation for high performance
- Immutable positions -- every move returns a new state
- Pure functions -- no hidden state, fully tree-shakeable
- Type-safe -- branded types for squares, files, and ranks
- Perft-tested -- verified against known node counts
Install
npm install @pech/chess-core
# or
bun add @pech/chess-coreQuick Start
import { fromFen, getLegalMoves, makeMove, toSan, isCheckmate, STARTING_FEN } from '@pech/chess-core';
const pos = fromFen(STARTING_FEN);
const moves = getLegalMoves(pos);
const newPos = makeMove(pos, moves[0]);
console.log(toSan(pos, moves[0])); // "e4"
console.log(isCheckmate(newPos)); // falseAPI
Position
fromFen(fen: string): Position
toFen(pos: Position): stringMove Generation
getLegalMoves(pos: Position): Move[]
getPseudoLegalMoves(pos: Position): Move[]Making Moves
makeMove(pos: Position, move: Move): PositionValidation
isCheck(pos: Position): boolean
isCheckmate(pos: Position): boolean
isStalemate(pos: Position): boolean
isInsufficientMaterial(pos: Position): boolean
isFiftyMoveRule(pos: Position): boolean
isSquareAttacked(pos: Position, sq: Square, byColor: Color): booleanNotation
toSan(pos: Position, move: Move): string
toUci(move: Move): string
fromUci(pos: Position, uci: string): Move | null
fromSan(pos: Position, san: string): Move | nullPerft
perft(pos: Position, depth: number): number
divide(pos: Position, depth: number): DivideResult[]Development
bun install # install dependencies
bun run test # run tests
bun run test:watch # run tests in watch mode
bun run build # build with tsup
bun run typecheck # type-check without emittingLicense
MIT
