Commit Graph
68 Commits
Author SHA1 Message Date
rektdieandclaude b7bfb0b916 mcts: score an edge that repeats the current path as a draw in selection
26.8 % of playouts at 5 s (without the perpetual-check position) end in a
draw of their path, 30 % in KR v K, where the root score falls to 739 cp
against main's 1701: a shared node's Q says nothing about whether going
there now repeats this path.

Selection now gives Q = 0 to an edge whose child position already occurred
on this playout's path or in the game, with the same side to move, within
the reversible window. The window keys are collected once per selection
(3, 5, ... plies back, up to the half-move clock) behind a 64-bit filter, so
most children need no search. The exploration term is unchanged, and if
the edge is still chosen the draw is recorded as before.

The bench changes because selection avoids repetitions.

Checked: zero warnings; VERIFY build: `verify` (a)-(d), the VERIFY searches of plan section 6 with forced GC at Hash 1 and 2, the reuse sequence at Hash 64, Hash 1 and from the 960 start, and the go nodes 1/2, go depth 1 smoke positions.

Bench: 755448

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 21:36:02 +01:00
rektdieandclaude 95e49098ec docs: 5312 result and step 3b (reroot, test 5313) in mcgs-log
Bench: 764208

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 21:20:26 +01:00
rektdieandclaude d38f0b133a mcts: reroot moves only the root index (no compaction between moves)
Step 3 rerooted by compacting what the new root reaches (plan 3.6.6,
mark/compact with T = 0). In a graph, a reversible endgame keeps almost the
whole graph reachable from the new root, so every move paid O(graph) before
its first playout. Replaying a 2+0.02 game that step 3 lost on time (Hash 16,
rook endgame, half-move clock about 70): the reroot averaged 3.3 ms per move,
max 14.5 ms, against 0.3 ms for main. Under load that is more than the
increment, and step 3 ran out of time in 2 of 100 games.

Now reroot only sets the root. Nodes the new root no longer reaches keep
their memory and their table entries (search may link to them again) until
the next collection, which keeps only what the root reaches. In the same
replay, the time before the first playout is 0 ms on average.

VERIFY: verify_tree requires every node to be reachable only right after a
collection; the table must always hold every node of the arena. Check (b)
now checks that a reroot changes nothing and that the next collection keeps
exactly the nodes the new root reaches, unchanged.

Checked: zero warnings, bench unchanged (bench never reuses a graph),
`verify` (a)-(d), the VERIFY searches of plan section 6 including forced GC
at Hash 1 and 2, the reuse sequence at Hash 64, Hash 1 and from the 960
start, and the go nodes 1/2, go depth 1 smoke positions.

Bench: 764208

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 21:19:17 +01:00
rektdieandclaude f4b79a472c docs: step 3 SPRT is test 5312 (STC vs main) in mcgs-log
Bench: 764208

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 20:59:36 +01:00
rektdieandclaude 62e5923254 docs: step 3 SPRT links (tests 5310 STC, 5311 LTC) in mcgs-log
Bench: 764208

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 20:45:48 +01:00
rektdieandclaude 98fae48886 docs: step 3 (MCGS core) in mcgs-log: gates, time forfeits, measurements
Bench: 764208

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 20:40:44 +01:00
rektdieandclaude 14f672a666 verify: checks (c) repetition leak and (d) table after GC and reroot
(c) searches five positions with forced or frequent repetitions and
50-move draws (the knight shuffle in the game history, the perpetual-check
bench position, KR v K at half-move 95, and two pawn endgames), checks every
node state from its position alone (verify_tree), and requires the draws to
show up as edge draw counts, the 50-move ones included.
(d) reports the table against the surviving nodes after every forced
collection and reroot of (b); verify_tree checks it in full.

VERIFY builds only. Bench: 764208 (unchanged)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 20:25:11 +01:00
rektdieandclaude 6ec8769555 mcts: Monte-Carlo graph search core (MCGS step 3)
Bench: 764208

One node per position, found through a key table, as in docs/mcgs-plan.md
sections 3.1-3.5 and 3.6.5:

