Skip to main content
Image

r/chessprogramming


Chess Engine Development Help Thread (Week 26)


Summer just got a whole lot more fun at Build-A-Bear. From mini pals to quirky new friends, our newest summer collection is here with something for everyone.
Image Summer just got a whole lot more fun at Build-A-Bear. From mini pals to quirky new friends, our newest summer collection is here with something for everyone.


Critical Moment: how we filter chess positions where only one move works
Critical Moment: how we filter chess positions where only one move works
Technical

the Stockfish-plus-Maia selection pipeline, the difficulty formula, and the thresholds a position must pass to enter the section.

We launched https://kingside.site/critical-moment — a training section built around positions with one strong move that even a strong neural net misses. This article is the internals: what Stockfish computes, what Maia computes, the thresholds, and why a puzzle keeps running only as long as its difficulty holds. Audience — players 1500+ and coaches who want to see the mechanics.

What counts as a Critical Moment

A half-position where simultaneously:

  • exactly one move sits at the top of the WDL evaluation (|strongSet| = 1),

  • Maia 2400 estimates the probability of a human finding it at < 10%,

  • there is a meaningful WDL gap to the second candidate (gap ≥ 0.2),

  • no "safe weak move" exists — playing badly costs the game (lossRisk ≤ 0.5).

All conditions are formal. No manual tagging, no categories ("combination", "endgame", "sacrifice"). Thresholds pass — the position joins the pool. Any one fails — it is dropped.

The selection pipeline

Source — modern classical games rated 2600+ from TWIC. Every position runs through the pipeline.

Step 1. Stockfish, MultiPV = 10, two passes. First — fast, 1,000,000 nodes — discards obviously equal or already lost positions. If the top three WDL values are close, no "only move" candidate exists. Second — deep, 10,000,000 nodes — on the survivors. Stockfish returns a stable WDL value for all ten moves; we build strongSet — the set of moves whose WDL differs from the best by no more than gap = 0.2. To pass we require |strongSet| = 1.

Step 2. Maia ONNX, ELO 2400. Maia is a neural network trained to imitate human players at a fixed rating. Inference runs via ONNX Runtime; the model returns a policy distribution — what a 2400 player would play. Difficulty:

difficulty = 1 − Σ policy(m), m ∈ strongSet

The probability that a 2400 player fails to find any strong move. With |strongSet| = 1 this reduces to 1 − policy(bestMove). Threshold — difficulty > 0.9.

Step 3. Trap protection. We also compute lossRisk — the total probability that the player picks a move whose WDL leads to a loss. Threshold — lossRisk ≤ 0.5: the position must be hard, not a coin flip. The section is about reasoning, not gambling.

How this differs from classical puzzles

Classical puzzles use a simple criterion: a forced sequence wins material or mates, and you can spell out the variations. Critical Moment uses a different one — the move is simply best. It can be prophylaxis, a piece transfer, a trade, a pawn-structure change — anything Stockfish sees as the only path and Maia treats as out of reach for a human. Hence no difficulty grades and no categories: all positions pass the same thresholds, there are no "easy" puzzles by definition.

How the puzzle itself runs

After the user's move the position changes. To keep the puzzle alive, the new position must satisfy the criterion again. The check happens in the browser — via the same selection module used on the server, reused from packages/shared: Stockfish WASM + Maia in ONNX Web Runtime.

Loop on every half-move:

  1. Player plays a move.

  2. Move outside strongSet — puzzle ends as a failure.

  3. Move correct — the new position is re-evaluated: strongSetdifficultygaplossRisk.

  4. All thresholds pass — the engine replies and the loop continues.

  5. Any threshold fails (position "cooled down", became technical, reached mate) — puzzle ends as a success.

Puzzle length is a consequence of the position, not a tag. Sometimes one half-move, sometimes six.

Try it

Available at https://kingside.site/critical-moment. No login required for a single run; stats and history — for signed-in users.