Skip to content

UCI: go nodes, full node counts and FEN validation - #65

Merged
nook0110 merged 10 commits into
deploy-elofrom
uci-nodes
Nov 12, 2026
Merged

nook0110 merged 10 commits into
deploy-elofrom
uci-nodes

Conversation

@nook0110

@nook0110 nook0110 commented Nov 8, 2026

Copy link
Copy Markdown
Owner

Stacked on #63 (it uses the typed ParseLegalMove from there); merge #63 first, then retarget this PR to deploy-elo if GitHub does not do it automatically.

What changes

  • go nodes N stops the search once main plus quiescence nodes reach N, shared across threads. With one thread a fresh engine gives the same best move and node count every time.

  • info nodes now counts main plus quiescence nodes, the same total nps uses. The non-standard info quiescence_nodes line is gone.

  • FEN validation: PositionFactory::TryParse parses a FEN once and returns std::nullopt for a malformed or unrepresentable position:

    • a garbage board;
    • two kings;
    • a pawn on the back rank;
    • a castling right without its rook;
    • an en passant square without a pushed pawn.

    The UCI handler also rejects positions where the side to move can capture the king. A rejected FEN prints info string invalid fen … and keeps the previous position. Before the first position command the engine now holds the initial position, not an empty board. Shredder-FEN castling files are still ignored, as before.

  • Tests:

    • explicit cases for each rejection;
    • a fixed-seed randomized batch of malformed FEN/move/go/setoption input, which also passes under ASan/UBSan;
    • a longer uciok wait in the Lazy SMP test, which once needed 34 s to start on a loaded machine.

Proof that search is unchanged

  • Asm vs Track move legality in the type system #63 (LTO gate build):

    • SearchNode<TimeCondition> (used in games): only stack slots are reassigned.
    • Pondering nodes: gain only the node-budget compare in their DepthCondition branch, with the same calls and stores.
    • Fixed-depth nodes: gain the budget check.
    • DoMove and NNUE Evaluate: inlining and register reshuffles from the larger program. Perf below shows no cost.
  • Search identity: 30 positions at depth 11 give the same best moves and the same 7,274,560 nodes as Track move legality in the type system #63.

  • Perf (CPU 19, alternating):

    Track move legality in the type system #63 this PR
    instructions/node 11,694–11,698 11,710–11,714 (+0.1%)
    cycles/node 12,871–13,005 12,969–12,978 (noise)
  • Perft: unchanged, startpos d5 4,865,609 and kiwipete d4 4,085,603.

  • Bench: with Track move legality in the type system #63 and Search bench signature, stronger CI and debug self-checks #64 merged, bench still gives Bench: 2709383, so all commits carry that line.

  • Tests: all 206 ctest tests pass. That includes SharedClusterTable.ConcurrentEntriesStayConsistent and the Lazy SMP lifecycle test, which used to be excluded locally. BestMove.WinAtChess stays excluded, as in CI: it is a strength test with a wall-clock budget.

🤖 Generated with Claude Code

nook0110 and others added 5 commits November 9, 2026 02:02
"go nodes N" stops the search once main plus quiescence nodes reach N.
The limit lives in DepthCondition as a NodeBudget shared by all search
threads, counted through a CountsNodes hook that compiles to nothing
for the other exit conditions. With one thread a fresh engine process
gives the same best move and node count for the same command; the info
lines report the nodes of the last completed iteration.

The clock-controlled search used in games adds no instruction, call or
store: the TimeCondition search nodes differ from the base only in
stack slot assignment, and the Pondering ones gain only the budget
compare in their DepthCondition branch. Fixed-depth search stays
node-for-node identical on 30 positions at depth 11 and costs 0.07%
more instructions per node for the counter check.

Bench: 2709383

Co-Authored-By: Claude Opus 5.5 <[email protected]>
"info nodes" now counts main plus quiescence nodes, the same total that
"nps" is computed from. The separate "info quiescence_nodes" line is
gone; no tool or test reads it.

Search is unchanged: the same 30 positions at depth 11 give the same
best moves, and each new node count equals the old main plus quiescence
count.

Bench: 2709383

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test waited 15 seconds for "uciok". An idle start takes about a
second, but on a loaded machine a cold start once took 34 seconds. The
wait is now 60 seconds.

The other two tests that were excluded locally do not need changes:
SharedClusterTable.ConcurrentEntriesStayConsistent passed every run in
a few milliseconds, and BestMove.WinAtChess is a strength test with a
wall-clock budget per position, so it stays excluded as in CI.

Bench: 2709383

Co-Authored-By: Claude Opus 5.5 <[email protected]>
"position fen" used to read any string into a Position: a garbage board,
a pawn on the back rank, two kings, a castling right without its rook
or an en passant square without a pushed pawn all produced a corrupt
position for the search. PositionFactory::TryParse now parses the FEN
once and returns std::nullopt for anything the engine cannot represent,
and the UCI handler also refuses positions where the side to move could
capture the king. A rejected FEN is reported with "info string invalid
fen" and keeps the previous position. Before the first "position"
command the engine now holds the initial position instead of an empty
board.

Shredder-FEN castling files (A-H, a-h) are accepted and ignored, as
before. Valid FENs give the same Position as before: perft and the
fixed-depth search checks are unchanged.

Bench: 2709383

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A fixed-seed batch of mutated FENs, illegal or truncated moves and
garbage go and setoption arguments runs through one engine process and
checks that the engine neither crashes nor changes its position. It
takes about ten seconds in Release and also passes under
AddressSanitizer and UndefinedBehaviorSanitizer.

Bench: 2709383

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nook0110
nook0110 changed the base branch from move-legality-types to deploy-elo November 12, 2026 00:11
nook0110 and others added 4 commits November 12, 2026 04:09
Bench: 696698

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Bench: 696698

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Restore compiler-selected inlining for the time condition while retaining the typed node-budget search.

Bench: 993713
@nook0110
nook0110 merged commit d7dbfac into deploy-elo Nov 12, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant