Castling works with any rook placement: each castling right remembers
its rook square (Position::castle_rook), set from KQkq (X-FEN, the
outermost rook on that side of the king) or Shredder-FEN file letters.
Castling moves stay king-from to king-destination (g/c file), so move
indices, history tables and the bench are unchanged; make_move lifts
king and rook before placing them, since in 960 their squares can
overlap. Rights are dropped by a king move or a move from or to a
castling rook's square. Generation follows the 960 rules: every square
the king or rook crosses or lands on is empty apart from the two, and
no square the king crosses or lands on is attacked with the moving rook
out of the occupancy (the king's own square included when it does not
move: the rook leaving can uncover the rank). has_legal_move falls back
to full generation for non-standard castling setups.
UCI_Chess960 writes and reads castling as the king taking its rook;
FEN output uses KQkq for outermost rooks and file letters otherwise.
New command perftfile <epd> [depth] runs an EPD perft file.
Checked: the 960 positions of the standard Chess960 perft suite
(fischer.epd) all match to depth 5 (17.6 billion nodes), perftsuite 6
passes, has_legal_move agrees with full generation at every perft node
to depth 4 of the 960 suite, castling both ways over UCI in 960 mode.
Lc0's training data has about 4% Chess960 games, which the policy data
converter now keeps.
Bench: 529903
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The root is where the move is chosen, so it pays to keep more of its
moves in play than deeper in the tree. Monty uses root_cpuct 0.4119
against cpuct 0.2826, a ratio of 1.458; with Rigby's cpuct of 1.6 that
gives a root cpuct of 2.33. The visit scaling applies on top as before.
Exposed as the UCI option RootCPuct (x100) next to CPuct for later
tuning.
Note on the previous commit: Monty's current cpuct_visits_scale is
37.63 (x128 = 4817), not 64; Rigby keeps 8192.
Bench is deterministic. setoption RootCPuct works.
Bench: 529903
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The dashboard keeps the statistics, the principal variation and the
root moves; the board and the knight glyph in the titles are gone. The
statistics take the full width, with the evaluation and time bars
capped at about half of it.
Checked: node-limited UCI output is still identical to main, bench
unchanged.
Bench: 546018
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The terminal output is now a framed dashboard that is redrawn in place
ten times a second instead of a growing list of lines:
- the root position as a coloured board, with the best move's squares
highlighted;
- the score, white's expected score as an evaluation bar, depth, playouts,
speed, time with a progress bar (time or playout limit), tree fill and
notes on tree reuse and collections;
- the principal variation in SAN with move numbers, wrapped and fading
with depth;
- the most visited root moves (SAN) with a bar for their share of the
visits, score and prior;
- a spinner while searching, "done" at the end, and bestmove in SAN.
Each frame moves the cursor back to the top of the previous one and
clears below it; lines the user typed under the dashboard (e.g. stop)
are counted and drawn over. The box adapts to the terminal's width and
height (fewer root moves, then no blank lines, the board only when it
fits). RIGBY_PRETTY=1 forces the dashboard into a pipe.
Checked: UCI output is unchanged (node-limited searches identical to
main, including tree reuse and a stalemate root; time-limited ones
differ only in node counts); go wtime, go infinite + stop and quit
work; the dashboard was driven in a real console, including the redraw,
a reused tree and the switch to UCI, and its colours were checked
rendered to HTML. Search is untouched, so the bench is unchanged.
Bench: 546018
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Started from a terminal, Rigby now shows its search for a human:
coloured progress lines (depth/seldepth, playouts, speed, time, a tree
fill bar, score in pawns, the PV fading with depth) at 125, 250, 500 ms
and then every second, and at the end a table of the most visited root
moves with a bar for their share of the visits, their score and prior.
Tree reuse and collections are shown as notes, and bestmove is
highlighted.
The first "uci" command switches to plain UCI output for good. GUIs and
match runners send it first and read stdout through a pipe, so they
never see the coloured output. NO_COLOR turns it off. On Windows the
console gets ANSI processing and UTF-8 output.
Checked: the UCI output of a scripted session (two searches with tree
reuse, a stalemate root) is identical to main apart from nps and time;
go wtime, go infinite with stop, and quit work; the pretty mode was
driven in a real console, including the switch to UCI. Search is
untouched, so the bench is unchanged.
Bench: 546018
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tree reuse keeps most of the previous tree, so the arena fills up fast.
In a 240-move self-play diagnostic of main at 8+0.08 with Hash=64, the
reused subtree alone was often 3.0-3.3M of the 3.35M nodes, and the tree
was full on 90 moves (37%). A full tree cannot expand anything any more;
for the rest of the move it only re-evaluates leaves.
Now a failed allocation triggers a collection after the playout. The
children of every node below a visit threshold are dropped (the node
keeps its visits and Q and becomes a leaf again, expanded anew on its
next visit), and the rest is packed in place with the same block
compaction as tree reuse. The threshold is the smallest one that brings
the tree down to half the arena; visits only shrink going down, so one
pass over the tree gives the size kept for every threshold.
In the same diagnostic with this change the tree was collected on 27 of
158 moves, once each, and search kept expanding afterwards; a collection
of a full 64 MB tree costs about 20-30 ms.
Checked: the -DRIGBY_VERIFY_TREE build verifies the tree after every
collection; UCI-driven self-play passed 700 checks / 428 collections
with 1 MB Hash and 476 checks / 205 collections with 16 MB, including
repeated searches of the same position and a root at halfmove 99.
uci, go wtime/nodes/infinite, stop and quit work. The bench is
unchanged because the bench never fills the tree.
Rebased from the earlier tree-gc branch onto main with the value
network and second-visit expansion.
Bench: 546018
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The static evaluation behind the quiescence search is now a
(768 -> 128)x2 -> 1 SCReLU network instead of the hand-written
evaluation. It was trained with bullet on linrock's Lc0-derived test80
2024-02 binpack, 40 superbatches (10 min on an RTX 3070), final loss
0.0220. The quiescence search itself is unchanged.
The network is embedded with incbin (EVALFILE, default
networks/rigby-value-v1.bin). Q is tanh(cp / 800), the same scale the
network was trained on (sigmoid(cp / 400) = expected score).
Checked: bullet's float evaluation of fixed positions (trainer --check)
and the engine's quantised inference (evalfens) agree within 6 cp; an
integer re-implementation in Python matches the engine exactly. Perft
passes, bench is deterministic.
Bench: 545914
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the new position continues the previous game, find its node in the
old tree (matching the keys of the positions played since) and make it
the root. Its subtree is packed to the front of the arena in place: child
blocks are always allocated after their parent's, so moving the kept
blocks in their original order only moves them towards the front.
A root that was a draw inside the old tree (repetition, 50 moves) or was
never expanded starts afresh. ucinewgame and Hash changes drop the tree.
Built with -DRIGBY_VERIFY_TREE, the engine checks every tree before and
after reuse (legal moves, visit counts); 2900+ such checks over self-play
games, with 16 MB and 1 MB hash, found no inconsistency.
Bench: 546127
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bitboard board with fancy magics and fully legal move generation, checked
by a perft suite. PUCT search over a node arena with FPU reduction and
in-tree draw detection. Hand-written value (eval + quiescence) and
heuristic policy stand in until the network is trained. UCI loop with a
search thread, OpenBench-compatible bench and Makefile.
Bench: 546127
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>