Chess
A complete chess game for the browser: play a friend on the same device or take on a built-in computer opponent at five strength levels. Written in TypeScript with no runtime dependencies; the rules engine and the AI are both implemented from scratch.

Quick start
Requires Node.js 22.12 or newer (the test runner supports Node 22, 24 and 26+).
Open the URL Vite prints (usually http://localhost:5173).
To build a static site into dist/:
npm run build
npm run preview
The build uses relative paths, so dist/ can be hosted from any folder or static host.
Features
Rules
- Every rule of chess: castling, en passant, promotion to any piece, check, checkmate and stalemate
- Draws by the fifty-move rule, threefold repetition, insufficient material and agreement
- When a flag falls the game is scored as a draw if the opponent has no way to checkmate, following FIDE rules
Playing
- Two players on one device, or you against the computer as White, Black or a random side
- Move by clicking or by dragging, with mouse or touch
- Legal-move hints, last-move and check highlights, sliding move animations
- A promotion picker with all four pieces
- Optional clocks: 1+0, 3+2, 5+0, 10+0 and 15+10 (minutes + increment in seconds)
- Undo (one move against a friend, back to your turn against the computer), resign, and draw offers in two-player mode
Around the board
- A move list in standard algebraic notation; click any move to review that position
- Captured pieces with the material difference
- Copy the game as PGN or the position as FEN
- The game is saved in the browser and restored after a reload
- Move, capture and check sounds, with a mute button
- Light and dark themes that follow your system setting
- Layouts for desktop, tablet and phone
- Fully playable from the keyboard, with screen reader labels for every square
Computer levels
| Level |
Search depth |
Time per move |
Character |
| Beginner |
1 |
0.3 s |
Plays loose and blunders often |
| Casual |
2 |
0.5 s |
Sees simple tactics |
| Club |
4 |
1 s |
Solid, occasionally imprecise |
| Expert |
6 |
2 s |
Strong tactical play |
| Master |
unlimited |
4 s |
Searches as deep as time allows |
The computer runs in a Web Worker, so the page stays responsive while it thinks. With a clock running, it spends less time per move as its own clock runs low.
Controls
| Input |
Action |
| Click a piece, then a square |
Move |
| Drag a piece |
Move |
Right-click or Esc |
Cancel the current selection or promotion |
← → |
Step back and forward through the moves |
Home / End |
Go to the start / back to the current position |
Tab to the board, arrow keys |
Choose a square |
Enter or Space |
Pick up or drop the piece on the chosen square |
You cannot move while reviewing an earlier position. Press End or Back to game to return.
How it works
src/
engine/ rules: board, move generation, SAN, game state and result detection
ai/ evaluation, search, the Web Worker and its client, difficulty levels
ui/ board rendering, input, panel, dialogs, clocks, sounds, persistence
main.ts entry point
Engine (src/engine). The board is a 64-square array (a1 = 0, h8 = 63) with an incremental 64-bit Zobrist hash for fast repetition checks. Moves are generated pseudo-legally and then checked for legality. Game adds the move history, SAN, PGN export, undo and result detection on top of Position. Correctness is checked with perft: the tests count every reachable position in six standard positions (millions of nodes) and compare against the published results.
AI (src/ai). The search is a negamax alpha-beta search with iterative deepening. On top of that it uses:
- a transposition table
- quiescence search on captures and promotions
- move ordering by the table's best move, most valuable victim / least valuable attacker, killer moves and the history heuristic
- null-move pruning and check extensions
The evaluation uses tapered PeSTO piece-square tables, a bishop pair bonus and a mop-up term that drives a lone king to the edge, so the engine converts won endgames. Lower levels add random noise to the scores at the root, but never enough to miss a mate in one.
UI (src/ui). Plain DOM and CSS, no framework. controller.ts holds all game state and redraws the board and panel from it. Pieces are original inline SVGs, so the game makes no network requests.
Development
| Command |
What it does |
npm run dev |
Start the dev server with hot reload |
npm test |
Run the test suite (Vitest) |
npm run typecheck |
Type-check with strict TypeScript |
npm run build |
Type-check and build to dist/ |
npm run check |
Everything: type-check, tests and build |
The AI speed benchmark is opt-in:
# bash
AI_BENCH=1 npx vitest run src/ai/bench.test.ts
# PowerShell
$env:AI_BENCH = '1'; npx vitest run src/ai/bench.test.ts
It reports nodes per second and the depth reached in two seconds. It searches about 1.6 million nodes per second on a desktop CPU.