- Key table: open addressing with linear probing over 8-byte slots
  {key_hi, node}, a power of two of at least twice the node arena. A hit
  needs the full 64-bit key and the node's 16-bit check (about 80 bits).
  It is rebuilt from the survivors after every collection and reroot.
- create_node: a position's first visit creates and evaluates its node
  (checkmate, stalemate, insufficient material except at the root, then
  ValueHash, then the net) with N = base = 1, q = u. The root is created
  and evaluated through it.
- Descent: after make_move, repetition and the 50-move rule (mate first)
  are judged before the lookup and recorded only as the edge's draw count.
  An edge is linked on first selection, to an existing node when the
  table has one. MAX_PLAYOUT_DEPTH = 512 guards against key collisions.
- Backprop: each path edge counts the visit (and the draw), each path
  node recomputes q = (base*u - sum (N-D)*c.q) / N, summed in double.
  ValueHash is stored for every path node; butterfly history as before.
  A playout whose node allocation fails is dropped and the graph collected.
- Selection, best move, smart pruning, score, PV and dashboard read edges,
  with path draws counted as 0. The PV stops after a repeated position.
- The root's edges are checked against its legal moves at search start;
  the graph is cleared otherwise.
- GC threshold: visited bitmap and the root counted apart, so the estimate
  stays an upper bound on a DAG.
- Hash: node arena, edge arena (8 edges per node, unchanged) and the
  table share the graph's budget; the table's power of two is rounded
  down or up, whichever leaves more nodes.
- VERIFY: verify_tree checks the graph per plan 3.8 (keys, table, states
  from the position alone, edges, N = base + edge visits, q = u on
  leaves); check (b) of `verify` identifies nodes by key.

The bench changes (663779 -> 764208) because the tree becomes a graph:
transpositions share nodes, so playouts run through existing nodes and
their depths and the positions they visit change; the root gets its own
evaluation and N = 1 + the edges' visits; and repetitions and the 50-move
rule are judged on every playout instead of once per node.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 20:25:02 +01:00
rektdieandclaude 5424e1a1ce docs: step 2 (Edge/Node split) in mcgs-log: gates, arena split, NPS
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 20:06:09 +01:00
rektdieandclaude fb1b8a5b93 mcts: document the arena split (8 edges per node)
Measured over the 16 bench positions at 5 s, Hash 64 (local, single
runs): collections main 200; edges per node 4: 217, 6: 183, 8: 184,
13: 184, 20: 249. 13 cut middlegame collections further but gave 2-3x
more in the endgames; 8 stays close to main everywhere.

Bench: 663779

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 19:42:32 +01:00
rektdieandclaude 226106e50a verify: add the verify command to VERIFY builds (checks a and b)
(a) Along random games from standard and Chess960 positions (50 games of
up to 300 plies from each of 7 FENs), the incremental key and the position
check equal those of the same position set up from its FEN.

(b) After a 30000-playout search on four positions (standard, middlegame,
pawn endgame, Chess960): three forced collections down to 1/2, 1/4 and 1/8
of the tree, each compared with a snapshot taken by move path (visits, q,
u, base, state, key, check, and every edge). Survivors must be unchanged,
pruned nodes must keep visits and q with u = q and base = visits, both
arenas must end within their targets, and no pruned node may have more
visits than a kept one. Then a reroot two plies down the best line must
keep that subtree exactly. verify_tree runs after each step.

Only compiled with -DRIGBY_VERIFY_TREE. Bench: 663779

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 19:37:17 +01:00
rektdieandclaude 6629525938 mcts: split Node into Node and Edge arenas (MCGS step 2)
The tree now has two arenas. An Edge (16 bytes: child, visits, draws, move,
policy) is written for every legal move at expansion; a Node (32 bytes: key,
first_edge, visits, q, u, base, num_edges, state, check) is created only
when its edge is first selected, and evaluated on that visit.

