Commit Graph
9 Commits
Author SHA1 Message Date
rektdieandclaude bf62fe185f feat: hard time limit for moves still open at the soft limit
With smart pruning most searches stop early and the clock piles up:
after move 40 of 8+0.08 self-play about 5 s of the 8 s were left. A
diagnostic of 202 searches showed 190 settled early; the 12 that reached
the time limit were the open ones (the best move had a median 50% of the
root visits, and was the best by Q in only 3 of 12).

So reaching the soft limit (the old allocation) is itself the sign of an
open move. Under a game clock such a search now runs on, with smart
pruning measured against a hard limit of min(3 x soft, remaining / 3),
until it settles or reaches that limit. movetime, nodes and infinite are
unchanged (their hard limit is the soft one).

Self-play diagnostic at 8+0.08 (3 games, 80 plies), main -> this:
average time per move 152-156 -> 162-189 ms, longest move about 350 ->
860-1040 ms, clock left after move 40 4.8-5.4 -> 2.4-5.0 s. go movetime
500 still stops at 480 ms; a 300 ms clock uses 6 ms.

The bench is unchanged: it searches by playout count.

Bench: 554375

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:01:27 +01:00
rektdieandclaude 6da27e2fad feat: smart pruning stops clock searches whose best move is settled
Under a game clock a search now stops early when no other root move can
catch up with the leading one in the playouts the remaining time still
allows (at the speed so far, divided by Lc0's smart-pruning factor
1.33). The saved time goes to later moves, whose allocation is a share
of the remaining clock. movetime, nodes and infinite searches are not
affected.

Only the visits gained in this search count, and the move leading them
must also be the most visited overall. Counting the reused tree's visits
stopped almost every search at once: the reused best move often has
hundreds of thousands of visits no rival could reach (a first version
spent 39 ms per move instead of 230 in self-play at 8+0.08).

Self-play diagnostic at 8+0.08 (3 games, 80 plies), main -> this:
average time per move 230 -> 157 ms, clock left after move 40
2.0 s -> 4.6-5.2 s.

The bench is unchanged: it searches by playout count.

Bench: 554375

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 15:47:04 +01:00
rektdieandclaude 0f1657eb00 feat: butterfly history added to the policy logits
Rigby's policy is a hand-written heuristic, so it often ranks moves
badly in ways the search itself finds out. Following Vine's butterfly
history for MCTS (aronpetkovski.com/blog/butterfly-history-mcts: +10
Elo in Vine, about +6 in Monty, +34 in Jackal):

- a [side][from][to] table of i16, cleared on ucinewgame and kept
  between the moves of a game like the tree;
- every playout scores each move on its path with the playout's result
  for the side that played it, converted to centipawns
  (q_to_cp(clamp(Q, +-0.998)), i.e. the inverse sigmoid on the 400
  scale), with gravity: entry += bonus - entry * |bonus| / 8192;
- on expansion, entry / 16384 is added to each move's policy logit
  before the softmax. The priors are a snapshot; later updates do not
  change them.

Constants are Vine's, no tuning.

Checked: after 50k playouts the root moves' entries make sense (Qxf7#
at +8192, queen-losing moves at -5000 to -7800). The
-DRIGBY_VERIFY_TREE build passed 477 tree checks with 297 collections
at 1 MB Hash. Bench is deterministic.

Bench: 555674

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 15:20:42 +01:00
rektdieandclaude c859163e2c feat: live framed search dashboard for a terminal
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>
2026-11-15 14:30:47 +01:00
rektdieandclaude 6490286852 feat: coloured search output for a terminal
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>
2026-11-15 14:15:49 +01:00
rektdieandclaude 967e0e0b90 feat: collect the tree when the node arena is full
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>
2026-11-15 10:52:06 +01:00
rektdieandclaude cdeb318016 feat: expand nodes on their second visit
Most leaves are visited only once. Their first visit now only settles
terminal states and evaluates the position; the move list, the priors
and the child nodes are created when search comes back a second time.
The root is expanded before the first playout, so a search always has a
move.

With the value network the tree is full on nearly every move at
8+0.08 with Hash=64 (hashfull 1000 in a 30-ply self-play diagnostic);
with this change many moves stay at 320-890. The -DRIGBY_VERIFY_TREE
build passed 1700 tree checks in UCI-driven self-play with 1 MB and
16 MB Hash, and a 1-playout search still returns a move.

Rebased from the earlier expand-second-visit branch onto the network
main, without the tree collection it was built on.

Bench: 546018

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 04:21:06 +01:00
rektdieandclaude 5c017ee43f feat: reuse the search tree between moves
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>
2026-11-15 01:23:42 +01:00
rektdieandclaude d3044c0b88 feat: minimal MCTS engine with UCI
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>
2026-11-15 00:31:20 +01:00