Build a Chess Engine — hardcover edition, 3D view
Build · Verify · Measure

The Book, Running

A taste of every part of Build a Chess Engine — live in your browser

Fourteen interactive stations following the book’s own arc: represent the position, generate and prove the moves, search with alpha-beta and transposition tables, evaluate, speak UCI, measure with SPRT, extend into NNUE and policy-value MCTS, then go beyond the engine into notation, puzzles, and analysis. One board position flows through the stations that operate on the live game — the derivations live in the book.

Part One The Board

One position, three representations.

Everything starts with how the position is stored. The same board can be a piece list, a square-centric mailbox, or twelve 64-bit bitboards — each makes different questions cheap. These views track the live board below.

In the book — Part One derives all three representations — and when each one wins.

Try Flip to Bitboards, then run the step-by-step generator below.

Bitboard move generation, step by step

Every legal move, and nothing else.

Click a piece to see its legal moves — castling, en passant, promotions, pins, and checks all handled. This board is the source position for the live stations on this page.

In the book — Two chapters build this generator rule by rule: pins, en passant, castling and all.

Try Castle both ways from the start position · promote a pawn on Position 4.

Mode Analyze: you move both sides. Against the engine: depth 3 with quiescence.
 

Moves played

No moves yet — click a piece to begin.

Legal moves here:

Prove the move generator.

Perft walks every legal move sequence to a fixed depth and counts the leaves. One wrong castling rule, one missed en-passant pin, and the totals diverge — every move generator in this book must prove it. Known reference values are checked automatically.

In the book — The book treats these tables as law — every move generator must reproduce them exactly.

Try Depth 5 on the start position — 4,865,609 nodes, checked live.

Depth
Part Two Search & Evaluation

The same position, reached twice, searched once.

Different move orders reach identical positions. A Zobrist hash names each position in one 64-bit number, and a transposition table lets the search recognize work it has already done.

In the book — Zobrist hashing, table bounds, and the subtle bugs they cause have a chapter of their own.

Try Show a transposition, then search with the table on.

Zobrist hash of the board position

Play a move on the board and this hash changes; return to the same position by a different move order and it comes back exactly.

Search with the table on

Never evaluate in the middle of a capture.

A fixed-depth search stops mid-exchange and believes the material it just grabbed is free — the horizon effect. Quiescence search keeps resolving captures before trusting the evaluation.

In the book — The horizon effect and its cure, with worked traces from a real engine.

Try Load the horizon position and watch depth 2 pick the wrong capture.

Results appear here.

What the engine thinks a square is worth.

The classical evaluation is material plus piece-square tables: a knight on the rim is worth less than a knight in the center before any search happens. Pick a piece to see its table — and play a move on the board here to watch the bar react.

In the book — From these tables to a full evaluation, term by measured term.

Try The knight’s table — rim against center.

Greener = bonus, redder = penalty, from White’s side.

Current position — play a move

Centipawns from White’s perspective — +100 ≈ one pawn ahead: the signal a GUI evaluation bar shows, before any search. This is the same live game as the main board — move a piece and the bar reacts.

Part Three Protocol & Measurement

Speak the protocol every GUI understands.

An engine is a program that reads lines and writes lines. This is a real UCI session against this page’s own small engine — click a command to send it and read the reply.

In the book — The complete protocol, one responsive worker, and a GUI-ready engine.

Try position startpos moves e2e4 e7e5, then go depth 3 — the engine answers with its search and best move.

Is the new version actually stronger?

A faster program is not a stronger engine, and a won match is not proof. SPRT plays paired games with colors swapped, buckets the pairs into five outcomes, and stops exactly when the evidence crosses a bound. Set the true strength difference and watch the test decide.

In the book — Fixed-work benchmarks, paired openings, SPRT — measurement without mythology.

Try Set +2 Elo and watch how long the test refuses to decide.

Part Four Neural Networks

Evaluation as a network you update, not recompute.

NNUE’s trick is incremental: a move changes a handful of input features, so the first layer’s sums are patched rather than rebuilt. Play moves on the board and watch which accumulator values change.

In the book — The architecture, the data contracts, and the training roadmap — honestly scoped.

Try Castle on the main board — four features flip at once.

Search guided by belief, refined by visits.

AlphaZero-style search: a prior policy suggests moves, a value estimate scores leaves, and visit counts concentrate on what keeps proving good. Run playouts on the live board position.

In the book — Policy, value, and search united: the AlphaZero design, in engine terms.

Try +500 playouts, then read the visit distribution.

Part Five Beyond the Engine

Games are data.

FEN names a position; PGN records a game. Anatomy of the live position’s FEN below, and a PGN replayer loaded with Morphy’s Opera Game — paste any game to step through it.

In the book — Databases, PGN tooling, and analysis software fill the book’s closing part.

Try Step to the end of the Opera Game.

The live FEN, field by field
Replay board

Tactics, verified by the engine.

Eight engine-verified mates. Find the move on the puzzle board — the same move generator that passed perft judges your answer.

In the book — The closing chapters show how to mine and verify tactics from real games.

Try Puzzle 6 is a smothered mate.

See what a position says.

The book closes with software that shows chess rather than plays it. Attack maps of the live position: every square colored by who controls it. The board is live — move a piece and watch the map redraw.

In the book — The closing chapters build this analysis software in full — where the book ends.

Try Contested control after 1.e4 e5.

Reading the map

Only in the book.

This page shows the algorithms moving. The book is where they are built — 442 pages, every subsystem derived, tested, and measured. None of the following is on this site:

  • The complete derivations — every mask, every invariant, every edge case, with the reasoning
  • Make/unmake, state snapshots, and the reversibility discipline that makes engines debuggable
  • Bug Laboratories: broken engines to diagnose, with worked diagnostic traces
  • Move ordering, iterative deepening, time management, and the clock that never loses on time
  • A UCI engine built around a responsive worker — GUI-ready, release-packaged
  • Fixed-work benchmarks, paired openings, confidence intervals — the full measurement discipline
  • Janus case studies from a real engine, including the ideas that failed or stayed inconclusive
  • NNUE and policy-value MCTS as implementation roadmaps: architectures, data contracts, training pipeline
  • Databases, opening explorers, annotation, puzzle mining, and chess-software products
  • Predict exercises throughout, plus a separate answers workbook