Search is unchanged: edge visits are kept equal to the child's visits, and
selection, FPU and the root decisions read edge.visits and edge.policy with
the child's q, in the same float order. Path-dependent draws stay in
node.state. key and check are set at node creation, u and base by pruning;
nothing reads them yet, and edge.draws stays 0.

The root index is a member. Garbage collection and rerooting use
mark -> forwarding -> slide -> remap over both arenas, which no longer
assumes that a block is allocated after its parent's. The threshold rule is
the tree-exact one, with a histogram per arena; a pruned node keeps its
visits and q. A playout that finds the node arena full ends at the parent,
like a failed expansion, and schedules a collection.

VERIFY builds check the whole tree after every reroot, collection and
search: in-degree 1, nothing unreachable in either arena, key and check,
the node state recomputed from the position and its path, one edge per
legal move, edge visits equal to the child's, and |q|, |u| <= 1.

info string reused now counts nodes (positions), not child slots.

Bench: 663779

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 19:37:10 +01:00
rektdieandclaude 18911b0388 tests: add Chess960 perft suite (fischer.epd, 960 positions, D1-D6)
sha256 4bc384f273d8ce9312bfde78484dce503c8d1b51b43aacc6352646b3c270b3cd.
Run with: perftfile tests/fischer.epd 5

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 19:25:11 +01:00
rektdieandclaude 479f6cfb2f docs: step 1 measurements (stats build) in mcgs-log
mcgsstats 1000, 5000 and 5000 16, plus an extra no-GC run at Hash 1024
for the edges-per-node growth ratio. Derived bounds, the ValueHash
cross-check (leaf_tt 54-66 % overall, inside 37-85 %) and the arena
split input for step 2. Stats-build numbers, local machine.

Bench: 663779

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 19:23:37 +01:00
rektdieandclaude fc0a3a8fec docs: MCGS plan approved, steps merge into main one by one
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 19:05:20 +01:00
rektdieandclaude 4a4338dd9a docs: MCGS plan with the owner's answers
Book and adjudication from tests 5307-5309 (UHO_Lichess_4852_v1.epd),
LTC 40.0+0.40 at Hash 256 since Rigby has no LTC preset yet, the stats
branch is never merged, and the Chess960 perft suite (found in an old
session scratchpad, passes depth 5 on main) gets committed by step 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 19:02:56 +01:00
rektdieandclaude 18bd529609 docs: MCGS research summary and implementation plan
Research on graph search (KataGo, Czech et al., Lc0 dag_classic, Ceres,
Monty, GHI literature) and the design for turning Rigby's MCTS into
Monte-Carlo Graph Search: 16-byte edges with per-edge draw counts,
32-byte nodes keyed by the full Zobrist key plus a 16-bit check,
idempotent backprop, path-dependent draws decided during descent, and
mark-and-slide compaction for two arenas. Ordered steps with gates and
SPRT recommendations. Empty mcgs-log.md for per-branch results.

