1.0.23 โ€ข Published 6 months ago

@chess-labs/core v1.0.23

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

Chess Core

A minimal, standalone chess logic implementation in TypeScript.

Features

  • ๐ŸŽฏ Type-safe piece and board representations
  • ๐Ÿ”ง Pure logic with no UI or DOM dependencies
  • โ™Ÿ๏ธ Complete legal move calculation for all pieces
  • ๐Ÿฐ Full special rules support (castling, en passant, promotion)
  • โœ… Check, checkmate, and stalemate detection
  • ๐Ÿ“ FEN notation support (import/export game states)
  • ๐Ÿ”„ Easily portable into any frontend or backend project
  • ๐Ÿงช Unit test friendly architecture with comprehensive test coverage

Installation

Once published to npm:

npm install @chess-labs/core

Usage Example

import { initGameState, getLegalMoves, movePiece, gameStateToFen, fenToGameState } from '@chess-labs/core';

// Initialize a new game
const gameState = initGameState();

// Get legal moves for a piece
const moves = getLegalMoves({ row: 6, col: 4 }, gameState); // White pawn at e2

// Make a move
const newGameState = movePiece(
  { row: 6, col: 4 }, // from e2
  { row: 4, col: 4 }, // to e4
  gameState
);

// Convert to FEN notation
if (newGameState) {
  const fen = gameStateToFen(newGameState);
  console.log(fen); // "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1"

  // Load from FEN
  const loadedGame = fenToGameState(fen);
}

Architecture

src/
โ”œโ”€โ”€ types.ts         # Core types (Piece, Board, Position)
โ”œโ”€โ”€ board.ts         # Board initialization & utilities
โ”œโ”€โ”€ board.spec.ts    # Board related tests
โ”œโ”€โ”€ game.ts          # Game state, turn tracking, move execution
โ”œโ”€โ”€ game.spec.ts     # Game logic tests
โ”œโ”€โ”€ helper.ts        # Utility functions
โ”œโ”€โ”€ helper.spec.ts   # Utility tests
โ””โ”€โ”€ moves/           # Per-piece movement logic

Roadmap

  • โœ… Basic movement rules
  • โœ… Special rules (castling, en passant, promotion)
  • โœ… Check & checkmate detection
  • โœ… FEN support (NEW!)
  • PGN support
  • AI opponent integration examples

Testing

npm run test

Unit tests are written with Vitest, covering all movement and rule logic.

Goals

  • Write maintainable, testable TypeScript logic
  • Decouple core engine from UI for maximum reusability
  • Build as an open-source learning and portfolio project

Contributing

Pull requests, suggestions, and feedback are welcome! Please refer to the issues tab to get started.

1.0.23

6 months ago

1.0.22

6 months ago

1.0.21

6 months ago

1.0.20

6 months ago

1.0.19

6 months ago

1.0.18

6 months ago

1.0.17

6 months ago

1.0.16

6 months ago

1.0.15

6 months ago

1.0.9

6 months ago

1.0.6

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago