Overview
The Engine Pipeline
Foundation
Bitboards: Chess on 64 Bits
Each 1 bit = a square occupied by that piece type. Bitwise AND/OR/XOR updates the board in nanoseconds. Board shown rank 8 (top) to rank 1 (bottom), matching the a1=0 index used by the engine.
- Generate knight moves with a few lookups + bitwise ops
- Popcount finds how many pieces attack a square
- Sliders use magic bitboards (see Layer 2)
- Industry standard since the 2000s (Crafty → Stockfish lineage)
Deep Dive
Six Layers Inside the Engine
Store the position as 12 × 64-bit integers — one bitboard per piece type per color — plus derived occupancy boards (all white, all black, all pieces), castling rights, en passant square, and side to move.
Leapers (pawn, knight, king) use precomputed [64] attack tables. Sliders (bishop, rook, queen) use magic bitboards: multiply occupancy by a magic number, shift, index into a prebuilt attack table — O(1) sliding attacks.
Generate pseudo-legal moves (pushes, captures, promotions, castling, en passant), then filter illegal ones by making the move and checking if the king is in check. Must handle castling through attacked squares correctly.
| Depth | Nodes (perft) |
|---|---|
| 1 | 20 |
| 2 | 400 |
| 3 | 8,902 |
| 4 | 197,281 |
| 5 | 4,865,609 |
| 6 | 119,060,324 |
⚠ Golden rule
Never write search until perft matches known node counts from the standard starting position. Move-gen bugs corrupt every evaluation above them.
Score a position in centipawns without searching deeper. A simple modern engine uses material plus tapered piece-square tables (separate midgame/endgame tables blended by remaining material phase).
The brain. Iterative deepening drives negamax with alpha-beta pruning. At leaf nodes, quiescence search (captures only) prevents horizon effect. A transposition table caches scores; move ordering (TT move, MVV-LVA, killers, history) makes pruning effective.
Text commands on stdin/stdout. The GUI sends position and go; the engine searches on a background thread and replies with info lines (depth, score, PV, nps) and finally bestmove.
Search Visualized
Alpha-Beta Prunes the Tree
Practical Guide
Build Order (Don't Skip Steps)
Reference
Layer Cheat Sheet
| Layer | Input | Output | Key idea |
|---|---|---|---|
| Bitboards | FEN / moves | Occupancy masks | 64-bit sets, popcount, bitwise ops |
| Attacks | Square + occupancy | Attack bitboard | Magic multiply-shift-index |
| Move gen | Position | Move list | Pseudo-legal then king-safe filter |
| Eval | Position | Score in cp | Material + tapered PST |
| Search | Position + depth | Best move + PV | αβ + TT + QSearch + ordering |
| UCI | Text commands | bestmove + info | Std protocol for all GUIs |
Simple vs. superhuman
A simple modern engine implements every layer correctly but keeps evaluation and search extensions modest — architecturally identical to Stockfish, just smaller nets and fewer terms. Strength comes from better eval (often NNUE) and deeper search refinements built on this same skeleton.
Keep exploring chess tech
Pair engine architecture with tactics training and analysis tools on FujiBit.
Related: All Blogs · Chess Tools Hub · Magic of Chess Tactics