No code change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 18:57:12 +01:00
claude c8d1ca682d Merge pull request 'Value network v2: 1024 hidden trained on linrock S2' (#22) from value-net-v2 into main
https://bench.rektdie.com/test/5309/

Elo   | 129.33 +- 23.23 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.37 (-2.94, 2.94) [0.00, 5.00]
Games | N: 604 W: 345 L: 130 D: 129
Penta | [7, 21, 105, 88, 81]

Bench: 663779
2026-11-16 18:27:06 +01:00
rektdieandclaude 2baaaf8bc8 docs: v2 training time and loss in the training README
Bench: 663779

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 18:15:04 +01:00
rektdieandclaude 79c866c77c feat: value network v2, 1024 hidden trained on linrock S2
Replaces the (768 -> 128)x2 value net with (768 -> 1024)x2 -> 1 SCReLU, same
inputs, quantisation and output scale, trained on much more data: the 12 S2
files of huggingface.co/datasets/linrock/bullet-training-data (6.6B positions,
already filtered and shuffled; v1 had one month of test80).

Training: 170 superbatches of 100M positions (17B positions, about 2.6
passes over S2), AdamW, LR 1e-3 cosine to 2.4e-6, target 0.4 * result +
0.6 * sigmoid(score / 400) as in v1. 1h34m on the RTX 3070 at ~3M
positions/s (GPU-bound); final running loss 0.01278 (not comparable to v1's
0.0220, other data). The width was picked for the 2 hour budget: 1024 trains
at 3-4M/s, and in the engine a random 1024 net cost only 16% nps against 128,
thanks to the SIMD kernels.

Trainer (train/value):
- --hidden N (default now 1024) and --batches N for speed tests
- reads bulletformat straight from .bin.zst (src/zstd_reader.rs), so the
  108 GB of S2 never has to be unpacked to 210 GB; training needs ~40 MB/s
  of compressed input, which the HDD holding it gives easily
- also reads raw .bin files (bullet's DirectSequentialDataLoader)

Engine:
- nnue::HIDDEN = 1024, Makefile EVALFILE = networks/rigby-value-v2.bin
- the output layer now sums in blocks of 128 that fit 32 bits and adds
  them up in 64, so it stays exact for any width (the single 32-bit sum was
  only provably safe up to 128)

Checked: evalfens against the trainer's --check on the final checkpoint:
same signs and sizes, within 6 cp on quiet positions and up to 7% on large
evaluations (quantisation; e.g. 553 vs 594 cp). Bench deterministic. UCI:
uci, isready, ucinewgame, go nodes / movetime / infinite + stop.
nps on bench: 4.6M -> 3.5M.

Bench: 663779

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 18:14:52 +01:00
claude 2d3be1982c Merge pull request 'Hand-written SIMD for all network inference' (#21) from simd-inference into main
https://bench.rektdie.com/test/5308/

Elo   | 29.49 +- 11.23 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.13 (-2.94, 2.94) [-5.00, 0.00]
Games | N: 1618 W: 582 L: 445 D: 591
Penta | [29, 134, 388, 187, 71]

Bench: 615835
2026-11-16 15:43:57 +01:00
rektdieandclaude 53553c351a perf: hand-written SIMD for all network inference
The value and policy networks now run on hand-written vector kernels
(src/simd.h) instead of plain loops left to the auto-vectoriser. Paths for
AVX-512BW (VNNI dpwssd when present), AVX2 (AVX-VNNI when present), SSE2
(SSE4.1 sign extend when present) and NEON, chosen at compile time by
-march=native, plus a scalar fallback (-DRIGBY_NO_SIMD).

All arithmetic is exact integer maths, so every path gives the same results
as before and the bench is unchanged.

Value net:
- refresh sums the feature rows in registers, one tile at a time, and
  writes the accumulator once instead of once per piece
- update adds and subtracts the changed rows in one vector pass
- evaluate does SCReLU as v * (v * w) with mullo + madd; v * w fits
  16 bits because the output weights are at most 32767 / QA = 128 (now
  checked on load; the v1 net's largest is 127), and each half's sum fits
  32 bits (static_assert)

Policy net:
- the hidden layer sums the i8 rows (sign-extended on load) into
  register tiles of 8 vectors; row by row in memory was 1.8x slower
- CReLU and the pairwise product in one vector pass
- the output dot products run four moves at a time, sharing the loads of
  the activations (output stage about 20% faster than one at a time)

Tried and dropped: software prefetch of the weight rows (slower), storing
the policy's first layer as i16 to skip the sign extend (slower: the
accumulation is bound by memory, not by the extend).

Measured on a Ryzen 9 5900X (AVX2), bench 50000, four runs each:
main 4.43M nps, this 5.21M nps (+18%).

Checked: bench 615835 identical for AVX2, SSE2, SSE4.1 and scalar builds;
AVX-512 (skylake-avx512, icelake-server) and AVX-VNNI (alderlake) builds
compile; the NEON kernels compile for aarch64 (not run). UCI: uci,
isready, position, go nodes, setoption PolicyFile.

Bench: 615835

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 15:30:56 +01:00
claude d7f97ee80b Merge pull request 'Value hash for transpositions' (#20) from hash-table into main
SPRT https://bench.rektdie.com/test/5307/
Elo   | 21.53 +- 9.13 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.15 (-2.94, 2.94) [0.00, 5.00]
Games | N: 2698 W: 952 L: 785 D: 961
Penta | [72, 251, 571, 348, 107]

Bench: 615835
2026-11-16 00:00:31 +01:00
rektdieandclaude db228fc5f9 feat: value hash for transpositions
Rigby evaluated every new leaf from scratch, although most leaves are
positions it has already searched: with temporary instrumentation,
37-85% of the leaf evaluations in a 5-second search repeated a
position evaluated earlier in the same search (85% from the start
position, 81% in a quiet middlegame, 37% in Kiwipete).

Monty, Vine and Jackal all keep a hash table of positions' Q for this.
Rigby now does the same: every node on a playout's path stores its Q
(from the view of the side to move there) with its visit count under
the position's key; a different position always replaces an entry,
the same one only with at least as many visits. A leaf whose position
is found takes the stored Q instead of the value network and
quiescence search, so it starts from what a deeper search already
knew. Draws by repetition or the 50-move rule are not stored (they
belong to the path, not the position). The table lives across
searches and is cleared on ucinewgame.

It takes a 32nd of Hash (12-byte entries; 174k entries at 64 MB), the
tree the rest.

Checked: bench deterministic; RIGBY_VERIFY_TREE build driven over UCI
with pauses (tree reuse up to 83k nodes, collections at Hash 1 MB,
Hash changes, wtime/winc, movetime, mate-in-one positions found,
go infinite + stop) without an abort.

Bench: 615835

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 23:39:12 +01:00
claude 74fb5eb2fb Merge pull request 'Policy network v1 trained on Lc0 visit distributions' (#19) from policy-net into main
SPRT https://bench.rektdie.com/test/5302/
Elo   | 168.05 +- 28.40 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.28 (-2.94, 2.94) [0.00, 5.00]
Games | N: 492 W: 320 L: 99 D: 73
Penta | [1, 15, 87, 48, 95]

Bench: 630039
2026-11-15 22:22:30 +01:00
claude 7fd14d1ca1 Merge pull request 'Chess960 support' (#18) from chess960 into main
No SPRT: standard chess plays identically (same bench); merged on the user's decision.
Correctness: Chess960 perft suite (960 positions) to depth 5, perftsuite 6.

Bench: 529903
2026-11-15 22:19:43 +01:00
rektdieandclaude c4f65b2632 feat: policy network v1 replaces the move heuristics
networks/rigby-policy-v1.bin is now built in by default (POLICYFILE;
POLICYFILE= still builds the heuristics). It is a 3072 -> 1024 -> 3920
network trained by train/policy on 171M positions of Lc0 test91
self-play (2026-10-25 .. 11-15) against the search's visit
distributions: 10 superbatches of 100M, 10 minutes on the RTX 3070,
final loss 2.296 (2.39 after the first superbatch). The butterfly
history bias and PolicyTemp apply on top of its logits as they did on
the heuristics' scores.

Sensible priors: 1.e4 e5 75%, Kiwipete Bxa6 38%, black bxc3 43%,
c8=Q in the K+P ending. The engine's quantised output matches the
trainer's float output to tenths of a percent, a few percent on very
sharp distributions. Costs about 10% nps on the bench.

Checked: bench deterministic; RIGBY_VERIFY_TREE build driven over UCI
(Hash 1 MB, repeated positions, fen + moves, wtime/winc, go infinite +
stop) without an abort; a build with POLICYFILE= gives the old bench
529903.

Bench: 630039

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 22:16:58 +01:00
rektdieandclaude 05fd552e0b fix: download Lc0 tars over 32 connections across days
storage.lczero.org limits each connection to about 2.3 MB/s but not
the number of connections: 8 give 23 MB/s, 16 give 43 MB/s, 32 give
72 MB/s. fetch.ps1 downloaded one day (about 24 tars) at a time, which
capped it at 24 connections; it now fills batches of whole days with
about two tars per connection, downloads them with -Parallel 32 by
default, then converts and deletes each day as before.

Checked: Nov 14-15 (45 tars, 2.9 GB) in one batch at 32 MB/s, 13.9M
positions, no record dropped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 21:35:27 +01:00
rektdieandclaude 15258f952a feat: policy network inference
src/policy.cpp runs the network train/policy writes: 3072 threat
inputs (side to move's view, flipped horizontally when its king is on
files e-h, +768 attacked, +1536 defended), a hidden layer with CReLU
and pairwise product, and one output row per move, i8 weights scaled
by 128. The hidden width is read from the file's size, so any trained
width loads. When a network is loaded, eval::policy uses its logits
plus the butterfly-history bias instead of the move heuristics; the
temperature and softmax are unchanged.

A network is built in with make POLICYFILE=<net> (default: none, so
the engine plays as before) or loaded at runtime with the UCI option
PolicyFile. policyfens prints the priors of the trainer's --check
positions.

Checked: with a smoke-trained network policyfens matches the trainer's
float output to a few tenths of a percent in all six positions (black
to move, mirrored king, castling, promotion). Speed with a network:
-13% nps at 512 hidden, -41% at 2048. A zero network built in with
POLICYFILE gives uniform priors. Without a network the bench is
unchanged.

Bench: 529903

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 21:27:38 +01:00
rektdieandclaude 1c9d2beec3 feat: policy network trainer on Lc0 visit distributions
train/policy is a fork of montytrain's policy trainer (the one Monty,
Vine and Jackal use: bullet at a pinned revision plus two CUDA
operations, SelectAffine over the legal moves' output rows and a
softmax cross-entropy against the visit distribution). Rigby's
version drops Monty's SEE split of the outputs (3920 rows, as in
Vine), takes its arguments on the command line and checks a
checkpoint with --check.

The Stockfish binpacks used for the value net only keep the played
move, so the data comes from Lc0's raw V6 training tars instead.
lc02monty rebuilds each game from its first record and the played
moves and checks every record: pieces must match, and the moves Lc0
gave a probability must be exactly the legal moves. Lc0 writes
castling as king-takes-rook; Chess960 games keep their rook files.
On a test91 tar all 351,454 records convert. fetch.ps1 downloads a
run's hourly tars day by day, converts and deletes them, and
interleave shuffles the day files into one.

Defaults sized for a 20-minute run on the RTX 3070: 1024 hidden,
10 superbatches of 100M positions (~1M positions/s). The pinned
cudarc does not know CUDA 13.3, so env.ps1 sets
CUDARC_CUDA_VERSION=13000.

Checked: a smoke run on one tar lowers the loss from 2.89 to 2.38 and
gives plausible opening priors; a checkpoint reloads to identical
output; interleaved data trains.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 21:27:08 +01:00
rektdieandclaude 9643c7b0a5 feat: Chess960 support
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>
2026-11-15 21:26:45 +01:00
claude 1dacc9c402 Merge pull request 'Separate, higher cpuct at the root' (#17) from root-cpuct into main
SPRT https://bench.rektdie.com/test/5298/
Elo   | 12.06 +- 8.95 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.01 (-2.94, 2.94) [0.00, 10.00]
Games | N: 3344 W: 1251 L: 1135 D: 958
Penta | [133, 328, 682, 348, 181]

Bench: 529903
2026-11-15 16:45:49 +01:00
rektdieandclaude b89ab39bdd feat: separate, higher cpuct at the root
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>
2026-11-15 16:20:25 +01:00
claude d39b8a3a4a Merge pull request 'cpuct grows with the parent's visits' (#16) from cpuct-scaling into main
SPRT https://bench.rektdie.com/test/5297/
Elo   | 38.82 +- 18.01 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.00 (-2.94, 2.94) [0.00, 10.00]
Games | N: 746 W: 294 L: 211 D: 241
Penta | [16, 63, 160, 90, 44]

Bench: 536817
2026-11-15 16:18:43 +01:00
rektdieandclaude 75c500ba61 feat: cpuct grows with the parent's visits
The exploration constant was fixed at 1.6. With tree reuse the root and
the nodes near it reach hundreds of thousands of visits, where a fixed
cpuct leaves the other children almost no chance. Now, as in Monty,
cpuct is multiplied by 1 + ln((N + 8192) / 8192) for a node with N
visits (Monty's default scale, 64 x 128; the factor is independent of
the Q range). Nodes under a few thousand visits are nearly unchanged;
at 10k visits cpuct is x1.8, at 1M x5.8.

Checked: the best move is the same as main's in four positions at 200k
playouts (Qxf7# included). The log costs up to about 10% speed in fast
endgame playouts.

Bench: 536817

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 16:11:51 +01:00
claude d8b1d6ef6f Merge pull request 'Hard time limit for moves still open at the soft limit' (#15) from soft-hard-limit into main
SPRT https://bench.rektdie.com/test/5296/
Elo   | 30.48 +- 15.36 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.25 (-2.94, 2.94) [0.00, 10.00]
Games | N: 1120 W: 439 L: 341 D: 340
Penta | [40, 88, 229, 140, 63]

Bench: 554375
2026-11-15 16:10:02 +01:00
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
claude ca921ce2e2 Merge pull request 'Smart pruning stops clock searches whose best move is settled' (#14) from smart-pruning into main
SPRT https://bench.rektdie.com/test/5295/
Elo   | 24.75 +- 13.56 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.24 (-2.94, 2.94) [0.00, 10.00]
Games | N: 1364 W: 501 L: 404 D: 459
Penta | [39, 133, 273, 166, 71]

Bench: 554375
2026-11-15 15:57:37 +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
claude 6f4c3b2656 Merge pull request 'Escape bonus for any piece the opponent can win' (#13) from policy-escape-see into main
SPRT https://bench.rektdie.com/test/5294/
Elo   | 103.71 +- 29.38 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.20 (-2.94, 2.94) [0.00, 10.00]
Games | N: 338 W: 174 L: 76 D: 88
Penta | [5, 15, 60, 55, 34]

Bench: 554375
2026-11-15 15:41:40 +01:00
rektdieandclaude 246af156ef feat: escape bonus for any piece the opponent can win
The policy rewarded moving a piece away (0.003 x its value) only when an
enemy pawn attacked it. A knight attacked by an undefended-against bishop
got nothing. Now the bonus goes to every move of a knight, bishop, rook
or queen standing where the opponent wins it in an exchange: their least
valuable attacker starts it and SEE (from their side) gains at least 1;
a king may only take an undefended piece. A pawn attack always passes
this test, so the old case is covered. The result is computed once per
square in each policy call.

The counterpart of the quiet-move SEE penalty on the target square.

Example: with a white knight on e5 attacked by Bd6 and undefended, its
four retreats rank first (5.6-6.1%); in the Ruy Lopez the defended Nc6
gets no bonus.

Bench is deterministic.

Bench: 554375

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 15:36:46 +01:00
claude 2ac8d64ca9 Merge pull request 'SEE penalty for quiet moves that hang the piece' (#12) from policy-quiet-see into main
SPRT https://bench.rektdie.com/test/5293/
Elo   | 247.64 +- 50.37 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.96 (-2.94, 2.94) [0.00, 10.00]
Games | N: 258 W: 190 L: 32 D: 36
Penta | [1, 4, 30, 24, 70]

Bench: 549158
2026-11-15 15:34:36 +01:00
rektdieandclaude da1b0e61e1 feat: SEE penalty for quiet moves that hang the piece
The policy only penalised a quiet move when an enemy pawn attacked the
target square. A knight stepping in front of a bishop or a pawn pushed
into an undefended capture got no penalty. Now any quiet move whose
static exchange on the target square loses material (SEE < 0) loses
0.004 x the moving piece's value from its logit, the same penalty the
pawn threat gave. Every move to a pawn-attacked square fails this SEE,
so the old case is covered; the pawn-threat penalty stays for captures
only, as before.

Example (Italian, white to move): b4 (hangs to Bf8) and g4 (to Nf6) drop
from about 3.4% to 2.4%, Bd5 (Nxd5 exd5 loses the exchange of a bishop
for a knight) to 1.0%; castling and developing moves stay on top.

Bench is deterministic.

Bench: 549158

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 15:30:29 +01:00
claude 4f3c0ba2b3 Merge pull request 'SEE decides the capture bonus in the policy' (#11) from policy-see into main
SPRT https://bench.rektdie.com/test/5292/
Elo   | 222.16 +- 49.14 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.59 (-2.94, 2.94) [0.00, 10.00]
Games | N: 248 W: 178 L: 38 D: 32
Penta | [2, 4, 32, 24, 62]

Bench: 552832
2026-11-15 15:28:50 +01:00
rektdieandclaude 1460f5e81e feat: SEE decides the capture bonus in the policy
The +262 Elo of butterfly history showed that the hand-written policy
is the main weakness. One clear flaw: every capture got a +1 logit
bonus, including ones that just lose the piece (a knight taking a
defended pawn, a bishop sacrifice on f7). Now a capture whose static
exchange on the square loses material (SEE < 0) gets -1 instead of +1;
the victim and attacker terms are unchanged.

Example priors (startpos-like middlegame, white to move): Nxe5 with the
pawn defended 0.3%, Bxf7+ 1.4%, while winning captures stay on top
(Nxe5 against an undefended pawn 10.8%).

Bench is deterministic.

Bench: 552832

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 15:25:53 +01:00
claude f61564c58e Merge pull request 'Butterfly history added to the policy logits' (#10) from butterfly-history into main
SPRT https://bench.rektdie.com/test/5291/
Elo   | 261.71 +- 54.35 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.93 (-2.94, 2.94) [0.00, 10.00]
Games | N: 248 W: 195 L: 37 D: 16
Penta | [0, 3, 35, 11, 75]

Bench: 555674
2026-11-15 15:24:01 +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
claude 786783d7d1 Merge pull request 'Incremental NNUE accumulator in quiescence' (#9) from nnue-incremental into main
SPRT https://bench.rektdie.com/test/5290/ (non-regression)
Elo   | 27.50 +- 10.61 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.07 (-2.94, 2.94) [-5.00, 0.00]
Games | N: 1608 W: 575 L: 448 D: 585
Penta | [28, 107, 443, 162, 64]

Bench: 546966
2026-11-15 15:18:27 +01:00
rektdieandclaude 8ceee77166 perf: incremental NNUE accumulator in quiescence
Every quiescence node built the network's hidden layer from the whole
board: about 30 pieces x 2 perspectives x 128 weights, a third of a
middlegame playout. The accumulator (both perspectives) is now built
once at the root of the quiescence search and passed down; each child
gets a copy updated with the two to four features the move changes
(normal move, capture, en passant, promotion, castling). i16 sums wrap
the same way in any order, so the values, and the search, are exactly
the same as before.

Playouts per second at 100k playouts, main -> this (two runs each):

  startpos           688k -> 705k   +2%
  QGD middlegame     453k -> 495k   +9%
  Kiwipete           128k -> 161k   +26%
  Sicilian middle    385k -> 440k   +14%
  rook endgame       881k -> 905k   +3%
  bench              3.87M -> 4.39M +14%

Checked: on 3,240,535 moves from random games (276,756 captures, 3,676
castles, 433 en passant, 30,900 promotions) the updated accumulator is
byte for byte equal to a fresh one, and a whole game played on updates
alone does not drift. The bench is identical to main.

Bench: 546966

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 15:03:40 +01:00
claude 807ddd90c1 Merge pull request 'Generate only captures in quiescence' (#8) from qs-captures-gen into main
SPRT https://bench.rektdie.com/test/5289/ (non-regression)
Elo   | 66.75 +- 16.38 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.07 (-2.94, 2.94) [-5.00, 0.00]
Games | N: 764 W: 311 L: 166 D: 287
Penta | [6, 46, 172, 113, 45]

Bench: 546966
2026-11-15 15:00:51 +01:00