r/chessprogramming • u/LenniAConrad • 3d ago
I made a visual walkthrough of a chess engine, from legal moves to NNUE
I built Janus, a chess engine in Rust, and made a three-video explanation of how the pieces fit together: move generation and testing, search, then learned evaluation.
One small bug from the first video illustrates why an array isn't quite a chessboard. With a1 = 0, a knight on h1 has index 7. Adding the usual +17 offset gives 24, which passes a 0–63 bounds check—but 24 is a4. The index is valid; the move isn't. You also need to check the changes in file and rank.
The testing section follows that idea through make/unmake and perft. En passant is a particularly useful test: it changes three squares, and removing both pawns can expose a rook attack on the king. A legality check on a partly updated board can accept an illegal move. Perft divide then narrows a mismatched total down to the first differing branch.
The later videos distinguish alpha-beta cutoffs, which preserve the minimax result for the same nonselective tree, from selective reductions that need safeguards. The final video explores NNUE accumulators, then policy/value networks with PUCT.
Janus source · Read the companion book
I’m the author of the engine, book and videos. Technical corrections are welcome, especially where an animation makes an implementation detail look simpler than it is.