Chess Engine — Watch Minimax Think
Real chess engine in pure JS — minimax, alpha-beta, transposition tables — with a live search-tree visualization beside the board. Watch the AI's mind work.
What this is
A standard chess board with Unicode pieces (drag-drop, legal-move dots, capture rings, check glow on the king, last-move highlight) sitting next to a live search-tree visualization. The engine is real: 0x88 board representation, negamax with alpha-beta pruning, iterative deepening, a 32-bit Zobrist transposition table used for both cutoffs and move ordering, MVV-LVA capture ordering, and an evaluator combining material, piece-square tables, doubled/isolated/passed pawns, king-file safety, and an endgame king-activity table. As the AI thinks, the tree on the right blooms — branches grow from root to candidate moves, node size scales with visit count, color maps eval (red blunder → green winning), the principal variation glows green and pulses, alpha-beta cutoffs render as dashed branches that stop expanding. Verified via perft to depth 4 (197,281 nodes).
Why this is mind-blowing
Most chess engines are black boxes. Watching the search expand in real time — pruning visibly, hashing visibly, focusing on the principal variation — turns minimax from an exam topic into a thing you can see breathing. One HTML file holds an engine that can beat a club player and a visualization that teaches them why.
Single-file chess game with a real chess engine in pure JS. Minimax with alpha-beta pruning, depth 4-6 ply, material + position evaluation. As the AI thinks, visualize the search tree on a side panel — nodes expand, alpha/beta cuts highlighted, principal variation glows green. Standard chess rules (castling, en passant, promotion). Drag-drop pieces.
Paste this into Claude, Cursor, or Copilot. Change one thing that matters to you.
What I learned shipping it
- Make/unmake with incremental Zobrist XOR is non-negotiable for any real search engine — building a fresh hash every node murders performance and re-implementing it under bug pressure murders sanity.
- Perft testing through depth 4 (197,281 nodes for the start position) is the tightest check that castling, en passant, promotion, and check-legality are all correct. If the count matches, the move generator is right.
- Visualizing alpha-beta as dashed branches that stop expanding makes pruning legible — students see why ordering matters within seconds.