76 Commits
Author SHA1 Message Date
claude 19a67fbb94 Merge pull request 'Rename MCTS to MCGS' (#26) from mcgs-rename into main
src/mcts.* is now src/mcgs.*; the banner, Makefile header and README say MCGS. No behaviour change, no SPRT.

Bench: 608763
2026-11-16 23:24:17 +01:00
rektdieandclaude 1ddb001e0b refactor: rename MCTS to MCGS (src/mcgs.h, src/mcgs.cpp)
Rigby searches a graph since PR #23, so the search files, the banner, the
Makefile header and the README now say MCGS. The README describes the
graph search, reuse, collection and Hash memory as they are now.
Internal names (Tree, RIGBY_VERIFY_TREE) are unchanged.

No behaviour change: zero warnings, bench identical to main twice.

Bench: 608763

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 23:23:39 +01:00
claude 59677616f7 Merge pull request 'MCGS: remove the value hash' (#25) from mcgs-v-novaluehash into main
Removes the ValueHash; all Hash goes to the graph (MCGS variant 5c). Merged together with the stop rule (#24) at the owner's request; no SPRT has measured the two together.

SPRT (Non-Regression, against mcgs-step3-reroot): https://bench.rektdie.com/test/5318/

Elo   | 13.59 +- 7.51 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.16 (-2.94, 2.94) [-5.00, 0.00]
Games | N: 3120 W: 1028 L: 906 D: 1186
Penta | [59, 283, 767, 379, 72]

Bench: 608763
2026-11-16 23:21:03 +01:00
rektdieandclaude 287bf93ef9 docs: MCGS merges into main (PRs 23-25) in mcgs-log
Bench: 608763

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 23:20:38 +01:00
rektdieandclaude 19aedfdce9 Merge main into mcgs-v-novaluehash
Brings in the stop rule (PR #24). The combined code passed the gates:
zero warnings, verify (a)-(d), VERIFY searches with forced GC, reuse at
Hash 64, Hash 1 and 960, smoke positions.

Bench: 608763

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 23:20:38 +01:00
claude 150a876b2a Merge pull request 'MCGS: stop a playout at a child that is ahead of its edge' (#24) from mcgs-v-stop into main
A playout stops at a child that has more visits than its edge and backs up the child's Q (MCGS variant 5a).

SPRT: https://bench.rektdie.com/test/5316/

Elo   | 12.35 +- 6.40 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.31 (-2.94, 2.94) [0.00, 5.00]
Games | N: 4898 W: 1609 L: 1435 D: 1854
Penta | [91, 544, 1073, 582, 159]

Bench: 609350
2026-11-16 23:19:45 +01:00
claude 75098c849b Merge pull request 'Monte-Carlo graph search (MCGS steps 2, 3 and 3b)' (#23) from mcgs-step3-reroot into main
Positions reached by different move orders now share one node. The plan is in docs/mcgs-plan.md, the gates and measurements in docs/mcgs-log.md.

SPRT: https://bench.rektdie.com/test/5313/

Elo   | 12.24 +- 6.54 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.09 (-2.94, 2.94) [0.00, 5.00]
Games | N: 4600 W: 1533 L: 1371 D: 1696
Penta | [109, 438, 1067, 554, 132]

Bench: 764208
2026-11-16 23:18:21 +01:00
rektdieandclaude 6e807b5565 docs: 5314, 5315 and 5319 stopped unfinished in mcgs-log
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 23:17:59 +01:00
rektdieandclaude e24145d0e5 docs: 5316 and 5318 passed, 5317 failed in mcgs-log
Also re-encodes two lines that were written as cp1252.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 23:15:35 +01:00
rektdieandclaude faa0b4700a docs: 5313 passed; six MCGS variant tests (5314-5319) in mcgs-log
Bench: 764208

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 21:44:28 +01:00
rektdieandclaude 9e7c3ef64a mcts: remove the value hash (MCGS variant 5c)
The graph shares a position's node, and with it its Q, between move
orders, which the value hash did for the tree. It still took 1/32 of Hash
and a store for every node of every playout path (about 6 % of playout
time in step 1). Its remaining use was positions the graph dropped in a
collection, or a new search without reuse.

All of Hash now goes to the graph. A simplification: Non-Regression SPRT.

The bench changes slightly (one Searcher runs all 16 bench positions, so
the value hash carried a few values between them).

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: 765326

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 21:36:02 +01:00
rektdieandclaude 59d5af56f3 mcts: stop a playout at a child that is ahead of its edge (MCGS variant 5a)
With always-descend, a playout runs through existing nodes until it reaches
a new position or a draw of its path. In reversible endgames it wanders
through cycles: mean playout depth 28 against main's 6 in KR v K (bench
15), at 0.15x main's playouts/s, with 30 % of playouts ending in a
repetition.

KataGo's stop rule: when the child an edge leads to already has more
visits than the edge (other move orders reached it), the playout ends
there. The edge counts the visit and its parent recomputes from the
child's current Q; the child is left as it is. In a tree the two counts are
equal, so this only fires on transpositions. The depth limit now ends a
playout the same way.

The bench changes because playouts stop at transpositions.

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: 609350

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 21:36:01 +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
rektdieandclaude 695d2dd30d perf: generate only captures in quiescence
Out of check the quiescence search only searches captures and queen
promotions, but every node generated all legal moves and threw the
quiet ones away. It now generates just those (generate_noisy: the same
legal generator with captures-only targets, no quiet pawn pushes, no
castling), in the same order as the full generation, so search is
unchanged. A node without any noisy move still has to tell stalemate
from a quiet position; has_legal_move answers that and stops at the
first legal move it finds.

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

  startpos           631k -> 725k   +15%
  QGD middlegame     390k -> 446k   +14%
  Kiwipete           106k -> 142k   +34%
  Sicilian middle    334k -> 423k   +27%
  rook endgame       851k -> 982k   +15%

Checked: perftsuite 7 passes. On 252,893 positions from random games
(captures preferred, so they reach endgames, promotions and 400
positions without legal moves) generate_noisy equals generate_legal
filtered to captures and queen promotions, in the same order, and
has_legal_move equals a non-empty generate_legal. The bench is
identical to main.

Bench: 546966

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 14:52:58 +01:00
claude c45450255a Merge pull request 'SEE pruning of losing captures in quiescence' (#7) from qs-see into main
SPRT https://bench.rektdie.com/test/5288/
Elo   | 115.97 +- 32.64 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 2.98 (-2.94, 2.94) [0.00, 10.00]
Games | N: 292 W: 146 L: 52 D: 94
Penta | [4, 11, 52, 45, 34]

Bench: 546966
2026-11-15 14:50:06 +01:00
rektdieandclaude ed1c2b77f7 feat: SEE pruning of losing captures in quiescence
Profiling showed that 80-85% of a middlegame playout is the quiescence
search behind the value network: 15-41 quiescence nodes per leaf, since
every capture was searched, including ones that just lose the piece.

The quiescence search now skips captures whose static exchange on the
target square loses material (SEE < 0) when not in check. The SEE is the
usual threshold swap (least valuable attacker first, x-rays opened as
pieces leave, a king recaptures only an undefended square, pins
ignored); castling, en passant and promotions count as even.

Effect at 60k playouts (instrumented build, qsearch nodes per leaf and
time per playout):

  startpos           3.7 -> 2.2     -20%
  QGD middlegame    14.7 -> 4.2     -54%
  Kiwipete          41.4 -> 25.5    -25%
  Sicilian middle   21.0 -> 3.4     -68%
  rook endgame       2.6 -> 2.3      -2%

Checked: the SEE matches an independent python-chess reference exactly
on 9957 captures from 3000 random positions (4884 with recaptures).
Bench is deterministic. Move generation is untouched.

Bench: 546966

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 14:43:40 +01:00
claude 8f69f4f6f1 Merge pull request 'Live framed search dashboard for a terminal' (#6) from pretty-dashboard into main
Display only, no SPRT: output before the first "uci" command changes,
search and the UCI output do not.

Bench: 546018
2026-11-15 14:34:51 +01:00
rektdieandclaude 4973535596 refactor: drop the board and piece glyphs from the dashboard
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>
2026-11-15 14:33:45 +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
claude 31a35fd84f Merge pull request 'Coloured search output for a terminal' (#5) from pretty-print into main
Display only, no SPRT: output before the first "uci" command changes,
search and the UCI output do not.

Bench: 546018
2026-11-15 14:17:01 +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
claude 1754753a6e Merge pull request 'Collect the tree when the node arena is full' (#4) from tree-gc-nn into main
SPRT https://bench.rektdie.com/test/5286/
Elo   | 8.74 +- 6.47 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.00 (-2.94, 2.94) [0.00, 10.00]
Games | N: 3262 W: 996 L: 914 D: 1352
Penta | [48, 226, 1023, 264, 70]

Bench: 546018
2026-11-15 11:56:36 +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
claude 0d5713f7f0 Merge pull request 'Expand nodes on their second visit' (#3) from expand-second-visit-nn into main
SPRT https://bench.rektdie.com/test/5285/
Elo   | 31.92 +- 15.09 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 2.96 (-2.94, 2.94) [0.00, 10.00]
Games | N: 764 W: 260 L: 190 D: 314
Penta | [9, 56, 201, 88, 28]

Bench: 546018
2026-11-15 10:41:03 +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
claude 6057476214 Merge pull request 'Value network trained on Lc0 data' (#2) from value-net into main
Merge pull request 'Value network trained on Lc0 data' (#2) from value-net into main

SPRT https://bench.rektdie.com/test/5284/
Elo   | 502.68 +- 147.15 (95%)
SPRT  | 8.0+0.08s Threads=1 Hash=64MB
LLR   | 3.05 (-2.94, 2.94) [0.00, 10.00]
Games | N: 162 W: 150 L: 5 D: 7

Bench: 545914
2026-11-15 04:18:12 +01:00
rektdieandclaude 30b0c36cd5 feat: value network trained on Lc0 data
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>
2026-11-15 04:12:52 +01:00
rektdieandclaude 530c4d67ed train: value network trainer on Lc0 data
A bullet trainer for a (768 -> 128)x2 -> 1 SCReLU value network, reading
linrock's Lc0-derived Stockfish binpacks directly (no conversion). The
target blends the game result (0.4) with the search score; 40
superbatches by default, about 12 minutes on an RTX 3070.

train/value/train.ps1 sets up CUDA 13.3 and cargo, unpacks the default
binpack if needed, builds and runs. train/README.md documents the data,
the setup and the network file layout for the engine side.

No engine change.

Bench: 546127

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 03:57:51 +01:00
59 changed files with 10569 additions and 740 deletions

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
# Networks are raw binary weights; never convert line endings
*.bin binary
+7
View File
@@ -5,6 +5,7 @@ Rigby
# Networks and data
*.bin
!networks/*.bin
*.nnue
*.pb
*.pb.gz
@@ -13,3 +14,9 @@ Rigby
# Editors
.vscode/
.idea/
# Training
train/data/
train/**/target/
train/**/checkpoints/
*.zst
+17 -5
View File
@@ -1,11 +1,16 @@
# Rigby - MCTS chess engine
# Rigby - MCGS chess engine
# OpenBench calls: make EXE=<name> [EVALFILE=<net>] [CXX=<compiler>]
# POLICYFILE=<net> picks the built-in policy network; POLICYFILE= builds none
# (move heuristics).
SRC_DIR := src
OBJ_DIR := obj
EXE ?= Rigby
EVALFILE ?=
# The value network embedded into the binary
EVALFILE ?= networks/rigby-value-v2.bin
# The policy network embedded into the binary; empty means move heuristics
POLICYFILE ?= networks/rigby-policy-v1.bin
CXX ?= clang++
ifeq ($(origin CXX),default)
CXX := clang++
@@ -25,7 +30,7 @@ else
endif
endif
CXXFLAGS := -std=c++20 -O3 -flto -Wall -Wextra -DNDEBUG
CXXFLAGS := -std=c++20 -O3 -flto -Wall -Wextra -DNDEBUG -Iexternal
LDFLAGS := -O3 -flto
ifeq ($(PLATFORM),windows)
@@ -55,8 +60,9 @@ else
LDFLAGS += -pthread -static
endif
ifneq ($(EVALFILE),)
CXXFLAGS += -DEVALFILE=\"$(EVALFILE)\"
CXXFLAGS += -DEVALFILE=\"$(EVALFILE)\"
ifneq ($(POLICYFILE),)
CXXFLAGS += -DPOLICYFILE=\"$(POLICYFILE)\"
endif
CXXFLAGS += $(ARCH_FLAGS)
@@ -77,6 +83,12 @@ $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp | $(OBJ_DIR)
$(OBJ_DIR):
mkdir $(OBJ_DIR)
# Rebuild the network's translation unit when the network changes
$(OBJ_DIR)/nnue.o: $(EVALFILE)
ifneq ($(POLICYFILE),)
$(OBJ_DIR)/policy.o: $(POLICYFILE)
endif
-include $(DEPS)
.PHONY: clean
+54 -16
View File
@@ -1,8 +1,8 @@
# Rigby
Rigby is a UCI chess engine built on Monte Carlo Tree Search (PUCT). The goal is a
neural-network-guided MCTS engine, later a Monte Carlo Graph Search (MCGS), with a
value and policy network trained with [bullet](https://github.com/jw1912/bullet) on
Rigby is a UCI chess engine built on Monte Carlo Graph Search (MCGS) with PUCT
selection. The goal is a neural-network-guided MCGS engine with a value and policy
network trained with [bullet](https://github.com/jw1912/bullet) on
data generated by Leela Chess Zero, and CUDA inference.
Every change is validated with SPRT on OpenBench.
@@ -11,13 +11,29 @@ Every change is validated with SPRT on OpenBench.
- Bitboard board with fancy magic attacks, fully legal move generation, copy-make.
Verified with a perft suite (`Rigby perftsuite`).
- PUCT search: node arena with contiguous children, first-play urgency reduction,
two-fold repetition, 50-move and insufficient-material draws inside the tree.
- Placeholder evaluation until the network exists: a small hand-written
evaluation behind a capture-only quiescence search for the value, and move
heuristics (captures, promotions, checks, pawn threats) for the policy.
- Tree reuse between moves: the subtree of the new position is packed to the
front of the node arena in place, so it costs no extra memory.
- Chess960: any castling rook placement, X-FEN and Shredder-FEN castling rights,
`UCI_Chess960` for king-takes-rook castling notation. Verified with the 960
positions of the standard Chess960 perft suite to depth 5 (`perftfile`).
- Monte Carlo Graph Search: a position reached by different move orders is one
node, found through a key table. Edges carry their own visits, so a node's Q
is the visit-weighted mix of its children. PUCT selection with first-play
urgency reduction. A playout stops at a child that already has more visits
than the edge leading to it and backs up that child's Q.
- Repetition and 50-move draws depend on the path, so they are counted only on
the edges of the current path, never stored in nodes. Insufficient-material
draws are terminal nodes.
- Value: a `(768 -> 128)x2 -> 1` network trained with bullet on Lc0 data
(`networks/rigby-value-v1.bin`, embedded at build time; see `train/README.md`),
behind a capture-only quiescence search.
- Policy: a `3072 -> 1024 -> 3920` network trained on Lc0 visit distributions
(`networks/rigby-policy-v1.bin`, embedded at build time; see `train/README.md`).
Built without one (`POLICYFILE=`), move heuristics (captures, promotions,
checks, pawn threats).
- Graph reuse between moves: only the root moves to the new position. The next
collection keeps what the root reaches.
- When the node or edge arena is full, the least visited parts of the graph are
cut back to leaves (keeping their visits and Q), the rest is packed in place
and the key table is rebuilt, so search never stops expanding.
- Single-threaded.
## Building
@@ -28,11 +44,16 @@ the build targets `x86_64-w64-windows-gnu`, same as Eleanor.
```
make
make EXE=Rigby-dev
make EVALFILE=path/to/quantised.bin
```
Compiling with `-DRIGBY_VERIFY_TREE` checks the whole tree before and after every
reuse (legal moves, visit counts) and aborts on the first inconsistency. It is slow,
for debugging only.
`EVALFILE` defaults to `networks/rigby-value-v1.bin`. `POLICYFILE` defaults to
`networks/rigby-policy-v1.bin`; `POLICYFILE=` builds the move heuristics instead.
Compiling with `-DRIGBY_VERIFY_TREE` checks the whole graph before and after every
reuse and after every collection (legal moves, visit counts, keys and the key table)
and aborts on the first inconsistency. Such a build also has a `verify` command that
runs these checks on test positions. It is slow, for debugging only.
## UCI
@@ -45,26 +66,43 @@ Extra commands:
| Command | Meaning |
| --- | --- |
| `d` | Print the board, FEN and hash key |
| `eval` | Static and quiescence evaluation of the current position |
| `eval` | Static (network) and quiescence evaluation of the current position |
| `evalfens` | Network evaluation of fixed positions, to compare with the trainer's `--check` |
| `perft <depth>` | Perft with per-move breakdown |
| `perftsuite [maxdepth]` | Standard perft positions with expected counts |
| `perftfile <epd> [maxdepth]` | Perft of every `<fen> ;D1 <n> ;D2 <n> ...` line of a file (e.g. a Chess960 suite) |
| `policyfens` | Policy network priors of fixed positions, to compare with the trainer's `--check` |
| `bench [playouts]` | Fixed playout search over the bench positions |
`go depth N` limits the mean playout depth. `nodes` in `info` lines are playouts.
Started from a terminal, Rigby shows its search for a human instead: a framed
dashboard, redrawn in place ten times a second, with the score and an evaluation
bar, depth, playouts, speed, a time bar, tree fill, the principal variation in SAN
and the most visited root moves with their share of the visits, score and prior.
It adapts to the terminal's size. 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 it. `NO_COLOR`
turns it off, `RIGBY_PRETTY=1` forces it into a pipe (e.g. `less -R`). It needs a
terminal with 24-bit colour and UTF-8 (Windows Terminal, any modern Linux/macOS
terminal).
### Options
| Option | Default | Meaning |
| --- | --- | --- |
| Hash | 64 | Tree memory in MB. A node takes 20 bytes. |
| Hash | 64 | Graph memory in MB: 32-byte nodes, 16-byte edges and the key table. |
| Threads | 1 | Only 1 for now. |
| MoveOverhead | 20 | Milliseconds kept back per move. |
| CPuct | 160 | Exploration constant x100. |
| RootCPuct | 233 | Exploration constant at the root x100. |
| FPUReduction | 30 | First-play urgency reduction x100. |
| PolicyTemp | 100 | Policy softmax temperature x100. |
| UCI_Chess960 | false | Write and read castling as the king taking its rook (`e1h1`). |
| PolicyFile | `<empty>` | Policy network file to use instead of the built-in one. |
## Bench
`Rigby bench` runs 5000 playouts on each of 16 positions. The reported node count is
the number of positions visited in the tree over all playouts, so it changes
the number of positions visited in the graph over all playouts, so it changes
whenever search behaviour changes, while the playout count stays fixed.
+760
View File
@@ -0,0 +1,760 @@
# MCGS log
One section per branch: commit, bench, SPRT link, outcome. Outcomes are filled in
only from results the owner provides.
| step | branch | commit | bench | SPRT (link, TC, bounds) | outcome |
| --- | --- | --- | --- | --- | --- |
| 1 | `mcgs-stats` | `bec9871` | 663779 (normal and `STATS=1` builds) | none (never merged) | measurement only; the branch stays on its own |
| 2 | `mcgs-step2-split` | `fb1b8a5` | 663779 (identical to main) | | |
| 3 | `mcgs-step3-core` | `14f672a` | 764208 | [5312](https://bench.rektdie.com/test/5312/) STC 8.0+0.08 `[0.00, 5.00]`, base `main` | failed: LLR −3.19, 4758 games, 106 lost on time |
| 3b | `mcgs-step3-reroot` | `d38f0b1` | 764208 | [5313](https://bench.rektdie.com/test/5313/) STC 8.0+0.08 `[0.00, 5.00]`, base `main` | passed: LLR 3.09, 4600 games, 0 lost on time |
| 5 | `mcgs-v-arena12` | `0a9bb40` | 764208 | [5314](https://bench.rektdie.com/test/5314/) STC `[0.00, 5.00]`, base `mcgs-step3-reroot` | stopped unfinished: Elo −0.99 ± 3.78, LLR −2.09, 12288 games |
| 5b | `mcgs-v-edgeq` | `e7f2bfb` | 769193 | [5315](https://bench.rektdie.com/test/5315/) STC `[0.00, 5.00]`, base `mcgs-step3-reroot` | stopped unfinished: Elo +1.10 ± 3.32, LLR −0.52, 16676 games |
| 5a | `mcgs-v-stop` | `59d5af5` | 609350 | [5316](https://bench.rektdie.com/test/5316/) STC `[0.00, 5.00]`, base `mcgs-step3-reroot` | passed: Elo +12.35 ± 6.40, LLR 3.31, 4898 games |
| 5 | `mcgs-v-pathrep` | `b7bfb0b` | 755448 | [5317](https://bench.rektdie.com/test/5317/) STC `[0.00, 5.00]`, base `mcgs-step3-reroot` | failed: Elo −2.06 ± 3.73, LLR −3.12, 12956 games |
| 5c | `mcgs-v-novaluehash` | `9e7c3ef` | 765326 | [5318](https://bench.rektdie.com/test/5318/) Non-Regression STC `[-5.00, 0.00]`, base `mcgs-step3-reroot` | passed: Elo +13.59 ± 7.51, LLR 3.16, 3120 games |
| 4 | `mcgs-v-reconcile` | `79fd017` | 764208 | [5319](https://bench.rektdie.com/test/5319/) STC `[0.00, 5.00]`, base `mcgs-step3-reroot` | stopped unfinished: Elo +1.61 ± 3.83, LLR 0.04, 12288 games |
## Step 1 measurements
All numbers below come from the **stats build** (`make STATS=1`) at `bec9871`, on
the owner's Windows machine, 2026-11-16. Rates, cycle shares and playouts per
second are local measurements of that build. They say nothing about strength.
**Stats-build overhead.** The key maps and timers slow the search down. Over the
16 positions, the normal build ran:
- 811k playouts/s at 1000 ms (12.7M playouts);
- 770k playouts/s at 5000 ms (61.3M playouts).
The stats build ran 498k/s and 474k/s, about 61 % of that. A stats-build
5000 ms tree is about the size of a normal-build 3 s tree.
**Definitions** (plan section 4, with these choices made explicit):
- A *tree node* is a node MCGS would create: the root, plus every
first-visited position that is not a path-dependent draw. Repetition and
50-move leaves are never graph nodes, so they are not counted.
- `newleaf` = playouts that end at such a first visit.
- `lf_tt` (`leaf_tt`) = new leaves whose key already had a tree node, as a
percentage of new leaves. That is the denominator the ValueHash comment uses
("leaf evaluations"). Per playout it is about 0.55× that.
- `vh` = ValueHash hits as a percentage of all first visits.
- `exp_dup` = expansions of a key that already had an expanded node, as a
percentage of expansions.
- `path_tt` = playouts with at least one path node whose key has ≥ 2 tree nodes.
`inner` is the same count without the new leaf.
- `dup` = tree nodes / distinct keys.
- `r_tree` = child slots / visited nodes: edges per node in the step 2 layout.
- `r_grph` = child slots counted once per distinct expanded key / distinct keys,
which approximates edges per node after merging.
- The key maps are rebuilt from the tree after root expansion, reroot and every
GC. The end-of-search figures are taken after the last GC.
Each run searched the 16 bench positions, each with a fresh `Searcher` (so no
reuse), at Hash 64 unless stated otherwise.
### `mcgsstats 1000` (Hash 64)
```
pos playouts po/s newleaf lf_tt tt_exp vh exp_dup path_tt inner rep r50 dup r_tree r_grph gc
1 249792 254889 249757 51.8 34.0 50.8 47.8 95.8 95.0 11 0 1.965 15.74 17.14 1
2 171008 174497 170960 23.8 15.1 22.9 22.1 92.9 92.6 16 0 1.278 14.88 15.37 1
3 250240 255346 250197 56.4 38.1 56.1 53.0 89.6 88.4 41 0 2.080 13.04 14.37 2
4 277376 283036 277372 76.8 58.3 76.5 74.2 95.4 94.7 2 0 4.076 14.73 15.45 2
5 232512 237257 232455 40.4 25.7 39.2 36.1 87.0 85.3 56 0 1.605 16.64 17.95 1
6 202944 207085 201798 32.1 20.5 30.7 29.9 88.4 87.4 206 0 1.430 15.48 16.08 1
7 192064 195983 191629 30.0 18.6 29.0 28.8 89.0 88.2 392 0 1.386 16.16 16.71 1
8 199808 203885 199106 23.2 14.5 22.5 20.9 80.5 79.4 684 0 1.263 16.85 17.67 1
9 252928 258089 250454 39.8 25.7 37.6 36.6 91.9 91.0 2418 0 1.546 9.05 9.79 1
10 307136 313404 268891 41.7 29.4 36.7 38.6 96.3 96.0 37831 0 1.716 11.09 11.75 0
11 886848 904946 451555 91.2 78.0 86.3 90.5 100.0 100.0 432838 0 11.403 4.09 7.98 0
12 821440 838204 524144 91.2 82.4 86.5 89.4 99.9 99.8 296636 0 11.331 3.56 4.61 0
13 224384 228963 223701 24.5 15.0 21.5 22.1 74.6 72.8 616 0 1.325 13.93 14.44 0
14 244992 247716 243015 31.4 20.2 29.7 28.3 88.4 87.6 1975 0 1.379 11.49 12.22 2
15 679936 693812 672593 93.8 75.5 88.5 88.9 99.7 99.6 6524 0 14.199 3.09 7.59 1
16 2625600 2679183 14470 34.0 21.3 32.7 29.9 99.3 99.3 2562358 0 1.515 12.70 13.58 0
all 7819008 498375 4422097 60.1 46.5 57.4 56.2 96.0 95.6 3342604 0 2.536 9.47 14.03 14
```
### `mcgsstats 5000` (Hash 64)
```
pos playouts po/s newleaf lf_tt tt_exp vh exp_dup path_tt inner rep r50 dup r_tree r_grph gc
1 1016192 204054 1015943 50.2 30.0 56.2 43.9 97.9 97.5 81 0 1.778 6.46 7.19 12
2 786880 156874 785729 19.9 10.8 24.0 16.3 96.6 96.5 535 0 1.210 6.26 6.44 9
3 1186880 238329 1186600 63.6 39.6 71.3 57.6 95.0 94.4 252 0 2.407 8.97 10.20 17
4 1244480 249895 1244387 73.5 50.5 80.4 67.0 97.6 97.3 77 0 3.885 9.09 11.53 16
5 1053568 211009 1052812 43.8 25.2 49.8 36.8 92.9 92.0 743 0 1.649 5.94 6.57 13
6 914112 183556 904648 33.9 19.1 36.8 28.1 94.3 93.9 4722 0 1.438 7.00 7.61 9
7 958720 192514 944891 31.5 18.2 37.0 27.4 96.1 95.8 13719 0 1.405 9.56 9.98 10
8 944000 189558 936972 22.9 12.5 28.0 18.4 92.4 92.0 6815 0 1.242 7.42 7.90 11
9 1159680 230828 1143522 40.5 25.2 42.0 35.0 93.9 93.3 15583 0 1.518 4.35 4.75 8
10 1658304 332992 1265760 51.5 34.4 47.7 43.9 99.1 99.0 389253 0 1.844 5.52 6.50 7
11 4141760 831678 1755422 92.2 78.4 86.9 90.5 100.0 100.0 2366999 0 12.889 2.80 6.53 4
12 3398208 682371 1913929 93.7 83.7 87.5 91.7 100.0 100.0 1307918 0 13.707 2.57 4.14 3
13 973888 195559 955354 27.2 15.4 28.6 22.3 89.5 88.9 14102 0 1.328 6.27 6.78 7
14 1050432 210930 1035983 27.2 14.8 32.5 21.1 94.5 94.2 14413 0 1.318 7.58 8.20 12
15 3230592 648713 3202909 96.0 78.0 90.9 89.9 99.9 99.9 24843 0 19.104 2.93 7.39 15
16 14102272 2831781 41850 40.1 25.6 38.1 35.1 99.9 99.8 13855364 0 1.670 12.31 13.34 0
all 37819968 474094 19386711 60.7 45.0 61.5 57.2 98.3 98.2 18015419 0 2.674 5.04 7.38 153
```
### `mcgsstats 5000 16` (Hash 16, GC-heavy)
```
pos playouts po/s newleaf lf_tt tt_exp vh exp_dup path_tt inner rep r50 dup r_tree r_grph gc
1 1047040 210248 1046869 42.5 20.8 54.9 33.1 94.6 93.8 37 0 1.689 5.27 5.92 60
2 792384 159113 791393 15.4 6.8 24.6 10.7 96.4 96.2 378 0 1.219 3.98 4.12 41
3 1216576 243851 1216235 56.4 29.2 69.6 45.7 94.4 93.6 258 0 2.067 3.92 4.32 83
4 1238592 248713 1238497 63.9 36.2 76.5 54.4 97.0 96.5 16 0 2.992 6.02 7.54 79
5 1056896 211972 1055994 34.6 16.2 48.0 25.0 90.8 89.7 838 0 1.428 3.61 3.97 64
6 853312 171347 847890 15.9 7.1 27.9 10.8 93.8 93.3 2705 0 1.149 3.51 3.61 45
7 948608 190139 945462 27.8 14.0 39.4 21.2 97.1 96.8 2859 0 1.422 3.57 3.67 51
8 930112 186769 926062 14.7 6.9 29.2 10.1 89.1 88.5 3640 0 1.145 5.08 5.31 51
9 1138688 228652 1130927 28.9 15.0 37.8 21.7 89.0 87.9 7255 0 1.290 2.67 2.83 42
10 1390144 279145 1170515 38.4 20.6 36.6 27.7 98.7 98.6 215548 0 1.560 3.03 3.44 34
11 4220352 847460 1785559 89.4 74.6 84.0 86.6 100.0 100.0 2421567 0 11.163 1.27 2.38 25
12 3396352 681998 1876547 89.9 75.6 81.8 85.2 100.0 100.0 1494614 0 8.520 1.83 3.00 24
13 980480 196883 960668 18.4 9.0 29.6 13.1 86.2 85.5 14413 0 1.152 3.95 4.18 37
14 1125632 225622 1093084 23.9 10.8 36.7 16.2 93.4 93.0 32457 0 1.279 3.19 3.39 61
15 3027584 607948 3012539 93.1 65.9 81.6 79.3 99.9 99.9 13000 0 9.931 1.59 5.07 67
16 14088960 2829108 41827 40.2 25.7 34.5 35.3 99.9 99.8 13842528 0 1.673 12.29 13.33 0
all 37451712 469831 19140068 53.6 35.9 57.6 48.9 97.7 97.5 18052113 0 2.162 3.09 4.25 764
```
### Extra: `mcgsstats 5000 1024` (no GC)
Not in the plan. GC prunes child slots, so the end-of-search `r` at Hash 64
(153 GCs) is a post-pruning figure. At Hash 1024 no GC happens, and `r` is the
ratio at which an arena fills.
```
pos playouts po/s newleaf lf_tt tt_exp vh exp_dup path_tt inner rep r50 dup r_tree r_grph gc
1 1108224 222534 1107765 58.2 41.7 56.9 55.7 98.3 98.0 77 0 2.391 18.88 19.93 0
2 797824 160205 794007 18.7 11.5 18.3 17.5 97.4 97.3 2446 0 1.231 20.02 20.27 0
3 1261888 253391 1261542 71.8 57.0 70.8 70.1 95.2 94.8 270 0 3.546 20.37 21.55 0
4 1263936 253802 1263722 77.1 62.6 76.4 76.1 97.9 97.7 214 0 4.373 20.66 21.31 0
5 1150592 231042 1149845 53.9 38.8 52.4 51.3 94.6 93.9 747 0 2.168 19.50 20.45 0
6 972288 195238 967436 39.8 27.2 38.8 38.0 94.4 93.9 2466 0 1.660 19.58 20.01 0
7 994816 199762 994059 41.5 28.7 40.4 40.5 97.7 97.5 554 0 1.709 19.98 20.18 0
8 972480 195277 966716 26.4 17.0 25.8 24.6 92.8 92.3 5155 0 1.359 20.98 21.51 0
9 1183744 237699 1162150 42.6 28.8 41.9 39.8 96.0 95.5 20460 0 1.743 13.17 13.81 0
10 1859456 373384 1267715 55.9 42.9 54.2 53.1 98.5 98.4 586712 0 2.268 10.90 11.72 0
11 4432384 890036 1785406 93.7 83.5 89.6 93.1 100.0 100.0 2625372 0 15.750 4.41 8.97 0
12 3578688 718612 2007906 94.5 86.8 90.8 93.5 100.0 100.0 1367082 0 18.339 3.59 5.31 0
13 1042880 209413 1022986 31.7 21.7 30.9 29.5 89.2 88.5 15776 0 1.465 14.12 14.90 0
14 1226432 246271 1212002 39.7 28.1 38.7 37.7 96.5 96.3 14361 0 1.658 19.99 20.44 0
15 4031168 809471 3983269 98.0 89.9 96.6 96.6 100.0 99.9 44174 0 49.578 5.45 9.66 0
16 14052352 2821757 41766 40.1 25.6 39.4 35.1 99.9 99.8 13806006 0 1.669 12.29 13.33 0
all 39929152 501118 20988292 66.0 54.8 64.6 63.8 98.5 98.4 18491872 0 2.938 13.04 18.13 0
```
### Totals
| counter | 1000 ms | 5000 ms | 5000 ms, Hash 16 | 5000 ms, Hash 1024 |
| --- | ---: | ---: | ---: | ---: |
| playouts | 7,819,008 | 37,819,968 | 37,451,712 | 39,929,152 |
| new leaves (% of playouts) | 56.6 % | 51.3 % | 51.1 % | 52.6 % |
| `leaf_tt` (% of new leaves) | **60.1 %** | **60.7 %** | **53.6 %** | **66.0 %** |
| `leaf_tt` (% of playouts) | 34.0 % | 31.1 % | 27.4 % | 34.7 % |
| `leaf_tt_expanded` (% of new leaves) | 46.5 % | 45.0 % | 35.9 % | 54.8 % |
| `vh_hits` (% of first visits) | 57.4 % | 61.6 % | 57.6 % | 64.6 % |
| `leaf_tt_eval` (% of value calls) | 7.4 % | 13.2 % | 18.4 % | 2.1 % |
| value calls (% of playouts) | 23.7 % | 19.4 % | 21.3 % | 18.3 % |
| `exp_dup` (% of expansions) | 56.2 % | 57.2 % | 48.9 % | 63.8 % |
| `path_tt` / `inner` (% of playouts) | 96.0 / 95.6 % | 98.3 / 98.2 % | 97.7 / 97.5 % | 98.5 / 98.4 % |
| `rep_draws` (% of playouts) | 42.7 % | 47.6 % | 48.2 % | 46.3 % |
| `rep_draws` without position 16 | 780,246 | 4,160,055 | 4,209,585 | 4,685,866 |
| `r50_draws` | 0 | 0 | 0 | 0 |
| GC runs | 14 | 153 | 764 | 0 |
| `dup` (tree nodes / distinct keys) | 2.54 | 2.67 | 2.16 | 2.94 |
| visited / allocated | 10.6 % | 19.8 % | 32.4 % | 7.7 % |
| `r_tree` (edges per node) | 9.47 | 5.04 | 3.09 | **13.04** |
| `r_graph` (edges per distinct key) | 14.03 | 7.38 | 4.25 | **18.13** |
`tt_halfmove_hist`: the halfmove clock at `leaf_tt` hits, as a share of hits.
| halfmove | 1000 ms | 5000 ms | 5000 ms, Hash 16 | 5000 ms, Hash 1024 |
| --- | ---: | ---: | ---: | ---: |
| 0 | 22.5 % | 22.2 % | 21.0 % | 22.0 % |
| 1–3 | 28.4 % | 27.9 % | 26.0 % | 28.0 % |
| 4–7 | 36.5 % | 34.6 % | 38.6 % | 29.8 % |
| 8–15 | 12.4 % | 15.0 % | 14.0 % | 19.8 % |
| 16–31 | 0.24 % | 0.38 % | 0.38 % | 0.35 % |
| 32–63 | 0 | 0 | 0 | 0 |
| ≥ 64 | 0 | 0 | 0 | 0 |
Time split, as a share of `playout()` cycles (rdtsc, stats build). `vhash` is
also counted inside `backprop` (the store) and in leaf evaluation (the probe).
| part | 1000 ms | 5000 ms | 5000 ms, Hash 16 | 5000 ms, Hash 1024 |
| --- | ---: | ---: | ---: | ---: |
| value (net + qsearch) | 23.0 % | 18.9 % | 20.1 % | 18.2 % |
| policy | 13.9 % | 14.0 % | 15.5 % | 12.2 % |
| movegen | 5.4 % | 5.2 % | 5.5 % | 5.0 % |
| `select_child` | 28.0 % | 30.7 % | 28.8 % | 32.3 % |
| backprop loop | 11.1 % | 11.7 % | 11.1 % | 12.8 % |
| ValueHash probe + store | 6.2 % | 6.3 % | 5.9 % | 6.7 % |
| `make_move` | 5.3 % | 5.7 % | 5.6 % | 5.7 % |
### Derived bounds (stats build)
The table gives the search time MCGS could free, as a share of playout time.
`f_value` is applied per value call and `f_policy` per expansion, because
those are what the timers cover.
| | 1000 ms | 5000 ms | 5000 ms, Hash 16 | 5000 ms, Hash 1024 |
| --- | ---: | ---: | ---: | ---: |
| plan formula `f_value·max(0, leaf_tt − vh_hits)/value_calls + f_policy·exp_dup/expansions` | 8.96 % | 8.03 % | 7.59 % | 8.16 % |
| exact value term `f_value·leaf_tt_eval/value_calls + f_policy·exp_dup/expansions` | 9.52 % | 10.51 % | 11.28 % | 8.13 % |
| of which policy (`f_policy·exp_dup/expansions`) | 7.82 % | 8.03 % | 7.59 % | 7.75 % |
| cost upper bound `f_select + f_backprop` | 39.1 % | 42.4 % | 39.8 % | 45.1 % |
- **The saving is mostly policy, not value.** ValueHash already answers almost
every leaf transposition.
- The value evaluations MCGS would still skip (`leaf_tt_eval`: transposed
leaves that missed ValueHash) are 2–18 % of value calls.
- They grow with GC because ValueHash is small: 64 MB / 32 / 12 B ≈ 175k
entries, so entries get overwritten.
- About 55 % of expansions repeat an already-expanded key, and those policy
calls are what MCGS saves.
- **The plan formula's value term is 0 at 5000 ms (Hash 64 and Hash 16)**,
because `vh_hits > leaf_tt` there. After GC, ValueHash also answers positions
that GC dropped from the tree, which `leaf_tt` does not count. The exact
counter `leaf_tt_eval` is the right numerator, so the second row is the bound
to use.
- **The cost bound is loose.** `select_child` is about 30 % of playout time
today. The recompute per path node costs about one more `select_child` pass,
so the real added cost is below roughly 40 %. Steps 2 and 3 measure it. None
of these bounds covers what sharing subtree statistics is worth; only the SPRT
measures that.
- **Shared structure is everywhere.**
- 96–99 % of playouts pass through a node whose key has at least two tree
nodes.
- On average there are 2.2–2.9 tree nodes per distinct position.
- **Variant 5d (window key for halfmove ≥ T).**
- No `leaf_tt` hit had halfmove ≥ 32, and 0.24–0.38 % had 16–31. So T = 16
would lose under 0.4 % of the merges here, and T ≥ 32 none.
- That says little: every bench position starts with halfmove 0–8, so long
reversible stretches are under-represented. `r50_draws` is 0 for the same
reason.
- **Repetition draws are common: 43–48 % of playouts.**
- Position 16 (`6k1/6p1/8/6KQ/1r6/q2b4/8/8 w`) alone has 2.6M of the 3.3M at
1000 ms and 13.9M of the 18.0M at 5000 ms. It is a perpetual-check position
where 98 % of playouts end in a repetition.
- Without it there are still 0.8M (1 s) to 4.7M (5 s) repetition-draw
playouts, mostly in positions 10–12.
- So the per-edge draw counts of 3.5 will get real use.
### Cross-check against the ValueHash comment (37–85 %)
The comment in `mcts.h` says 37–85 % of leaf evaluations in a 5-second search
repeat a position already evaluated. Measured `leaf_tt` over all positions:
- 60.1 % at 1000 ms;
- 60.7 % at 5000 ms;
- 53.6 % at Hash 16;
- 66.0 % without GC.
All four are inside the range. Per position the spread is wider, 15–98 %:
- Low: the open middlegames 2 and 8, at 15–26 %.
- High: the pawn endgames 11 and 12 and the rook endgame 15, at 89–98 %.
The comment does not say which positions it measured, so a wider spread per
position is plausible. `vh_hits` stays within a few points of `leaf_tt` in every
row, which is consistent with the counters being right.
### Edges per node for the arena split (step 2)
| measurement | `r_tree` (edges per visited node) | `r_graph` (per distinct key) |
| --- | ---: | ---: |
| 5000 ms, Hash 1024, no GC (growth ratio) | **13.0** (per position 3.6–21.0; middlegames 18.9–21.0, endgames 11/12/15 3.6–5.5) | 18.1 |
| 5000 ms, Hash 64, end of search after 153 GCs | 5.0 (2.6–12.3) | 7.4 |
| 1000 ms, Hash 64 (14 GCs) | 9.5 | 14.0 |
| 5000 ms, Hash 16 (764 GCs) | 3.1 | 4.3 |
- With 16 B edges and 32 B nodes, the edge-to-node arena byte ratio is `r/2`:
6.5 at r = 13, about 10 for middlegames at r ≈ 20.
- GC keeps pruned nodes and drops their edges, so `r` right after a collection
is far below the ratio at which the arenas fill between collections.
- The no-GC figure decides which arena fills first. Step 2 should size for it,
or for the middlegame value, and check that the 5000 ms Hash 64 runs do not
hit GC on the node arena first.
## Step 2: Edge/Node split (`mcgs-step2-split`)
Code at `fb1b8a5`, on top of `mcgs-plan` (`479f6cf`). Commits:
- `18911b0` tests: add `tests/fischer.epd` (sha256 `4bc384f2…70b3cd`, checked);
- `6629525` the split itself;
- `226106e` the `verify` command (VERIFY builds only);
- `fb1b8a5` the arena-split comment.
What changed: 16-byte `Edge` and 32-byte `Node` in two arenas (plan 3.2), lazy
node creation, edge visits kept equal to child visits, selection and root
decisions on edges, root index as a member, and mark → forwarding → slide →
remap compaction for both arenas with the tree-exact threshold. `key`/`check` are
set at node creation, and `u`/`base` are set by pruning. Nothing reads them yet.
`draws` stays 0. Path draws still live in `node.state`.
**Arena split: 8 edges per node** (edge arena 128 of every 160 bytes). All of the
following are local single runs at 5 s, Hash 64, on the 16 bench positions. GC runs:
| | main | 4 | 6 | 8 | 13 | 20 |
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
| GC runs | 200 | 217 | 183 | 184 | 184 | 249 |
- 13 (the no-GC growth ratio) cut middlegame collections further. It gave 2–3× more
in positions 11, 12 and 15, where the node arena fills first.
- 8 stays near main in every phase.
- Step 4 re-measures this split once the graph exists.
Deviations from the plan's wording:
- `src/uci.cpp` gains the VERIFY-only `verify` command.
- VERIFY builds also run `verify_tree` at the end of every search, not only on
the next search. Otherwise a single `go` would never be checked.
- `verify_tree` additionally recomputes each node's state from its position and
its path, including repetition. That is exact while the search is a tree.
- Check (b) identifies nodes by move path, not by key, because a tree has
several nodes per key.
- `info string reused N nodes` now counts positions, not child slots.
### Gates (all on the owner's machine, 2026-11-16)
- **Build:** `make -j EXE=rigby-dev` and the VERIFY build, zero warnings.
- **Bench:** `663779`, identical to main.
- **Perft:**
- `perftsuite`: all passed (590,175,385 nodes);
- `perftfile tests/fischer.epd 5`: 960 positions, 0 failed, 17,614,927,759 nodes, 53 s.
- **Reuse sequence**, Hash 256, `go nodes 50000`, 10 moves (best move plus the
second PV move): every `bestmove` and every `info depth` line (depth, seldepth,
score, nodes, PV) identical to main. Only `nps`, `time`, `hashfull` and the
`reused N` count differ.
- **VERIFY searches**, all clean (`tree verified` after every reroot, GC and
search, no abort):
- the `go nodes 200000` positions of section 6, including the 960 start with
`UCI_Chess960 true`;
- forced GC with `go nodes 300000`: Hash 1 gave 144 collections (startpos) and
121 (960); Hash 2 gave 82 and 63;
- the reuse sequence with the VERIFY build at Hash 64, at Hash 1 (28–36
collections per move) and from the 960 start.
- Under GC the output differs from main because the bytes per node differ.
That is expected.
- **`verify`:**
- (a) 96,434 random plies over 7 standard and 960 FENs, incremental key = FEN key;
- (b) three forced collections (to 1/2, 1/4, 1/8) and a reroot on 4
positions, all survivors identical.
- **Smoke:**
- `go nodes 1`, `go nodes 2`, `go depth 1` on the section 6 positions (plus
the perpetual-check bench position and two no-move positions): output
identical to main;
- cutechess-ob: 100 games of dev vs main at 2+0.02, Hash 16, UHO book, and 20
games of the VERIFY build against itself at `nodes=20000`. All games ended by
mate, the 50-move rule, repetition or insufficient material. There were no
illegal moves, disconnects, time forfeits or aborts. Not strength evidence.
- **Note:** on `6k1/5ppp/8/8/8/8/5PPP/3R2K1 w - - 0 1` both main and step 2 play
`g1f1` at 200k nodes, not `Rd8#`. White is a rook up, every move already has
Q ≈ 0.996, and the mate (Q = 1) barely stands out. This was there before the
split.
### NPS versus main (local, noisy machine)
The machine had other load (about 40 % CPU from other applications), so main and
step 2 were run interleaved.
| measurement | main | step 2 | ratio |
| --- | ---: | ---: | ---: |
| `bench` nps, 5 alternating runs each (mean) | 3,443,510 | 3,356,540 | 0.975 |
| playouts/s, 5 s per bench position, Hash 64, interleaved per position, 2 rounds | 610,987 | 545,670 | **0.893** |
| the same at Hash 1024 (no GC), 1 round | 778,216 | 679,995 | 0.874 |
- The loss grows with tree size (−2.5 % on bench's 5000-playout trees, −11 to
−13 % at 5 s). It is the same without GC, so it is in the playout, not in
compaction.
- Likely cause: selection now loads every visited child node, scattered over
the node arena, where it used to read sibling Q values from one contiguous
block.
- A software prefetch of those nodes and `alignas(32)` nodes were each tried and
each measured within noise (+0.5 %, +0.7 %). Both were dropped.
- Variant 5b (edge-Q cache) is the plan's answer to this cost.
- The drop is over 3 %, so the plan's LTC condition applies.
### SPRT (owner)
- STC Non-Regression `[-5.00, 0.00]`, 8.0+0.08, Threads=1, Hash=64,
`UHO_Lichess_4852_v1.epd`: link and outcome to be filled in.
- LTC Non-Regression `[-5.00, 0.00]`, 40.0+0.40, Threads=1, Hash=256 (NPS drop
> 3 %): link and outcome to be filled in.
## Step 3: MCGS core (`mcgs-step3-core`)
Code at `14f672a`, on top of `mcgs-step2-split` (`5424e1a`). Commits:
- `6ec8769`: the MCGS core (search, key table, sizing, graph-safe GC
threshold, graph `verify_tree`, key-based check (b));
- `14f672a`: checks (c) and (d) of the `verify` command (VERIFY builds only).
**Bench: 764208** (step 2 and main: 663779). The bench changes for three reasons:
- The tree becomes a graph: transpositions share nodes, so playouts run on
through existing nodes, and their depths and visited positions change.
- The root gets its own evaluation, and N = 1 + the edges' visits.
- Repetitions and the 50-move rule are judged on every playout instead of
once per node.
What changed (plan 3.1–3.5 and 3.6.5):
- **Key table.** Each slot is 8 bytes, `{key_hi, node}`, with linear probing.
The table is a power of two with at least 2× the node arena's slots. A hit
needs the full key and the 16-bit check. The table is rebuilt after every
collection and reroot.
- **Node creation.** `create_node` evaluates a position on its first visit
(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 they are only ever counted in
`edge.draws`. An edge links to its child on first selection, to an
existing node when the table has one. `MAX_PLAYOUT_DEPTH` is 512.
- **Backprop.** For every path node: `edge.visits++` (and `draws++` for a
path draw), `node.visits++`, and q = (base·u − Σ (N−D)·c.q) / N, summed in
`double`. ValueHash is stored for every path node, with no `TERMINAL_DRAW`
test. The butterfly update is as before.
- **Edges everywhere.** Selection, root decisions, score, PV and dashboard
use edges, with draws counted as 0. The PV also stops after a repeated
position and at 64 plies.
- **Root check.** At search start, the root's edges are checked against its
legal moves. If they differ, the graph is cleared.
- **GC threshold.** It uses a visited bitmap and counts the root apart, so
the estimate stays an upper bound on a DAG.
- **Hash split.** Hash now covers the node arena, the edge arena (still 8
edges per node) and the table. The table's power of two is rounded down or
up, whichever leaves more nodes. At Hash 64 that gives 353,894 nodes and
2^20 slots (step 2: 406,323 nodes).
Deviations and choices the plan does not cover:
- **Full node arena.** If node allocation fails, the playout is dropped
without a trace: no visit is counted and no iteration is used. The graph is
then collected. The plan only says what happens when expansion fails
(value −n.q, the node's visit counted as a base visit, so q = u stays).
- **Depth limit.** At `MAX_PLAYOUT_DEPTH`, the node reached is not changed;
only the edge into it counts the visit. The recompute reads its q anyway.
- **Terminal nodes** count each visit in `base` as well, so N = base + Σ
edge visits holds for every node and VERIFY can check it everywhere.
- **Former roots.** `verify_tree` accepts a non-terminal node with
insufficient material at the root and at positions of the game history
(former roots). Insufficient material is never terminal at the root.
- **Arena split.** It stays at 8 edges per node, the step 2 value. In graph
searches the edge arena fills first: at the end of 5 s searches,
`hashfull` comes from the edge arena. Step 4 re-measures the split, as
planned.
### Gates (owner's machine, 2026-11-16)
- **Build:** normal and VERIFY builds, zero warnings.
- **Bench:** `764208`.
- **Perft:**
- `perftsuite`: all passed (590,175,385 nodes);
- `perftfile tests/fischer.epd 5`: 960 positions, 0 failed,
17,614,927,759 nodes, 55 s.
- **VERIFY searches** (`go nodes 200000`), each ending with `tree verified`
and no abort:
- startpos;
- the transposition line;
- the history repetition (`g1f3 g8f6 f3g1 f6g8 g1f3 g8f6`);
- bench positions 11, 12, 15 and 16;
- `8/8/8/4k3/8/8/2KR4/8 w - - 95 100` (seldepth 5);
- the mate-in-1 FEN (still `g1f1`, as on main and step 2);
- the 960 start with `UCI_Chess960 true`.
- **Forced GC** (`go nodes 300000`), every collection verified:
- Hash 1: 190 collections (startpos) and 145 (960);
- Hash 2: 104 and 77.
- **Reuse sequence** (VERIFY build, `go nodes 50000`, best move plus the
second PV move, 10 moves), clean every time:
- Hash 64 (21k–69k positions reused per move);
- Hash 1 (24–42 collections per move);
- the 960 start at Hash 64.
- **`verify`**, all passed:
- (a) 96,434 plies, incremental key = FEN key.
- (b) Three forced collections (to 1/2, 1/4 and 1/8) and a reroot on 4
positions: every survivor is identical by key, including edges and child
keys, and no pruned node has more visits than a kept one.
- (c) Five positions with forced or frequent repetitions and 50-move draws
(knight shuffle in the history, perpetual check, KR v K at half-move 95,
two pawn endgames). Every node state matches its position alone, and the
draws appear on edges: 30 to 29,077 draw visits per position. In the
KR v K position, 10,504 draw edges are at half-move 100+.
- (d) After every forced collection and reroot, the table has exactly one
entry per surviving node, and the table finds each node by its position.
- **Smoke:**
- `go nodes 1`, `go nodes 2` and `go depth 1` on the section 6 positions,
two no-move positions and a KB v K root: clean.
- 20 VERIFY self-play games at `nodes=20000`, Hash 16: all ended by mate,
repetition, the 50-move rule or insufficient material, with no abort.
- **Smoke, step 3 vs main: FAILED.** 100 games at 2+0.02, Hash 16, UHO book,
cutechess-ob, concurrency 10, while the VERIFY self-play (concurrency 10)
and the owner's own game were running. Step 3 lost **2 games on time**
(games 31 and 81, both as White, rook endgames at ply 180–181, half-move
clock about 70). There were no illegal moves, disconnects or aborts. See
the next section.
- **Control:** step 3 vs main and step 2 vs main, run at the same time, 100
games each at concurrency 6. There were no time forfeits, but step 3 still
had 23 moves in 11 games that stopped at ≤ 64 playouts. Step 2 and main had
none.
### Time forfeits: rerooting a graph is O(graph)
Step 3 ended moves at 64 playouts in late endgames (the clock is checked every
64 playouts, and those moves were already past the hard limit). In both
forfeits, every step 3 move over the last 10–20 moves had 64 playouts in
about 28 ms. In the same games, main searched about 10,000 playouts per move.
Cause, measured by replaying game 31 in one session (Hash 16, local
instrumented build that is not committed):
- **Cost before the first playout.** With `go nodes 1` after each move,
step 3 averages 3.5 ms (max 14 ms), against 0.3 ms for main and step 2.
- **The reroot itself.** Over 179 reroots it took 3.3 ms on average and kept
27,262 nodes on average: mark 1.4 ms, slide and remap 1.6 ms, table rebuild
0.26 ms. The worst case was 14.5 ms with 65,081 nodes kept.
- **Why it keeps so much.** In a reversible endgame, almost the whole graph
stays reachable from the new root, because the old positions can be reached
again. A tree reroot keeps one subtree, so main's cost stays small.
- **Why the clock drains.** At 2+0.02 under heavy load, a fixed cost per move
above the 20 ms increment drains the clock.
This is a gap in plan 3.6.6. "Reroot = mark/compact with T = 0" is O(nodes
kept), and on a graph that is close to O(graph) in endgames. As instructed, I
did not change the design. Options for the owner:
- (a) Reroot by moving the root index only (unreachable parts go at the next
collection, and the table stays valid). This changes 3.6.6.
- (b) Make compaction cheaper (a forwarding array instead of `lower_bound`,
reused buffers). This is a constant factor only.
- (c) Count the setup cost in time management.
The 8+0.08 STC has a 4× larger increment, but OpenBench workers also run
under load.
### Measurements (local, owner playing a game at the same time: noisy)
**Playouts/s at 5 s per bench position, Hash 64.** One round, the four
engines interleaved per position. Step 3 is run twice: the normal build and
the counter build.
| pos | main | step 2 | step 3 | step 3 / main |
| ---: | ---: | ---: | ---: | ---: |
| 1 | 200,122 | 181,012 | 117,808 | 0.59 |
| 2 | 148,819 | 134,104 | 111,678 | 0.75 |
| 3 | 217,946 | 202,846 | 108,144 | 0.50 |
| 4 | 220,530 | 197,230 | 106,011 | 0.48 |
| 5 | 197,654 | 171,347 | 124,401 | 0.63 |
| 6 | 168,134 | 161,465 | 113,824 | 0.68 |
| 7 | 179,816 | 162,171 | 119,518 | 0.66 |
| 8 | 173,057 | 164,973 | 127,588 | 0.74 |
| 9 | 227,084 | 204,864 | 148,048 | 0.65 |
| 10 | 335,241 | 318,534 | 192,549 | 0.57 |
| 11 | 959,036 | 912,732 | 425,445 | 0.44 |
| 12 | 774,695 | 703,203 | 361,420 | 0.47 |
| 13 | 191,421 | 175,871 | 133,590 | 0.70 |
| 14 | 199,466 | 194,403 | 147,058 | 0.74 |
| 15 | 667,244 | 678,618 | 101,590 | 0.15 |
| 16 | 4,619,553 | 4,342,926 | 3,595,617 | 0.78 |
| all | **592,489** | **556,526** | **377,088** | **0.64** (0.68 vs step 2) |
- `bench` nps, 5 alternating runs each (mean): main 2,996,116, step 2
2,974,460, step 3 2,572,979 (0.86× main).
- Playouts are longer, so playouts/s understates the positions searched.
The mean playout depth at 5 s is:
| position | main | step 2 | step 3 |
| --- | ---: | ---: | ---: |
| startpos | 14 | 14 | 13 |
| bench 11 | 12 | 12 | 16 (seldepth 80) |
| bench 15, KR v K | 6 | 6 | 28 (seldepth 100) |
With always-descend, a playout runs through existing nodes until it reaches
a new position, a repetition or the 50-move rule. In reversible endgames it
wanders through cycles. In bench 15, 30 % of playouts end in a repetition,
and the root score is 739 cp against main's 1,701. The plan leaves stopping
early to variant 5a.
- In the 2+0.02 games (heavy load), the median playouts per move was 4,480
for step 3 against 8,256 for main. In the control match it was 5,312
against 9,664, with step 2 at 9,024.
**Rates** from the counter build (5 s, Hash 64, same run as above):
| pos | playouts | mean depth | lookups | **hit %** | **path draw %** | of which 50-move % | new node % | GC |
| ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| 1 | 621,248 | 13.4 | 769,706 | 19.3 | 0.0 | 0 | 100.0 | 10 |
| 2 | 540,608 | 21.2 | 581,323 | 7.1 | 0.1 | 0 | 99.9 | 6 |
| 3 | 563,520 | 12.8 | 710,180 | 20.8 | 0.1 | 0 | 99.9 | 10 |
| 4 | 528,640 | 19.0 | 613,787 | 14.0 | 0.1 | 0 | 99.9 | 7 |
| 5 | 620,096 | 11.3 | 727,622 | 14.9 | 0.1 | 0 | 99.9 | 9 |
| 6 | 589,696 | 18.5 | 629,636 | 6.8 | 0.3 | 0 | 99.5 | 7 |
| 7 | 587,392 | 17.9 | 632,662 | 7.4 | 0.2 | 0 | 99.7 | 7 |
| 8 | 627,456 | 15.4 | 669,276 | 7.0 | 0.7 | 0 | 99.2 | 8 |
| 9 | 747,520 | 20.0 | 879,332 | 19.1 | 4.8 | 0 | 95.1 | 3 |
| 10 | 958,144 | 15.2 | 901,621 | 21.4 | 25.9 | 0 | 73.9 | 3 |
| 11 | 2,148,608 | 16.7 | 1,051,775 | 45.3 | 71.8 | 0 | 26.8 | 2 |
| 12 | 1,762,496 | 19.7 | 835,300 | 52.2 | 71.5 | 0 | 22.7 | 1 |
| 13 | 671,360 | 22.4 | 731,789 | 9.2 | 0.6 | 0 | 99.0 | 5 |
| 14 | 766,144 | 12.5 | 842,901 | 10.7 | 1.7 | 0 | 98.3 | 9 |
| 15 | 522,688 | 28.3 | 2,026,421 | 83.8 | 32.3 | 2.15 | 62.9 | 1 |
| 16 | 17,866,176 | 4.0 | 53,747 | 18.2 | 98.3 | 0 | 0.2 | 0 |
| all | 30,121,792 | 9.5 | 12,657,078 | **30.1** | **69.2** | 0.04 | 29.4 | 88 |
- **Lookup.** A lookup is the table probe when an edge is first selected (no
child linked yet). A hit links the edge to an existing node.
- **Hit rate.** 30.1 % of lookups hit over all positions: 7–21 % in
middlegames, 45–52 % in the pawn endgames and 84 % in KR v K.
- **Path draws.** 69.2 % of playouts end in a path draw, almost all by
repetition. Without position 16 (perpetual check), the figure is 26.8 %.
- **Other endings.** Over all positions, 420,673 playouts ended at a terminal
node and 87 at a node that could not be expanded. One playout was dropped
because the node arena was full, and none reached the depth limit.
- **Edge arena.** Middlegames fill the edge arena first. At 8 edges per node,
`hashfull` reached 965 at 5 s from startpos, against 661 for main.
### SPRT (owner)
The plan recommends these tests, both with Threads=1 and
`UHO_Lichess_4852_v1.epd`:
- STC 8.0+0.08, `[0.00, 5.00]`, Threads=1, Hash=64, base `main` (bench
663779): https://bench.rektdie.com/test/5312/. Result as shown on the test
page:
```
Elo | -8.91 +- 6.44 (95%)
SPRT | 8.0+0.08s Threads=1 Hash=64MB
LLR | -3.19 (-2.94, 2.94) [0.00, 5.00]
Games | N: 4758 W: 1504 L: 1626 D: 1628
```
The workers report 106 games lost on time (18 + 88). The earlier Rigby STC
test 5308 lost none in 1618 games.
The owner chose a single STC test against `main`, so it measures steps 2 and
3 together. Tests 5310 (STC) and 5311 (LTC) against `mcgs-step2-split` were
deleted soon after they started. The owner started the test knowing about the
failed smoke gate; the reroot is unchanged.
## Step 3b: reroot moves only the root (`mcgs-step3-reroot`)
Code at `d38f0b1`, on top of `mcgs-step3-core` (`f4b79a4`). This deviates from
plan 3.6.6, on the owner's decision after the time forfeits above.
**Bench: 764208**, unchanged, because bench never reuses a graph.
What changed:
- `Tree::reroot` only sets the root index. It no longer compacts.
- Nodes the new root no longer reaches keep their memory and their table
entries until the next collection. Search may link to them again in the
meantime. The collection keeps only what the root reaches.
- `info string reused N` now counts every node in the graph, reachable or
not.
- **VERIFY:**
- `verify_tree` requires full reachability only right after a collection.
The table must always hold every node in the arena.
- Check (b) now verifies two things: a reroot changes nothing, and the next
collection keeps exactly the nodes the new root reaches, unchanged.
Gates (owner's machine, 2026-11-16):
- Zero warnings. Bench 764208.
- `verify` (a)–(d) passed. The reroot check reported, for example, 10,803
nodes in the pawn endgame, with 10,802 reachable from the new root and
10,802 kept by the collection.
- The VERIFY searches of section 6 all passed, including forced GC: Hash 1
gave 190 and 145 collections, Hash 2 gave 104 and 77.
- The reuse sequence passed at Hash 64, at Hash 1 and from the 960 start.
- The `go nodes 1/2` and `go depth 1` smoke positions passed.
- Perft was not re-run, because move generation is untouched.
- No local games: the owner asked for the SPRT directly.
Replay of the 2+0.02 game that step 3 lost on time (game 31, Hash 16), measuring the time
before the first playout (`go nodes 1` after each move, 90 moves). This is a
local measurement:
| | mean | max |
| --- | ---: | ---: |
| main | 0.2 ms | 1 ms |
| step 3 | 3.5 ms | 13 ms |
| step 3b | 0 ms | 0 ms |
At `go movetime 40` in the same replay, mean playouts per move were: main
12,083, step 3 5,047, step 3b 5,899.
### SPRT (owner)
- STC 8.0+0.08, `[0.00, 5.00]`, Threads=1, Hash=64, base `main` (bench
663779): https://bench.rektdie.com/test/5313/. Result as shown on the test
page (0 games lost on time):
```
Elo | 12.24 +- 6.54 (95%)
SPRT | 8.0+0.08s Threads=1 Hash=64MB
LLR | 3.09 (-2.94, 2.94) [0.00, 5.00]
Games | N: 4600 W: 1533 L: 1371 D: 1696
```
This measures steps 2, 3 and 3b together against `main`. Merged into main
as PR #23 (`75098c8`).
## Variants on top of step 3b (one branch and one SPRT each)
Each branch is cut from `mcgs-step3-reroot` (`95e4909`) and tested against it
at STC 8.0+0.08, Threads=1, Hash=64, `UHO_Lichess_4852_v1.epd`, so a result
points at exactly one change. All passed the same gates before their test:
zero warnings, `verify` (a)–(d), the VERIFY searches of 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 smoke positions. There were no local games.
| branch | change | bench | test | result |
| --- | --- | ---: | --- | --- |
| `mcgs-v-arena12` | arenas sized for 12 edges per node instead of 8 | 764208 (unchanged, no GC in bench) | [5314](https://bench.rektdie.com/test/5314/) `[0.00, 5.00]` | stopped |
| `mcgs-v-edgeq` | 5b: each edge caches its child's Q; selection and recompute read only the edges (20-byte edge, no running sum) | 769193 | [5315](https://bench.rektdie.com/test/5315/) `[0.00, 5.00]` | stopped |
| `mcgs-v-stop` | 5a: a playout stops at a child with more visits than its edge | 609350 | [5316](https://bench.rektdie.com/test/5316/) `[0.00, 5.00]` | passed |
| `mcgs-v-pathrep` | selection scores Q = 0 for an edge whose child repeats the current path or the game | 755448 | [5317](https://bench.rektdie.com/test/5317/) `[0.00, 5.00]` | failed |
| `mcgs-v-novaluehash` | 5c: no value hash, all Hash to the graph | 765326 | [5318](https://bench.rektdie.com/test/5318/) Non-Regression `[-5.00, 0.00]` | passed |
| `mcgs-v-reconcile` | 3.6.7: after reuse each root edge is all draws or none | 764208 (unchanged, no reuse in bench) | [5319](https://bench.rektdie.com/test/5319/) `[0.00, 5.00]` | stopped |
Notes:
- **Arena split.** Collections over the 16 bench positions at 5 s and
Hash 64 (local, four builds running at once, so noisy): 8 edges per node
gave 67, 12 gave 53, 16 gave 51 and 20 gave 57. With 16, more collections
move into the endgames.
- **Edge-Q cache.** Root decisions still read the children's current Q.
The VERIFY build checks each cached Q (finite, in [-1, 1], 0 without a
child), and check (b) compares the cached Q too.
- **Stop rule.** The depth limit now ends a playout the same way the stop
rule does.
- **Reconciliation.** In reuse sequences from KR v K and two pawn endgames,
1–8 root edges were reconciled on most moves. The VERIFY build checks
after every reuse, collection and search that every visited root edge is
all draws exactly when its move draws.
Outcomes are in the table at the top. 5314, 5315 and 5319 were stopped
unfinished at the owner's request and are to be revisited later.
## Merged into main
| PR | branch | merge commit | bench on main |
| --- | --- | --- | ---: |
| #23 | `mcgs-step3-reroot` (steps 2, 3, 3b) | `75098c8` | 764208 |
| #24 | `mcgs-v-stop` (5a) | `150a876` | 609350 |
| #25 | `mcgs-v-novaluehash` (5c) | see `main` | 608763 |
The stop rule and the ValueHash removal each passed against
`mcgs-step3-reroot` alone. They were merged together at the owner's
request; no SPRT has measured the two together. Before the last merge the
combined code (`mcgs-v-novaluehash` with main merged in) passed the same
gates: zero warnings in both builds, `verify` (a)–(d), 300 tree checks in
the VERIFY searches with forced GC, the reuse sequences at Hash 64, Hash 1
and from the 960 start, and the smoke positions. Bench 608763, twice.
+901
View File
@@ -0,0 +1,901 @@
# Monte-Carlo Graph Search for Rigby: research and plan
Written 2026-11-16 against `main` at `c8d1ca6` (bench `663779`).
Implementation sessions read this file and `docs/mcgs-log.md` first. They do one
step from section 5, nothing else. If this plan turns out wrong for a step, that
session stops and explains instead of improvising.
Contents:
1. Facts about the current code (verified)
2. Research findings, with sources
3. Design
4. Measurement design (step 1)
5. Implementation plan
6. Test reference
7. Open questions for the owner
---
## 1. Facts about the current code (verified on c8d1ca6)
Read in full: `src/mcts.h`, `src/mcts.cpp`, `src/uci.cpp`, `src/eval.cpp`,
`src/position.h`, `src/types.h`, plus the key and halfmove parts of `src/position.cpp`.
- **Value net.** The brief says `(768->128)x2->1`. That is out of date. The
Makefile embeds `networks/rigby-value-v2.bin`, which is `(768->1024)x2` SCReLU
(PR #22). The README still describes v1. Value = `cp_to_q(quiescence(...))`,
with Q = tanh(cp/800).
- **`Node` is 20 bytes:** `u32 first_child, u32 visits, float q, u16 move,
u16 policy, u8 num_children, u8 state`. It is node and edge at once. Children
sit contiguously in `Tree::nodes_`. Index 0 is null and index 1 is always the root
(`Tree::root()` is `static constexpr`).
- **`q`** is a running mean from the view of the side that moved into the node,
updated incrementally: `q += (value - q) / visits`. Selection reads `child.q`
directly. The side to move at a node sees `-node.q`.
- **Leaf handling.** The first visit of a node only evaluates it
(`evaluate_leaf`); the second visit expands it (`expand`: movegen, butterfly
bias, policy net). The root is expanded before the first playout and never
evaluated, so the root's visits equal the sum of its children's visits. Every
other expanded node has at least one visit more.
- **`evaluate_leaf`** checks, in this order: no legal moves (mate → `TERMINAL_LOSS`,
stalemate → `TERMINAL_DRAW`); then, only at depth > 0, `halfmove >= 100`,
insufficient material and `is_repetition`, all stored as `TERMINAL_DRAW`; then
a `ValueHash` probe; then `eval::value`. Path-dependent draws therefore live
in the node today. That is fine in a tree and wrong in a graph.
- **`is_repetition`** is two-fold: any earlier occurrence of the key, same side
to move, `back = 4, 6, ... <= halfmove`, over `history_`. `history_` holds the
game history up to and including the root, plus the playout path. Two-fold
therefore also counts a single earlier occurrence in the game before the root.
- **`ValueHash`** takes 1/32 of Hash: 12-byte entries, a 32-bit check, replaced by
visits. Backprop stores `-node.q` for every path node except `TERMINAL_DRAW`
nodes. `evaluate_leaf` probes it before calling the net. It persists across
searches and is cleared on `ucinewgame`.
- **`ButterflyHistory`** is updated for every path move with the playout result
in cp and biases policy logits at expansion time.
- **`Tree::compact`** (used by `reroot` and `collect_garbage`) packs kept child
blocks in place. It relies on two things: a child block is allocated after its
parent's block, and every node has exactly one parent. `prune_threshold` relies
on visits only shrinking going down the tree. All three break on a DAG.
- **Root decisions** use child visits: `best_child` (most visits, then Q, then
prior), `best_move_settled` (smart pruning with `root_start_visits_`),
`principal_variation`, `print_info` and `draw_dashboard`.
- **Zobrist key** covers pieces, castling rights, side to move and the ep file
only when an ep capture is pseudo-legal. It excludes the halfmove clock, which
is good for merging.
- **`RIGBY_VERIFY_TREE`** checks, after reroot and after each GC: legality of
every child move, `num_children == legal moves`, and visits >= the children's
visits sum (+1 for non-root nodes).
- **`bench`** runs 16 positions × 5000 playouts, one `Searcher`, Hash 64.
Signature = Σ(playouts + depth sum). Each position has history `{key}`, so tree
reuse never happens. 5000 expansions are far below 64 MB, so GC never happens
either. **Bench therefore does not cover GC or reuse.** Separate checks are
needed (section 6).
- Baseline on this machine: `663779 nodes 3253818 nps` (bench nps is tree
positions per second, not playouts).
- The Chess960 perft EPD with node counts was **not in the repo**. The Chess960
session left `fischer.epd` in its scratchpad: 960 positions, D1–D6. It is now
copied, untracked, to `tests/fischer.epd`, and step 2 commits it.
`perftfile tests/fischer.epd 5` passes on c8d1ca6 (17.6·10⁹ nodes, 52 s).
- `cutechess-ob.exe` exists at `C:\Users\rektd\repos\OpenBench\Client\` and can
run local smoke matches.
## 2. Research findings
"Verified" means I read the source or text myself in this session. Anything else
is marked.
### 2.1 KataGo, "Monte-Carlo Graph Search from First Principles" (verified)
https://github.com/lightvector/KataGo/blob/master/docs/GraphSearch.md
- Naive node sharing is unsound. Child visit counts get inflated by other
parents, and parent Q goes stale or drifts. Updating every parent of a node is
also wrong.
- Derivation: PUCT approximately solves a KL-regularised policy optimisation
(Grill et al.). The node value is then the regularised utility of the posterior
policy: `Q(n) = (U(n) + Σ_a N(n,a)·Q(n,a)) / N(n)`, with
`N(n) = 1 + Σ_a N(n,a)` and `Q(n,a) = Q(child)`.
- **Edge visits** N(n,a), meaning how often PUCT at n chose a, are separate from
the child's N. PUCT uses edge visits:
`Q(n,a) + c·P(n,a)·sqrt(Σ_b N(n,b)) / (1 + N(n,a))`.
- Recompute Q idempotently on the playout path. Stale Q off the path is accepted:
exploration visits everything eventually, and a recompute makes a node correct
once its children are.
- **Stop rule:** optionally recurse only if `child.N <= edge visits`. Otherwise
increment the edge and recompute upward without a new child visit. KataGo stops
by default and has options to always continue or stop "leakily". Convergence
needs child visits → ∞ as edge visits → ∞.
- An incremental update is equivalent on trees. On graphs it "can be a little
tricky" but can be done. KataGo prefers idempotent updates. Tracking N·Q instead
of Q can give torn reads under lock-free multithreading.
- Game-over nodes: N = 1, U = Q = outcome.
- Hashes: 128–192-bit Zobrist is "usually collision-free". Cycle detection guards
against collision-induced recursion.
- Cycles are mostly ignored in the main text. KataGo (Go) uses a history hash
that blocks sharing only when a cycle is possible. The 2024-03-10 addendum
links a Google Doc (next item).
### 2.2 lightvector, "Thoughts on Handling N-fold Repetition in MCGS for Chess" (verified)
The Google Doc at
https://docs.google.com/document/d/1JbxsoMtr7_qAAkfYynAgpvuarMMJycaL5toXdnqVJoo
does not render for a fetcher, but its plain-text export
(`.../export?format=txt`) was readable. Dated 2024-02-28. The author notes he has
no chess implementation experience. Content:
- Baseline: put the full history in the hash. That is safe and degenerates to
MCTS. Do not XOR position Zobrists together for the history, because XOR
commutes and self-cancels; use a non-linear mixer such as splitmix64.
- Truncate history at provably irreversible moves (captures, pawn moves,
castling-right changes). States that differ only before such a move merge.
- Then prune history heuristically with `prune_history_for_hashing(history)`,
as KataGo does for Go. Possible rules: drop positions that are too many plies
old, or that differ from the current board on many squares, or a learned head
predicting whether a history position can recur.
- If a cycle still occurs, "terminate a playout if that playout's path ever
intersects itself", while still incrementing edge visits and recomputing N and
Q on the way back.
### 2.3 Czech, Korus, Kersting, "Monte-Carlo Graph Search for AlphaZero" (2020, verified)
https://arxiv.org/abs/2012.11045, CrazyAra (crazyhouse and chess).
- Stores visits and Q on **both edges and nodes**. When the next node is a
transposition, it computes `δQ = Q(s,a) − V*(s')`. If `|δQ| > ε_Q` (0.01), it
stops the playout without a net evaluation and backs up the correction
`Q_φ = N(s,a)·δQ + V*(s')`, clipped to `[Vmin, Vmax]`. Otherwise it keeps
descending. ε_Q is "the only hyper parameter".
- "We incorporate the step counter within the transposition hash key. This way
we cannot reach a state with the same key more than once within a trajectory.
Therefore, cycles cannot occur." Which counter is meant is **not stated**
(probably the ply or move count). Merges then happen only between paths of
equal length.
- Assumes Markovian states. Using history in the net input "did not result in a
major issue".
- 30–70 % memory reduction. The gain grows with search size. Chess gains are
smaller than crazyhouse gains.
### 2.4 Grill et al., "Monte-Carlo Tree Search as Regularized Policy Optimization" (ICML 2020)
https://arxiv.org/abs/2007.12509. I verified only the abstract: AlphaZero's
search heuristics approximate the solution of a specific regularised policy
optimisation. The form `π̄ = argmax_y [qᵀy − λ_N·KL(π_θ, y)]` with
`λ_N = c·sqrt(Σ_b n_b) / (|A| + Σ_b n_b)` is **from memory and not verified**.
What matters here is the consequence (verified through the KataGo doc): the
regularised target is defined by how often PUCT chose each action at this node,
which is the edge visits, not the child's total visits.
### 2.5 Lc0
- **PR #963 is not DAG search.** It is Naphthalin's "Beta-MCTS: a soft hybrid of
MCTS and Minimax", opened 2019-10-06, labelled "not for merge" and never merged
(verified on the PR page). The TalkChess thread cites it, which is probably
where the confusion comes from.
- Lc0's DAG search is `src/search/dag_classic`, merged as "dag-preview" in
**PR #2155** (borg323, 2025-04, "mostly the work of @Etcaqab"). Follow-ups:
#2274 garbage-collection thread (merged 2025-10), #2388 n_in_flight underflow
fix (merged 2026-05), #2291 fixed-size TT (open), #2295 TT memory calculation
(merged). Source read at master `476a0f7` (2026-10-20).
- **Layout** (verified, `node.h`). `LowNode` is the shared position: an
`edges_` array (move + policy), N, WL, D, M, number of parents. `Node` is a
realised edge with its own N, WL, D, M, `n_in_flight_`, a `sibling_` pointer,
a `shared_ptr` to the target `LowNode`, and bit flags including "edge was
handled as a repetition at some point". Both are ≤ 64 bytes. **Lc0 keeps Q
on the edge** (`Node`) as well as on the node (`LowNode`), like Czech.
- **Key** (verified, `PositionHistory::HashLast` and `Position::Hash`):
`HashCat` of the last `CacheHistoryLength+1` positions (default 0, so just
the last position). Each position's hash includes its repetition count, and
the rule-50 ply is mixed in. **Lc0 merges only positions with equal rule-50
ply and equal repetition count**, which is conservative. The TT maps the
64-bit hash to a `weak_ptr<LowNode>` and erases expired entries. The exact
container type was not checked. There is no full-position comparison.
- **Repetition** (verified, `search.cc`). Three-fold (`repetitions >= 2`) is a
pseudo-terminal: the `Node`, i.e. the edge, gets `SetRepetition()` and value
0. A two-fold inside the search tree (`TwoFoldDraws`, default on, depth >= 4
and depth >= plies since the previous occurrence) also marks the edge as a
repetition and propagates a draw above it. Fifty-move and insufficient
material are made terminal on the `Node` at extension, except at the root.
- **Transposition catch-up** (verified). `MaybeAdjustForTerminalOrTransposition`
replaces the edge's value by the LowNode's when the edge has fewer visits or
the LowNode is a transposition, and propagates the delta upward
(`n_to_fix`, `v_delta`). `ShouldStopPickingHere` stops a playout at a
transposition whose Node and LowNode differ by ≥ 0.01 WL (and other limits).
This is Czech's ε rule.
- Multithreaded, with `n_in_flight` on both Node and LowNode and reference
counting plus a background GC thread.
### 2.6 Monty (verified, `official-monty/Monty` master `0950aff`, 2026-05-12)
- **A tree, not a graph.** Transpositions are handled only by a hash table of Q
(`tree/hash.rs`: 32-bit check, q, d, visits). It is probed in place of the
network at a node's first visit and written on the way back for every path
node. Rigby's `ValueHash` copies this.
- Repetition and 50-move are checked by `game_state` with a stack of keys
cleared at every zeroing move, set on the node at first visit
(`node.set_state`). That is fine in a tree. Note: `halfm == 100` with mate
counts as mate. Monty's hash also receives the value of path-dependent draw
nodes. I did not check whether that matters.
### 2.7 Ceres (verified, `dje-dev/Ceres` main, `src/Ceres.MCGS`, last change 2026-09-12)
- Has a full MCGS implementation (`GNode`, `GEdge`, parent lists, `n_in_flight`
per edge).
- `PathMode`, default **`PositionEquivalence`**: nodes are coalesced by board
position. Alternative: `PositionAndHistoryEquivalence`, which keys on the
position plus a 96-bit **multiset** running hash of the positions since the last
irreversible move (`PositionWithHistoryHashes`: the running hash resets after
an irreversible move).
- **Repetition draws live on the edge as a count**, not a flag: `GEdgeStruct`
has `N` and `NDrawByRepetition` (both `int`), and
`Q = QChild·(N − NDrawByRepetition) / N`, so a draw visit counts as 0.
- `ReconcileDrawByRepetitions`: after graph reuse, an edge whose child board is in
the game history (graph-root to search-root spine plus prehistory) is
reclassified as a full draw (`NDrawByRepetition = N`). That is exact, because
that history is common to every path. Purely in-tree repetitions stay
path-dependent and are left to live detection.
### 2.8 Graph History Interaction literature
- Kishimoto & Müller, "A General Solution to the Graph History Interaction
Problem", AAAI-04 (verified, PDF text). GHI was first noted by Palay (1983).
Campbell (1985) split it into **draw-first** (a score involving repetition is
stored and wrongly reused for a position without repetition) and **draw-last**
(the reverse). Breuker et al.'s Base-Twin Algorithm (BTA) uses possible-draw
marks with base and twin nodes, needs an explicit graph, and must remove marks
every iteration "since marks are path-dependent information". The AAAI paper
stores path information for proven results and uses Kawano's simulation,
targeting proofs (df-pn, αβ) in checkers and Go.
- Campbell 1985 and Breuker, van den Herik, Uiterwijk, Allis 2001 ("A solution to
the GHI problem for best-first search", TCS 252) were **not read directly**,
only through the AAAI-04 summary.
- What carries over to MCGS: MCGS proves nothing, so exact GHI handling is not
needed. What is needed is to avoid the draw-first case systematically (never
store a path-dependent draw in a shared node) and to keep the draw-last error
bounded.
### 2.9 TalkChess, "Move repetitions in tree search + transpositions" (t=72136)
Page 1 of 2 was read. Page 2 could not be fetched (connection refused) and is
**unread**.
- koedem: shared nodes make repetition status path-dependent. He cites lc0 PR
#963.
- noobpwnftw: only the path with the globally shortest occurrence of a node may
expand it. Other occurrences are treated as terminal and rescored locally if
the path repeats.
- koedem's objections: the shortest path may go through a blunder, the main line
can be starved, and his example FEN is
`3r2k1/5ppp/8/8/8/8/5PPP/2R3K1 w`.
- No resolution on page 1.
### 2.10 Not verified
- The exact Grill formula (2.4).
- Which "step counter" Czech et al. hash (2.3).
- Campbell 1985 and Breuker 2001, read only second-hand (2.8).
- TalkChess page 2 (2.9).
- Lc0's TT container type (2.5).
## 3. Design
### 3.1 Conventions and invariants
- `v` = a value in [-1, 1] **from the side to move** at a position (what
`eval::value` returns).
- `node.q` and `node.u` are **from the view of the side that moved into the
node**: `node.q = −(stm value)`. This keeps Rigby's convention. It is
path-independent, because the side to move is part of the position.
- Edge `(n, a)` leads to child `c`. `c.q` is from the view of the side to move
at n, which is the side choosing a. So the edge value used in PUCT at n is
`Q(n,a) = (W(n,a) / N(n,a)) · c.q`, where `N(n,a)` = edge visits,
`D(n,a)` = edge visits that ended in a path-dependent draw, and
`W = N − D`. Draw visits count as 0. If `N(n,a) = 0`, FPU applies. If
`W = 0`, the edge value is 0.
- Node visits: `N(n) = base(n) + Σ_a N(n,a)`. A fresh node has `base = 1` and
`u = −v_leaf`. A pruned node (3.6) keeps its N in `base` and its Q in `u`.
- Recompute in mover view:
`n.q = (base·u − Σ_a W(n,a)·c_a.q) / N(n)`
Check: the side to move at n sees `−n.q = (base·(−u) + Σ W·c.q) / N`, which is
KataGo's formula with draw visits contributing 0.
- Terminal nodes (position-intrinsic only: checkmate, stalemate, insufficient
material): `u = q = +1` (the stm is mated, so the mover won) or 0. They have no
edges. N counts visits.
- **Only position-intrinsic facts are ever written into a node.** Repetition and
50-move results exist only as per-edge draw counts and as a playout's value.
### 3.2 Data layout
```
struct Edge { // 16 bytes, contiguous per node, created at expansion
u32 child; // node index, 0 = no node yet (lazy creation)
u32 visits; // N(n,a): how often PUCT at n chose a
u32 draws; // D(n,a): of those, playouts that ended in a path draw
u16 move;
u16 policy; // prior scaled to 0..65535
};
struct Node { // 32 bytes, created when a position is first reached
u64 key; // full Zobrist key
u32 first_edge; // 0 = not expanded
u32 visits; // N(n) = base + Σ edge visits
float q; // mover view, recomputed on the playout path
float u; // mover view: own evaluation, or the Q kept by pruning
u32 base; // weight of u: 1, or N at the time of pruning
u8 num_edges; // ≤ 218 legal moves
u8 state; // UNEXPANDED, EXPANDED, TERMINAL_LOSS, TERMINAL_DRAW
u16 check; // second fingerprint, see 3.5
};
```
Why this differs from the brief's 12-byte edge: the draw count must be per edge
and 32-bit. A perpetual-check edge in a long analysis can collect more than 65k
draw visits, so a u16 would saturate and silently bias Q. A one-bit flag is not
enough either (3.5). 16 bytes also keeps 4 edges per cache line. The node is 32
bytes, not 20, because it carries the key (needed to rebuild the table after GC
and to verify), `u` and `base` (needed for idempotent recompute and for pruning
without losing information) and a 16-bit second check.
**Key table:** open addressing with linear probing, power-of-two capacity
≥ 2 × node capacity. 8-byte slots `{u32 key_hi, u32 node}` (`node = 0` is
empty). Slot = `key & mask`. A hit needs equal `key_hi`, then the node's full
64-bit `key` and its 16-bit `check`. Nothing is ever deleted except by a rebuild
after GC or reroot (3.6), so there are no tombstones. About 16 bytes per node.
**Memory and the meaning of Hash.** Hash still means all search memory:
ValueHash (1/32, until variant 5c), key table, node arena, edge arena. With r
edges per node, a node costs about `32 + 16 + 16r` bytes. Today a node costs
20 bytes for every child, visited or not. The split between the arenas is set
in step 3 from the edges-per-node ratio measured in step 1 (`edge_bytes / node_bytes`
at the end of 5 s searches). GC runs when either arena or the table (load > 0.5)
is full.
### 3.3 Playout (always-descend base, step 3)
```
pos = root_pos; history_ = game history + root; path = [root]
loop:
n = path.back()
if n is TERMINAL: value = stm view of n.u; break
if n is UNEXPANDED: expand(n) (fails → playout ends here, value = -n.q, gc_pending)
e = select_edge(n)
pos.make_move(e.move); history_.push(pos.key); depth++
// Path-dependent draws are decided before the node lookup:
if is_repetition(pos) → path draw
else if pos.halfmove >= 100 and not checkmated(pos) → path draw
if path draw: value = 0; e is marked as a draw edge for backprop; break
if e.child == 0:
c = table.find(pos) // a transposition into an existing node
if !c: c = create_node(pos) // first visit: evaluate (3.1); value = its v
e.child = c; path.push(c); break
e.child = c
path.push(e.child)
if depth >= MAX_PLAYOUT_DEPTH (e.g. 512): value = -c.q; break // collision guard
```
- `checkmated(pos)`: if the child node exists, read its state; otherwise use
`pos.in_check() && !has_legal_move(pos)`. Mate takes precedence over the
50-move rule, as now. A repeated position cannot be mate, because the game
continued from its first occurrence.
- `create_node` = today's `evaluate_leaf` minus the path checks: movegen (mate
or stalemate → terminal); insufficient material → `TERMINAL_DRAW` (never at
the root); then the ValueHash probe; then `eval::value`.
- `expand` is unchanged apart from writing edges (`child = 0, visits = draws = 0`).
The priors are a snapshot from whichever path expanded the node, the same as
today.
- The root has no path checks (they apply to children), so it is never declared
drawn, as today. The root is created through `create_node` (one evaluation) and
expanded before the first playout.
### 3.4 Selection and root decisions
- PUCT at n over edges: `Q(n,a)` as in 3.1 for `N(n,a) > 0`, FPU otherwise;
exploration `cpuct(N(n)) · sqrt(N(n)) · P / (1 + N(n,a))`, using today's
formula with `N(n)` in place of `node.visits`. In a tree `N(n)` equals today's
`node.visits`. FPU = `−n.q − fpu_reduction·sqrt(Σ P over edges with N(n,a) > 0)`.
Root cpuct is chosen by `idx == root`.
- **Everything at the root uses edge visits:** best move (most `N(n,a)`, then
edge Q, then prior), smart pruning (`root_start_visits_` = root edge visits at
search start), score (`Q` of the best edge), `print_info`, the dashboard rows.
- **PV:** follow the best edge from each node. Stop when `child == 0`,
`visits == 0`, after 64 plies, or after a move whose position repeats the PV
or the history. Cycles make the 64-ply cap necessary, not cosmetic.
### 3.5 Repetition, 50-move and cycles
**Decision: key = the position only (today's Zobrist). Detect repetition and
50-move draws on every descent, after `make_move` and before the table lookup.
Record them per edge as a draw count `D(n,a)`, never in a node. The
reversible-window key with threshold T is variant 5d.**
Why counts and not a per-edge flag: an edge belongs to its parent node, and the
parent node is shared by every path that reaches it. A move can be a repetition
on one path to n and a fresh position on another. A sticky flag, as in Lc0's
`Node`, makes every later path see a draw. A count makes the edge value the
visit-weighted mixture of what the paths actually produced. Ceres does this with
`NDrawByRepetition` and the same formula. Both are approximations. Only the count
stays consistent as path frequencies change.
Why not put history in the key from the start (Lc0's rule-50 ply plus repetition
count, Ceres's history mode, Czech's step counter):
1. **It removes much of the merging.** Two move orders reach the same position
with a different halfmove clock whenever their pawn moves fall in a different
order. For example, `1.e4 Nc6 2.Nf3` has halfmove 2 and `1.Nf3 Nc6 2.e4` has
halfmove 0. A reversible-window key also refuses every transposition between
piece manoeuvres, which is where deep transpositions come from.
2. **The pure-position key is the KataGo and Ceres default** (Ceres's
`PositionEquivalence`), and every other option is a strict refinement. A
threshold variant (5d) can be added later without touching anything else.
3. **The error is bounded.** The value a shared node carries is a mixture over
real paths, never a fabricated draw. Repetition-sensitive positions (long
reversible sequences, perpetuals, fortresses) are exactly where 5d splits
nodes, and 5d's SPRT decides whether that is worth the lost merging.
Variant 5d, for comparison: when `halfmove >= T`, the key additionally mixes in a
**multiset** hash of the positions in the current reversible window (splitmix64
of each key, summed mod 2^64 so that order does not matter and there is no XOR
cancellation; the hash resets at each zeroing move, as in Ceres). Below T the key
is the position. Above T, paths with different reversible histories get
different nodes, so neither repetition nor the 50-move proximity mixes there. The
window multiset fixes its own length, so the halfmove clock is fixed too.
T = ∞ is the base. Path detection stays in either case, because repetitions
within the window must still score as draws.
**Cycles cannot cause infinite descent.** A cycle in the position graph uses only
reversible moves: a capture, a pawn move or a lost castling right changes the
position for good. So a playout that would re-enter a position already on its
path finds that position's key in `history_` within `halfmove` plies, with the
same side to move, at distance ≥ 4. `is_repetition` sees it and ends the playout
as a draw before the node is entered. A path therefore never contains a node
twice, and its length is bounded.
`MAX_PLAYOUT_DEPTH` only guards against a hash collision linking unrelated
positions (see the next point).
**There is no unbounded value feedback.** Nodes can still depend on each other
through a cycle: X→Y on one path, Y→X on another. But each recompute is a convex
combination: weights `base` and `W(n,a)` over `N(n)`, values in [-1, 1], draw
visits at 0. So every Q stays in [-1, 1] and only nodes on the path change.
There is no iteration to a fixed point, so nothing can diverge. The remaining
error is GHI's draw-last kind: Y's value includes X's value on paths where going
back to X would be a draw. The draw counts on that edge pull it towards 0 in
proportion to how often that actually happened.
**Collisions.** The table compares the full 64-bit key plus a 16-bit
`check = u16(mix64(colors[WHITE] ^ rotl(pieces[PAWN], 17) ^ rotl(pieces[KING], 41)))`
that is independent of the Zobrist key. That makes about 80 bits. With 2·10^6
nodes the chance of any false merge is about `n²/2^81 ≈ 2·10^-12` per search.
Without the check, 64 bits would give about `10^-7` per search, which is fine
for games but not for long analysis. The root is additionally re-validated at
search start: its edges must equal `generate_legal(root)`, otherwise the graph is
cleared. Illegal-move protection inside the graph rests on the 80-bit check.
VERIFY builds check legality of every edge (3.8).
### 3.6 Reuse and GC on a DAG
**Mark, then slide both arenas, then rebuild the table.**
1. **Mark.** Do a DFS from the root over `edge.child`, with a visited bitmap.
Pruning rule with threshold T: a reachable node with `N < T` (other than the
root) loses its edges. It keeps `visits`. It sets `u = q` (the current
mover-view Q) and `base = visits`, and `state = UNEXPANDED`. Its edges and
anything reachable only through them are dropped. `q` is unchanged, so no
value is lost, which matches today's behaviour.
2. **Threshold.** Same histogram as today: `kept(T) ≈ Σ over reachable nodes with N ≥ T of
(edges + edge targets)`. In a tree this is exact and equals today's rule. In
a DAG, reachability through pruned nodes can only lower the real number, so
`kept ≤ estimate ≤ target`. The policy therefore does not assume monotone
visits for safety, only for tightness.
3. **Forwarding.** `fwd_node[old] → new` for marked nodes, in index order. The
edge blocks of kept expanded nodes are sorted by `first_edge` and given new
starts in that order. Both arenas then slide toward the front in increasing
index order. Every destination is ≤ its source, so memmove in place is safe
**regardless of allocation order**. The tree assumption is gone.
4. **Remap.** Remap `node.first_edge` from the block map and `edge.child` from
`fwd_node`. A kept node's edges with a child always point to marked nodes,
because marking follows exactly those edges. The root becomes
`fwd_node[root]`. Make the root index a member, since `root()` can no longer
be the constant 1. Null slot 0 stays.
5. **Table.** Clear it and reinsert every surviving node by its own key. This is
O(nodes), like the rest of GC, and removes a whole class of remapping bugs.
6. **Reroot** = find the new root (walk the played moves along edges as today,
or look its key up in the table; both find the same node in a graph), then
mark/compact with T = 0. If the node is terminal, the graph starts fresh.
That covers insufficient material, which must not be the root's state.
7. **Root-edge reconciliation** (step 4). After reroot, the game history is
common to every path. For each root edge: if its move now gives a two-fold
repetition against `history_`, set `D = N`, so the edge becomes a pure draw.
If it does not but `D > 0`, those draws belonged to other histories: subtract
them (`N −= D`, root `N −= D`, `D = 0`). Root edges are then exact.
Ceres goes deeper with a depth-limited walk; that is not planned.
### 3.7 ValueHash and butterfly history
- ValueHash stays in step 3, unchanged: it is probed in `create_node` and
written for every path node (`−n.q`, visits). Path draws are never nodes, so
they are never written. That is cleaner than today's `state != TERMINAL_DRAW`
test. In a graph it only helps for positions the graph has dropped (after GC
or reroot) or never held. Removing it is variant 5c.
- Butterfly history is unchanged and path-based. The playout value is the leaf
value, 0 for a path draw, or the stopped node's value (5a).
### 3.8 Debug tooling (`-DRIGBY_VERIFY_TREE`)
Each node is visited once, by DFS from the root, carrying the position from the
first path that reaches it. Positions are path-independent apart from the clock.
The checks:
- `node.key == pos.key` and `node.check` matches. `table.find(pos)` returns this
node. The number of table entries equals the number of nodes after a rebuild.
- Expanded: `num_edges == legal moves`, every `edge.move` legal and distinct,
`first_edge + num_edges <= edges_used`.
- `edge.draws <= edge.visits`. `edge.visits > edge.draws ⇒ child != 0`.
`child < nodes_used`.
- `node.visits == base + Σ edge.visits` (expanded nodes, root included from
step 3). Terminal nodes have no edges.
- **No path state in nodes:** `TERMINAL_LOSS ⇔` checkmate and `TERMINAL_DRAW ⇔`
stalemate or insufficient material, recomputed from the position.
- `|q| <= 1`, `|u| <= 1`, finite.
- Step 2 only (still a tree): the in-degree of every node is exactly 1, the
root's is 0.
Unit-style checks run as a `verify` UCI command that exists only in VERIFY
builds:
- (a) Incremental key equals `set_fen(fen()).key` along random games, standard
and 960.
- (b) GC: snapshot every reachable node by key → (visits, q, edges by move →
(visits, draws, child key)), force `collect_garbage`, compare all survivors.
Do the same after `reroot`.
- (c) Repetition leak: search positions with forced repetitions, then run the
node-state check above.
- (d) Table consistency after every GC.
### 3.9 Choices that affect later batching or multithreading
- Edges have no `n_in_flight`. Virtual loss would need 2 more bytes per edge
(20-byte edges), or packing `draws` into fewer bits.
- Lazy child creation and table insert would need CAS on `edge.child` and on the
table slot, plus per-thread allocation chunks.
- `create_node` evaluates synchronously. Batching would need a "pending eval"
state that selection treats as in flight. Nothing in this design writes a value
that a pending node could not supply later.
- Idempotent recompute reads children without locks. Storing a mean `q` (not
N·Q) avoids KataGo's torn-read problem. Torn reads of `q` versus `visits` only
make a value briefly stale.
- GC and reroot are stop-the-world, which is fine with a pause-all-threads
barrier.
- Path draw detection uses each playout's own `history_` and is naturally
per-thread.
### 3.10 Optional variants (each its own branch and SPRT, never bundled)
- **5a Stop rule.** After linking or entering an existing child `c` with
`c.N > N(n,a)` (before the increment), end the playout: value = `−c.q` (stm view at
`c`), increment the edge, and recompute upward. Sub-variants: always stop;
leaky (stop with probability p, e.g. 0.5).
- **5b Edge-Q cache + incremental sum.** The edge stores the `c.q` it last folded
in (+4 bytes, a 20-byte edge). The node stores `S = Σ W·q_seen`. The
recompute is O(1): replace the path edge's term. Selection reads only
contiguous edges. This trades staleness of off-path children for locality and
NPS.
- **5c ValueHash removal.** Give its 1/32 to the graph.
- **5d Window-hash key for halfmove ≥ T** (3.5). Candidate T from the step-1
halfmove histogram of transposition hits.
- Later, not planned: Lc0-style two-fold handling (history two-folds need a
third occurrence); path-aware selection that scores an edge as 0 when it
repeats on the current path; a deeper reconciliation walk.
## 4. Measurement design (step 1)
Goal: bound what MCGS can gain before building it, and size the arenas. All
counting is behind `-DRIGBY_STATS` (`make STATS=1`). The normal build is
unchanged and bench-identical.
**Runner:** a new UCI command `mcgsstats <movetime_ms> [hash_mb]` searches the
16 bench positions. It uses a fresh `Searcher` per position (no reuse, so
results don't depend on order) and prints one row per position plus totals. Run
it at **1000 ms and 5000 ms**, Hash 64. Also run 5000 ms at Hash 16 to see GC.
**Transposition counters (exact).** These use an instrumentation-only
`std::unordered_map<u64, u32>` from key to the number of tree nodes with that key,
updated at node creation and rebuilt after GC and reroot. A second map from key
to the number of expanded nodes is kept the same way.
| counter | meaning | what it bounds |
| --- | --- | --- |
| `leaf_tt` | playouts whose new leaf's key already exists in the tree | the brief's "transposition rate"; value evals MCGS could skip |
| `leaf_tt_expanded` | ... and that existing node is expanded | how much subtree would be shared |
| `vh_hits` | first visits answered by ValueHash today | what is already saved |
| `exp_dup` | `expand()` calls for a key already expanded elsewhere | policy-net calls MCGS saves |
| `path_tt` | playouts passing through ≥ 1 node whose key has ≥ 2 tree nodes | how many playouts touch shared structure |
| `dup_nodes` | tree nodes / distinct keys, at the end | memory duplication |
| `rep_draws`, `r50_draws` | playouts ending in a repetition or 50-move draw | how much the draw-count path is exercised |
| `tt_halfmove_hist` | histogram of `pos.halfmove` at `leaf_tt` hits: 0, 1–3, 4–7, 8–15, 16–31, 32–63, ≥64 | upper bound of merges lost by variant 5d for each T |
| `visited / allocated` | nodes with visits > 0 / all nodes, at the end | edges-per-node ratio r for the arena split (3.2) |
**Time split.** Use `__rdtsc()` on x86 (`std::chrono::steady_clock` elsewhere)
around these parts, cumulative per search: value (`eval::value`, i.e. net +
qsearch); policy (`eval::policy` inside `expand`); movegen in `evaluate_leaf` and
`expand`; `select_child`; backprop loop; ValueHash probe and store; `make_move`
in `playout`; total `playout()`. Report each as a share of total playout cycles.
The timer overhead (≈ 10 reads × 20–40 cycles) is small against a playout. The
shares are from a stats build and labelled as such.
**How the numbers bound the gain** (to be filled with measured values in
`mcgs-log.md`):
- Search time MCGS could free is at most `f_value · max(0, leaf_tt − vh_hits) + f_policy · exp_dup`.
`f_*` are the time shares, and the rates are per playout or per expansion.
- From the opposite direction, MCGS adds a table lookup per new node plus a
recompute over the edges of each path node (about the cost of one more
`select_child` per path node). An upper bound for that is
`f_select + f_backprop` today. Steps 2 and 3 measure the real NPS cost.
- The effect of sharing subtree statistics (deeper effective search, the actual
point of MCGS) is not bounded by any of this. Only the SPRT measures it.
- Cross-check: the ValueHash comment claims 37–85 % of leaf evaluations repeat a
position. `leaf_tt` should land in that range, or the counters are wrong.
## 5. Implementation plan
Each step: its own branch from `main` (or from the previous step once merged),
small commits, every correctness gate from section 6 passed, `mcgs-log.md`
updated (branch, commit, bench; SPRT link and outcome left empty for the owner).
No step merges to main by itself.
Changes to the brief's suggested order, and why:
- **The DAG-capable compaction (forwarding tables, two arenas, no
allocation-order assumption) moves into step 2.** It must exist before step 3
can create a graph. Otherwise step 3 would have to disable GC and reuse, and
its SPRT would mix MCGS with "no tree reuse".
- **Step 4 shrinks** to the DAG-specific reuse behaviour (root-edge
reconciliation) plus table and arena sizing.
### Step 1: instrumentation (measurement only)
- **Branch:** `mcgs-stats`.
- **Files:** `src/mcts.h`, `src/mcts.cpp`, `src/uci.cpp`, `Makefile` (`STATS=1`
adds `-DRIGBY_STATS`), and a new `src/stats.h` if that keeps `mcts.cpp` tidy.
- **Brief:** Add the counters and timers of section 4, all under
`#ifdef RIGBY_STATS`, and the `mcgsstats` command, also stats-only. Do not
change search behaviour.
- The key→count maps are instrumentation-only and must be rebuilt after
`collect_garbage` and `reroot`. Walk the tree from the root and recompute
each node's key from its position.
- `rep_draws` / `r50_draws` count playouts that end at a `TERMINAL_DRAW` node
whose reason was repetition or 50-move. Record the reason in a stats-only
side table indexed by node, or recompute it.
- Run `mcgsstats 1000`, `mcgsstats 5000`, `mcgsstats 5000 16`. Put the tables
and the derived bounds into `mcgs-log.md` under "Step 1 measurements",
labelled as stats-build numbers.
- **Acceptance:** the normal build is bench-identical (`663779`, or main's
current bench if main moved), and the `STATS=1` build is also bench-identical.
The stats code must not change search. No new warnings. Cross-check: `leaf_tt`
is in the same range as the ValueHash comment's 37–85 %.
- **Verification:** build both variants, `bench` on both, `perftsuite`, and one
VERIFY build search to make sure nothing broke.
- **SPRT:** none. The code is compiled out of the shipped build and the bench is
unchanged.
- **Merge:** never. The branch stays on its own (owner's decision, 2026-11-16).
Later steps branch from `main`, not from `mcgs-stats`. To measure a later
branch with the stats build (e.g. when an SPRT disappoints), merge
`mcgs-stats` into a throwaway local branch, measure, and delete it. The stats
code never enters a step branch. Conflicts are expected once step 2 reshapes
`mcts.cpp`, so port the counters by hand on the throwaway branch.
### Step 2: Edge/Node split with tree behaviour preserved
- **Branch:** `mcgs-step2-split`.
- **Files:** `src/mcts.h`, `src/mcts.cpp`. `src/pretty.*` only if the dashboard
rows need new fields (they should not).
- **Brief:**
1. Introduce `Edge` (16 B) and the 32-byte `Node` of 3.2, in two arenas.
2. Expansion writes an edge block. A child `Node` is created only when its
edge is first selected.
3. Edge visits are kept equal to child visits. In a tree they are identical,
and selection, FPU and root decisions switch to reading `edge.visits` (and
`edge.policy`) now, with `child.q` for Q.
4. Keep the incremental `q` update and every float operation in the same
order. The point is bit-identical search. `u`/`base`/`key`/`check` and
`edge.draws` exist but are unused (or set and ignored).
5. Path-dependent draws stay in `node.state` for now. That is still correct in
a tree, and it moves in step 3.
6. Make the root index a member.
7. Replace `compact` and `prune_threshold` with the mark → forwarding → slide →
remap scheme of 3.6 for two arenas. No table yet. Keep the tree-exact
threshold rule. The pruned node keeps visits and q, as today.
8. Extend `verify_tree` per 3.8 (tree subset, in-degree 1) and add the `verify`
command with checks (a) and (b).
9. Hash is split between the arenas by the step-1 ratio. Document the split in
a comment.
10. In its own commit, add the Chess960 perft suite as `tests/fischer.epd`
(960 positions, `;D1`..`;D6`, sha256
`4bc384f273d8ce9312bfde78484dce503c8d1b51b43aacc6352646b3c270b3cd`). An
untracked copy is at `tests/fischer.epd` in the main checkout
(`C:\Users\rektd\repos\Rigby`). Check the hash before committing it. It
enters `main` with this step.
- **Acceptance:**
- `bench` identical to main.
- The reuse sequence from section 6 gives identical `bestmove` and `info`
node counts versus main at Hash 256, where no GC happens.
- All VERIFY runs clean, including forced-GC runs (Hash 1 and 2). Under GC the
output may differ from main, because the bytes per node differ. That is
expected; state it.
- `perftsuite` and 960 perft clean. No new warnings.
- **Report:** NPS (bench nps, and playouts/s at 5 s on the bench positions)
versus main, labelled as a local measurement.
- **SPRT:** **Non-Regression `[-5.00, 0.00]`, STC 8.0+0.08, Threads=1,
Hash=64**, book `UHO_Lichess_4852_v1.epd`, adjudication as in the earlier
Rigby tests. It is a hot-path refactor (two arenas, lazy
creation, an extra indirection), and GC timing changes with the bytes per node,
so play can differ even though bench does not. Non-regression is the right
question for a refactor. If NPS drops by more than 3 %, also run LTC 40.0+0.40
Hash=256 Non-Regression, because GC matters more at LTC.
### Step 3: MCGS core (one self-consistent commit series)
- **Branch:** `mcgs-step3-core`, from step 2.
- **Files:** `src/mcts.h`, `src/mcts.cpp`, `src/movegen.cpp` only if a cheap
`checkmated` helper is needed.
- **Brief:** Implement 3.1–3.5 and the table rebuild in GC (3.6.5):
- The key table with the 80-bit check.
- `create_node` (today's `evaluate_leaf` without path checks), with the root
created and evaluated through it.
- Descent with path draws before the lookup, lazy linking to existing nodes,
and `MAX_PLAYOUT_DEPTH`.
- Backprop:
- for each path node from the leaf's parent up: `edge.visits++` (`edge.draws++`
for a path draw), `node.visits++`, recompute `q` by the 3.1 formula (sum in
`double`);
- the leaf: a new node has `N = base = 1`; a terminal node gets `N++`;
- ValueHash store per path node;
- the butterfly update as today.
- Remove the repetition and 50-move checks from node creation, and the
`TERMINAL_DRAW` test in the ValueHash store.
- Root decisions, PV, info and dashboard on edges (3.4).
- Root edge validation at search start.
- VERIFY: the full 3.8 list, including check (c) and the table checks.
- Arena and table sizing per 3.2.
- No stop rule, no edge Q cache: those are variants.
- **Acceptance:**
- All gates in section 6.
- The bench changes. Explain it in the commit message: the tree becomes a graph
(transpositions share nodes, so playout depths and the visited positions
change); the root gets an evaluation and `N = 1 + Σ`; and repetitions are now
judged per playout instead of once per node.
- VERIFY self-play: at least 20 games at a fixed-nodes TC with no abort.
- Report labelled numbers: NPS versus step 2, and the measured transposition
rate (share of node lookups that hit).
- **SPRT:**
- **STC 8.0+0.08, `[0.00, 5.00]`, Threads=1, Hash=64**, and **LTC 40.0+0.40,
`[0.00, 5.00]`, Threads=1, Hash=256**, both with `UHO_Lichess_4852_v1.epd`.
Run both, because the expected gain grows with search size (Czech et al.).
LTC gets more Hash because 5× the nodes at 64 MB would GC constantly. 256 MB
is roughly the node growth (5×, rounded to a power of two). Eleanor's
OpenBench presets scale Hash by 8× from STC to LTC, which would be 512 MB;
either is defensible, but keep the same value across all MCGS LTC tests.
Both sides always get the same Hash. Rigby has had no LTC test before (the
server's index shows only 8.0+0.08), so the LTC preset has to be created.
- Suggested merge rule (the owner decides): merge if LTC passes and STC
passes, or STC is inconclusive but a follow-up STC Non-Regression
`[-5.00, 0.00]` passes.
- If both fail or stall, do not tune. Investigate with the stats build:
transposition hit rate, NPS loss, depth distribution, draw counts.
### Step 4: DAG-aware reuse polish
- **Branch:** `mcgs-step4-reuse`, from step 3.
- **Files:** `src/mcts.cpp`.
- **Brief:**
- Root-edge reconciliation (3.6.7) after every reroot.
- Reroot by table lookup, with the move walk kept as a cross-check in VERIFY
builds.
- Confirm that GC's kept size stays ≤ target on DAGs (log it in VERIFY builds).
- Re-measure the arena split at the end of 5 s searches with transpositions
and adjust it if one arena fills first.
- Add check (b) for a rerooted graph.
- **Acceptance:** all gates. Bench unchanged versus step 3, because bench has no
reuse; state this. A scripted game sequence shows the reconciled root edges
(log the count in `info string`).
- **SPRT:** STC `[0.00, 5.00]` Hash=64. If the arena re-split changes memory use
noticeably, also LTC `[0.00, 5.00]` Hash=256.
### Step 5: variants (each separate)
Each variant gets its own branch from the current MCGS head, a single concern,
all gates, and its own SPRT. Never bundle them.
| branch | change | SPRT |
| --- | --- | --- |
| `mcgs-v-stop` | 5a stop rule, always-stop | STC + LTC `[0.00, 5.00]` |
| `mcgs-v-stop-leaky` | 5a leaky, p = 0.5 (only after `mcgs-v-stop` has a result) | STC + LTC `[0.00, 5.00]` |
| `mcgs-v-edgeq` | 5b edge-Q cache + incremental sum | STC `[0.00, 5.00]` (it is mostly an NPS trade) |
| `mcgs-v-novaluehash` | 5c remove ValueHash, memory to the graph | Non-Regression STC `[-5.00, 0.00]` (a simplification) |
| `mcgs-v-window-T` | 5d window-hash key for halfmove ≥ T, T from the step-1 histogram | STC + LTC `[0.00, 5.00]` |
- Bench changes for every variant except possibly 5c, which changes it only where
ValueHash hits mattered. That is almost certainly a change too. Explain each.
- **If a variant is inconclusive or negative:** measure before tuning. For
example: the stop rule's share of stopped playouts and the change in depth;
5b's NPS gain and how stale the stored Q is (|q_seen − c.q| histogram);
5d's share of node lookups split by the window.
## 6. Test reference (correctness gates)
Run them on Windows with the repo Makefile (clang++, MinGW target), from the
repo root.
```bash
make -j EXE=rigby-dev
```
```bash
make -j EXE=rigby-verify OBJ_DIR=obj-verify CXX="clang++ -DRIGBY_VERIFY_TREE"
```
This works with today's Makefile: command-line variables override `OBJ_DIR`,
and `CXX` still contains "clang", so the MinGW target is kept. The separate
`OBJ_DIR` keeps the VERIFY objects from mixing with the normal build. Delete
`obj-verify/` afterwards, since `.gitignore` does not cover it. A `STATS=1` build
(step 1) works the same way with `OBJ_DIR=obj-stats`. Checked in this session:
on main, `setoption name Hash value 1`, `go nodes 300000` from startpos runs
dozens of collections and every one passes `verify_tree`.
UCI searches must be driven so that the next `position` waits for `bestmove`,
because `position` stops a running search. Piping all commands at once
silently cuts the searches short. Use a small driver that waits for
`bestmove` (Python stdlib is enough; keep it outside the repo or under `tools/`).
- **Build:** zero new warnings (`-Wall -Wextra`).
- **Perft:** `perftsuite` all pass. `perftfile tests/fischer.epd 5` all pass
(960 positions, about 52 s on this machine; main at c8d1ca6 passes).
- **Bench:** `bench`. Identical for steps 1, 2 and 4 (stated per step). Changed
and explained for 3 and 5.
- **VERIFY searches**, with a VERIFY build over UCI, `go nodes 200000` unless
noted:
- `position startpos` and `position startpos moves e2e4 e7e5 g1f3 b8c6 f1c4 g8f6`
(transpositions).
- `position startpos moves g1f3 g8f6 f3g1 f6g8 g1f3 g8f6` (history repetition
at the root's children).
- Bench positions 11, 12 and 15 (`8/8/3k4/...`, `8/5pk1/...`, `8/8/8/4k3/8/8/2KR4/8 w - -`),
which are endgames with long reversible play.
- `8/8/8/4k3/8/8/2KR4/8 w - - 95 100`: 50-move draws at depth 5+ must appear
as edge draws, never as node states.
- `6k1/5ppp/8/8/8/8/5PPP/3R2K1 w - - 0 1` (mate in 1, Rd8#).
- A Chess960 start, e.g. `bqnb1rkr/pp3ppp/3ppn2/2p5/5P2/P2P4/NPP1P1PP/BQ1BNRKR w HFhf - 2 9`
with `UCI_Chess960 true`.
- **Tree reuse:** one session with `position startpos`, `go nodes 50000`, then
`position startpos moves <bestmove> <any reply>`, `go nodes 50000`, repeated
for 10 moves.
- **Forced GC:** `setoption name Hash value 1`, `go nodes 300000` on startpos
and on the 960 position (several `tree collected` lines expected).
- **`verify` command** (VERIFY builds, from step 2 on): checks (a)–(d) of 3.8.
- **Smoke:** `go nodes 1`, `go nodes 2`, and `go depth 1` on the positions above.
Then self-play with `C:\Users\rektd\repos\OpenBench\Client\cutechess-ob.exe`:
100 games of dev vs base at 2.0+0.02, Hash 16, which forces GC, and 20 games of
the VERIFY build vs itself at `nodes=20000`. Look for illegal moves,
disconnects, timeouts and aborts. Results are not strength evidence.
## 7. Questions for the owner
Answered on 2026-11-16:
1. **Chess960 perft EPD:** the owner did not know where it was. It was found in
the Chess960 session's scratchpad and verified (section 1). Step 2 commits it.
2. **Book and LTC:** use the settings of previous tests. Tests 5307–5309 use
`UHO_Lichess_4852_v1.epd`, Threads=1, Hash=64, 8.0+0.08, win adjudication
`movecount=3 score=400`, draw adjudication
`movenumber=40 movecount=8 score=10`. There was no earlier Rigby LTC, so the
plan uses 40.0+0.40 with Hash=256 (section 5, step 3).
3. **Step 1 merge:** the stats code stays on its branch and is never merged.
4. **Plan approved, including the ordering change.** Compaction moves into step 2
and step 4 becomes small.
5. **Merge policy:** step by step into `main`. Every step has its own branch and
is merged to `main` only after its SPRT passes (step 1 excepted, see there).
There is no long-lived MCGS integration branch.
Until the plan itself is in `main`, step branches start from `mcgs-plan`, so they
carry these docs. The first step merged to `main` (step 2) brings the docs along.
+481
View File
@@ -0,0 +1,481 @@
// incbin.h by Dale Weiler, https://github.com/graphitemaster/incbin (Unlicense / public domain).
// Copied unchanged from Eleanor's external/incbin.h.
/**
* @file incbin.h
* @author Dale Weiler
* @brief Utility for including binary files
*
* Facilities for including binary files into the current translation unit and
* making use from them externally in other translation units.
*/
#ifndef INCBIN_HDR
#define INCBIN_HDR
#include <limits.h>
#if defined(__AVX512BW__) || \
defined(__AVX512CD__) || \
defined(__AVX512DQ__) || \
defined(__AVX512ER__) || \
defined(__AVX512PF__) || \
defined(__AVX512VL__) || \
defined(__AVX512F__)
# define INCBIN_ALIGNMENT_INDEX 6
#elif defined(__AVX__) || \
defined(__AVX2__)
# define INCBIN_ALIGNMENT_INDEX 5
#elif defined(__SSE__) || \
defined(__SSE2__) || \
defined(__SSE3__) || \
defined(__SSSE3__) || \
defined(__SSE4_1__) || \
defined(__SSE4_2__) || \
defined(__neon__) || \
defined(__ARM_NEON) || \
defined(__ALTIVEC__)
# define INCBIN_ALIGNMENT_INDEX 4
#elif ULONG_MAX != 0xffffffffu
# define INCBIN_ALIGNMENT_INDEX 3
# else
# define INCBIN_ALIGNMENT_INDEX 2
#endif
/* Lookup table of (1 << n) where `n' is `INCBIN_ALIGNMENT_INDEX' */
#define INCBIN_ALIGN_SHIFT_0 1
#define INCBIN_ALIGN_SHIFT_1 2
#define INCBIN_ALIGN_SHIFT_2 4
#define INCBIN_ALIGN_SHIFT_3 8
#define INCBIN_ALIGN_SHIFT_4 16
#define INCBIN_ALIGN_SHIFT_5 32
#define INCBIN_ALIGN_SHIFT_6 64
/* Actual alignment value */
#define INCBIN_ALIGNMENT \
INCBIN_CONCATENATE( \
INCBIN_CONCATENATE(INCBIN_ALIGN_SHIFT, _), \
INCBIN_ALIGNMENT_INDEX)
/* Stringize */
#define INCBIN_STR(X) \
#X
#define INCBIN_STRINGIZE(X) \
INCBIN_STR(X)
/* Concatenate */
#define INCBIN_CAT(X, Y) \
X ## Y
#define INCBIN_CONCATENATE(X, Y) \
INCBIN_CAT(X, Y)
/* Deferred macro expansion */
#define INCBIN_EVAL(X) \
X
#define INCBIN_INVOKE(N, ...) \
INCBIN_EVAL(N(__VA_ARGS__))
/* Variable argument count for overloading by arity */
#define INCBIN_VA_ARG_COUNTER(_1, _2, _3, N, ...) N
#define INCBIN_VA_ARGC(...) INCBIN_VA_ARG_COUNTER(__VA_ARGS__, 3, 2, 1, 0)
/* Green Hills uses a different directive for including binary data */
#if defined(__ghs__)
# if (__ghs_asm == 2)
# define INCBIN_MACRO ".file"
/* Or consider the ".myrawdata" entry in the ld file */
# else
# define INCBIN_MACRO "\tINCBIN"
# endif
#else
# define INCBIN_MACRO ".incbin"
#endif
#ifndef _MSC_VER
# define INCBIN_ALIGN \
__attribute__((aligned(INCBIN_ALIGNMENT)))
#else
# define INCBIN_ALIGN __declspec(align(INCBIN_ALIGNMENT))
#endif
#if defined(__arm__) || /* GNU C and RealView */ \
defined(__arm) || /* Diab */ \
defined(_ARM) /* ImageCraft */
# define INCBIN_ARM
#endif
#ifdef __GNUC__
/* Utilize .balign where supported */
# define INCBIN_ALIGN_HOST ".balign " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n"
# define INCBIN_ALIGN_BYTE ".balign 1\n"
#elif defined(INCBIN_ARM)
/*
* On arm assemblers, the alignment value is calculated as (1 << n) where `n' is
* the shift count. This is the value passed to `.align'
*/
# define INCBIN_ALIGN_HOST ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT_INDEX) "\n"
# define INCBIN_ALIGN_BYTE ".align 0\n"
#else
/* We assume other inline assembler's treat `.align' as `.balign' */
# define INCBIN_ALIGN_HOST ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n"
# define INCBIN_ALIGN_BYTE ".align 1\n"
#endif
/* INCBIN_CONST is used by incbin.c generated files */
#if defined(__cplusplus)
# define INCBIN_EXTERNAL extern "C"
# define INCBIN_CONST extern const
#else
# define INCBIN_EXTERNAL extern
# define INCBIN_CONST const
#endif
/**
* @brief Optionally override the linker section into which size and data is
* emitted.
*
* @warning If you use this facility, you might have to deal with
* platform-specific linker output section naming on your own.
*/
#if !defined(INCBIN_OUTPUT_SECTION)
# if defined(__APPLE__)
# define INCBIN_OUTPUT_SECTION ".const_data"
# else
# define INCBIN_OUTPUT_SECTION ".rodata"
# endif
#endif
/**
* @brief Optionally override the linker section into which data is emitted.
*
* @warning If you use this facility, you might have to deal with
* platform-specific linker output section naming on your own.
*/
#if !defined(INCBIN_OUTPUT_DATA_SECTION)
# define INCBIN_OUTPUT_DATA_SECTION INCBIN_OUTPUT_SECTION
#endif
/**
* @brief Optionally override the linker section into which size is emitted.
*
* @warning If you use this facility, you might have to deal with
* platform-specific linker output section naming on your own.
*
* @note This is useful for Harvard architectures where program memory cannot
* be directly read from the program without special instructions. With this you
* can chose to put the size variable in RAM rather than ROM.
*/
#if !defined(INCBIN_OUTPUT_SIZE_SECTION)
# define INCBIN_OUTPUT_SIZE_SECTION INCBIN_OUTPUT_SECTION
#endif
#if defined(__APPLE__)
# include "TargetConditionals.h"
# if defined(TARGET_OS_IPHONE) && !defined(INCBIN_SILENCE_BITCODE_WARNING)
# warning "incbin is incompatible with bitcode. Using the library will break upload to App Store if you have bitcode enabled. Add `#define INCBIN_SILENCE_BITCODE_WARNING` before including this header to silence this warning."
# endif
/* The directives are different for Apple branded compilers */
# define INCBIN_SECTION INCBIN_OUTPUT_SECTION "\n"
# define INCBIN_GLOBAL(NAME) ".globl " INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME "\n"
# define INCBIN_INT ".long "
# define INCBIN_MANGLE "_"
# define INCBIN_BYTE ".byte "
# define INCBIN_TYPE(...)
#else
# define INCBIN_SECTION ".section " INCBIN_OUTPUT_SECTION "\n"
# define INCBIN_GLOBAL(NAME) ".global " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME "\n"
# if defined(__ghs__)
# define INCBIN_INT ".word "
# else
# define INCBIN_INT ".int "
# endif
# if defined(__USER_LABEL_PREFIX__)
# define INCBIN_MANGLE INCBIN_STRINGIZE(__USER_LABEL_PREFIX__)
# else
# define INCBIN_MANGLE ""
# endif
# if defined(INCBIN_ARM)
/* On arm assemblers, `@' is used as a line comment token */
# define INCBIN_TYPE(NAME) ".type " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME ", %object\n"
# elif defined(__MINGW32__) || defined(__MINGW64__)
/* Mingw doesn't support this directive either */
# define INCBIN_TYPE(NAME)
# elif defined(_WIN32)
// CIEKCE: this just doesn't work on windows at all
# define INCBIN_TYPE(NAME)
# else
/* It's safe to use `@' on other architectures */
# define INCBIN_TYPE(NAME) ".type " INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME ", @object\n"
# endif
# define INCBIN_BYTE ".byte "
#endif
/* List of style types used for symbol names */
#define INCBIN_STYLE_CAMEL 0
#define INCBIN_STYLE_SNAKE 1
/**
* @brief Specify the prefix to use for symbol names.
*
* @note By default this is "g".
*
* @code
* #define INCBIN_PREFIX incbin
* #include "incbin.h"
* INCBIN(Foo, "foo.txt");
*
* // Now you have the following symbols instead:
* // const unsigned char incbinFoo<data>[];
* // const unsigned char *const incbinFoo<end>;
* // const unsigned int incbinFoo<size>;
* @endcode
*/
#if !defined(INCBIN_PREFIX)
# define INCBIN_PREFIX g
#endif
/**
* @brief Specify the style used for symbol names.
*
* Possible options are
* - INCBIN_STYLE_CAMEL "CamelCase"
* - INCBIN_STYLE_SNAKE "snake_case"
*
* @note By default this is INCBIN_STYLE_CAMEL
*
* @code
* #define INCBIN_STYLE INCBIN_STYLE_SNAKE
* #include "incbin.h"
* INCBIN(foo, "foo.txt");
*
* // Now you have the following symbols:
* // const unsigned char <prefix>foo_data[];
* // const unsigned char *const <prefix>foo_end;
* // const unsigned int <prefix>foo_size;
* @endcode
*/
#if !defined(INCBIN_STYLE)
# define INCBIN_STYLE INCBIN_STYLE_CAMEL
#endif
/* Style lookup tables */
#define INCBIN_STYLE_0_DATA Data
#define INCBIN_STYLE_0_END End
#define INCBIN_STYLE_0_SIZE Size
#define INCBIN_STYLE_1_DATA _data
#define INCBIN_STYLE_1_END _end
#define INCBIN_STYLE_1_SIZE _size
/* Style lookup: returning identifier */
#define INCBIN_STYLE_IDENT(TYPE) \
INCBIN_CONCATENATE( \
INCBIN_STYLE_, \
INCBIN_CONCATENATE( \
INCBIN_EVAL(INCBIN_STYLE), \
INCBIN_CONCATENATE(_, TYPE)))
/* Style lookup: returning string literal */
#define INCBIN_STYLE_STRING(TYPE) \
INCBIN_STRINGIZE( \
INCBIN_STYLE_IDENT(TYPE)) \
/* Generate the global labels by indirectly invoking the macro with our style
* type and concatenating the name against them. */
#define INCBIN_GLOBAL_LABELS(NAME, TYPE) \
INCBIN_INVOKE( \
INCBIN_GLOBAL, \
INCBIN_CONCATENATE( \
NAME, \
INCBIN_INVOKE( \
INCBIN_STYLE_IDENT, \
TYPE))) \
INCBIN_INVOKE( \
INCBIN_TYPE, \
INCBIN_CONCATENATE( \
NAME, \
INCBIN_INVOKE( \
INCBIN_STYLE_IDENT, \
TYPE)))
/**
* @brief Externally reference binary data included in another translation unit.
*
* Produces three external symbols that reference the binary data included in
* another translation unit.
*
* The symbol names are a concatenation of `INCBIN_PREFIX' before *NAME*; with
* "Data", as well as "End" and "Size" after. An example is provided below.
*
* @param TYPE Optional array type. Omitting this picks a default of `unsigned char`.
* @param NAME The name given for the binary data
*
* @code
* INCBIN_EXTERN(Foo);
*
* // Now you have the following symbols:
* // extern const unsigned char <prefix>Foo<data>[];
* // extern const unsigned char *const <prefix>Foo<end>;
* // extern const unsigned int <prefix>Foo<size>;
* @endcode
*
* You may specify a custom optional data type as well as the first argument.
* @code
* INCBIN_EXTERN(custom_type, Foo);
*
* // Now you have the following symbols:
* // extern const custom_type <prefix>Foo<data>[];
* // extern const custom_type *const <prefix>Foo<end>;
* // extern const unsigned int <prefix>Foo<size>;
* @endcode
*/
#define INCBIN_EXTERN(...) \
INCBIN_CONCATENATE(INCBIN_EXTERN_, INCBIN_VA_ARGC(__VA_ARGS__))(__VA_ARGS__)
#define INCBIN_EXTERN_1(NAME, ...) \
INCBIN_EXTERN_2(unsigned char, NAME)
#define INCBIN_EXTERN_2(TYPE, NAME) \
INCBIN_EXTERNAL const INCBIN_ALIGN TYPE \
INCBIN_CONCATENATE( \
INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \
INCBIN_STYLE_IDENT(DATA))[]; \
INCBIN_EXTERNAL const INCBIN_ALIGN TYPE *const \
INCBIN_CONCATENATE( \
INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \
INCBIN_STYLE_IDENT(END)); \
INCBIN_EXTERNAL const unsigned int \
INCBIN_CONCATENATE( \
INCBIN_CONCATENATE(INCBIN_PREFIX, NAME), \
INCBIN_STYLE_IDENT(SIZE))
/**
* @brief Externally reference textual data included in another translation unit.
*
* Produces three external symbols that reference the textual data included in
* another translation unit.
*
* The symbol names are a concatenation of `INCBIN_PREFIX' before *NAME*; with
* "Data", as well as "End" and "Size" after. An example is provided below.
*
* @param NAME The name given for the textual data
*
* @code
* INCBIN_EXTERN(Foo);
*
* // Now you have the following symbols:
* // extern const char <prefix>Foo<data>[];
* // extern const char *const <prefix>Foo<end>;
* // extern const unsigned int <prefix>Foo<size>;
* @endcode
*/
#define INCTXT_EXTERN(NAME) \
INCBIN_EXTERN_2(char, NAME)
/**
* @brief Include a binary file into the current translation unit.
*
* Includes a binary file into the current translation unit, producing three symbols
* for objects that encode the data and size respectively.
*
* The symbol names are a concatenation of `INCBIN_PREFIX' before *NAME*; with
* "Data", as well as "End" and "Size" after. An example is provided below.
*
* @param TYPE Optional array type. Omitting this picks a default of `unsigned char`.
* @param NAME The name to associate with this binary data (as an identifier.)
* @param FILENAME The file to include (as a string literal.)
*
* @code
* INCBIN(Icon, "icon.png");
*
* // Now you have the following symbols:
* // const unsigned char <prefix>Icon<data>[];
* // const unsigned char *const <prefix>Icon<end>;
* // const unsigned int <prefix>Icon<size>;
* @endcode
*
* You may specify a custom optional data type as well as the first argument.
* These macros are specialized by arity.
* @code
* INCBIN(custom_type, Icon, "icon.png");
*
* // Now you have the following symbols:
* // const custom_type <prefix>Icon<data>[];
* // const custom_type *const <prefix>Icon<end>;
* // const unsigned int <prefix>Icon<size>;
* @endcode
*
* @warning This must be used in global scope
* @warning The identifiers may be different if INCBIN_STYLE is not default
*
* To externally reference the data included by this in another translation unit
* please @see INCBIN_EXTERN.
*/
#ifdef _MSC_VER
# define INCBIN(NAME, FILENAME) \
INCBIN_EXTERN(NAME)
#else
# define INCBIN(...) \
INCBIN_CONCATENATE(INCBIN_, INCBIN_VA_ARGC(__VA_ARGS__))(__VA_ARGS__)
# if defined(__GNUC__)
# define INCBIN_1(...) _Pragma("GCC error \"Single argument INCBIN not allowed\"")
# elif defined(__clang__)
# define INCBIN_1(...) _Pragma("clang error \"Single argument INCBIN not allowed\"")
# else
# define INCBIN_1(...) /* Cannot do anything here */
# endif
# define INCBIN_2(NAME, FILENAME) \
INCBIN_3(unsigned char, NAME, FILENAME)
# define INCBIN_3(TYPE, NAME, FILENAME) INCBIN_COMMON(TYPE, NAME, FILENAME, /* No terminator for binary data */)
# define INCBIN_COMMON(TYPE, NAME, FILENAME, TERMINATOR) \
__asm__(INCBIN_SECTION \
INCBIN_GLOBAL_LABELS(NAME, DATA) \
INCBIN_ALIGN_HOST \
INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(DATA) ":\n" \
INCBIN_MACRO " \"" FILENAME "\"\n" \
TERMINATOR \
INCBIN_GLOBAL_LABELS(NAME, END) \
INCBIN_ALIGN_BYTE \
INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(END) ":\n" \
INCBIN_BYTE "1\n" \
INCBIN_GLOBAL_LABELS(NAME, SIZE) \
INCBIN_ALIGN_HOST \
INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(SIZE) ":\n" \
INCBIN_INT INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(END) " - " \
INCBIN_MANGLE INCBIN_STRINGIZE(INCBIN_PREFIX) #NAME INCBIN_STYLE_STRING(DATA) "\n" \
INCBIN_ALIGN_HOST \
".text\n" \
); \
INCBIN_EXTERN(TYPE, NAME)
#endif
/**
* @brief Include a textual file into the current translation unit.
*
* This behaves the same as INCBIN except it produces char compatible arrays
* and implicitly adds a null-terminator byte, thus the size of data included
* by this is one byte larger than that of INCBIN.
*
* Includes a textual file into the current translation unit, producing three
* symbols for objects that encode the data and size respectively.
*
* The symbol names are a concatenation of `INCBIN_PREFIX' before *NAME*; with
* "Data", as well as "End" and "Size" after. An example is provided below.
*
* @param NAME The name to associate with this binary data (as an identifier.)
* @param FILENAME The file to include (as a string literal.)
*
* @code
* INCTXT(Readme, "readme.txt");
*
* // Now you have the following symbols:
* // const char <prefix>Readme<data>[];
* // const char *const <prefix>Readme<end>;
* // const unsigned int <prefix>Readme<size>;
* @endcode
*
* @warning This must be used in global scope
* @warning The identifiers may be different if INCBIN_STYLE is not default
*
* To externally reference the data included by this in another translation unit
* please @see INCBIN_EXTERN.
*/
#if defined(_MSC_VER)
# define INCTXT(NAME, FILENAME) \
INCBIN_EXTERN(NAME)
#else
# define INCTXT(NAME, FILENAME) \
INCBIN_COMMON(char, NAME, FILENAME, INCBIN_BYTE "0\n")
#endif
#endif
Binary file not shown.
Binary file not shown.
Binary file not shown.
+162 -62
View File
@@ -1,29 +1,29 @@
#include "eval.h"
#include <algorithm>
#include <iterator>
#include <cmath>
#include <cstdlib>
#include "nnue.h"
#include "policy.h"
namespace rigby::eval {
namespace {
constexpr int MATE = 30000;
constexpr int QS_MAX_PLY = 32;
constexpr float Q_SCALE = 300.0f;
// The network is trained so that sigmoid(cp / 400) is the expected score, so
// Q = 2 * sigmoid(cp / 400) - 1 = tanh(cp / 800).
constexpr float Q_SCALE = 2.0f * float(nnue::SCALE);
constexpr int MG_VALUE[6] = {90, 320, 335, 480, 980, 0};
constexpr int EG_VALUE[6] = {110, 290, 305, 520, 940, 0};
constexpr int SEE_VALUE[6] = {100, 300, 310, 500, 900, 0};
constexpr int PHASE_WEIGHT[6] = {0, 1, 1, 2, 4, 0};
// Material folded into piece-square tables, indexed [piece][square].
int mg_table[12][64];
int eg_table[12][64];
// Positional part only (no material), white's view, used by the policy.
// Positional piece-square bonuses, white's view, used by the policy.
int mg_pst[6][64];
void pst_for(int type, int sq, int& mg, int& eg) {
int pst_mg(int type, int sq) {
const int f = file_of(sq);
const int r = rank_of(sq);
const int center = std::abs(2 * f - 7) + std::abs(2 * r - 7); // 2..14
@@ -31,29 +31,17 @@ void pst_for(int type, int sq, int& mg, int& eg) {
switch (type) {
case PAWN:
mg = (r >= 1 && r <= 6) ? (r - 1) * 6 + (central_file ? (r - 1) * 4 : 0) : 0;
eg = (r >= 1 && r <= 6) ? (r - 1) * 14 : 0;
break;
return (r >= 1 && r <= 6) ? (r - 1) * 6 + (central_file ? (r - 1) * 4 : 0) : 0;
case KNIGHT:
mg = 24 - center * 4;
eg = 18 - center * 3;
break;
return 24 - center * 4;
case BISHOP:
mg = 12 - center * 2;
eg = 10 - center * 2;
break;
return 12 - center * 2;
case ROOK:
mg = (r == 6 ? 20 : 0) + (central_file ? 6 : 0);
eg = r == 6 ? 15 : 0;
break;
return (r == 6 ? 20 : 0) + (central_file ? 6 : 0);
case QUEEN:
mg = 6 - center;
eg = 20 - center * 2;
break;
default: // KING: shelter in the middlegame, centralise in the endgame
mg = -std::min(r, 3) * 25 + ((f <= 2 || f >= 6) ? 15 : -15);
eg = 30 - center * 4;
break;
return 6 - center;
default: // KING: stay sheltered
return -std::min(r, 3) * 25 + ((f <= 2 || f >= 6) ? 15 : -15);
}
}
@@ -61,55 +49,104 @@ int victim_type(const Position& pos, Move m) { return m.is_en_passant() ? PAWN :
} // namespace
bool see_ge(const Position& pos, Move m, int threshold) {
// Castling, en passant and promotions are taken as an even trade.
if (m.is_castle() || m.is_en_passant() || m.is_promotion()) return threshold <= 0;
const int from = m.from();
const int to = m.to();
// `swap` is what the side to move is ahead of the threshold if the exchange
// stops now, seen from the side that just captured.
int swap = (pos.piece_on(to) == NO_PIECE ? 0 : SEE_VALUE[piece_type(pos.piece_on(to))]) - threshold;
if (swap < 0) return false;
swap = SEE_VALUE[piece_type(pos.piece_on(from))] - swap;
if (swap <= 0) return true;
u64 occ = pos.occupancy() ^ bb(from) ^ bb(to);
u64 attackers = pos.attackers_to(to, occ);
const u64 diagonal = pos.pieces[BISHOP] | pos.pieces[QUEEN];
const u64 straight = pos.pieces[ROOK] | pos.pieces[QUEEN];
int stm = pos.stm;
int result = 1;
for (;;) {
stm ^= 1;
attackers &= occ;
const u64 ours = attackers & pos.colors[stm];
if (!ours) break;
result ^= 1;
// Recapture with the least valuable piece; taking it off the board may
// open a line for a slider behind it.
u64 b;
if ((b = ours & pos.pieces[PAWN])) {
if ((swap = SEE_VALUE[PAWN] - swap) < result) break;
occ ^= bb(lsb(b));
attackers |= attacks::bishop(to, occ) & diagonal;
} else if ((b = ours & pos.pieces[KNIGHT])) {
if ((swap = SEE_VALUE[KNIGHT] - swap) < result) break;
occ ^= bb(lsb(b));
} else if ((b = ours & pos.pieces[BISHOP])) {
if ((swap = SEE_VALUE[BISHOP] - swap) < result) break;
occ ^= bb(lsb(b));
attackers |= attacks::bishop(to, occ) & diagonal;
} else if ((b = ours & pos.pieces[ROOK])) {
if ((swap = SEE_VALUE[ROOK] - swap) < result) break;
occ ^= bb(lsb(b));
attackers |= attacks::rook(to, occ) & straight;
} else if ((b = ours & pos.pieces[QUEEN])) {
if ((swap = SEE_VALUE[QUEEN] - swap) < result) break;
occ ^= bb(lsb(b));
attackers |= (attacks::bishop(to, occ) & diagonal) | (attacks::rook(to, occ) & straight);
} else {
// Only the king is left: it may recapture only if nothing defends the square.
return (attackers & ~pos.colors[stm]) ? result ^ 1 : result;
}
}
return result;
}
void init() {
for (int type = PAWN; type <= KING; type++) {
for (int sq = 0; sq < 64; sq++) {
int mg, eg;
pst_for(type, sq, mg, eg);
mg_pst[type][sq] = mg;
mg_table[make_piece(WHITE, type)][sq] = MG_VALUE[type] + mg;
eg_table[make_piece(WHITE, type)][sq] = EG_VALUE[type] + eg;
mg_table[make_piece(BLACK, type)][sq ^ 56] = -(MG_VALUE[type] + mg);
eg_table[make_piece(BLACK, type)][sq ^ 56] = -(EG_VALUE[type] + eg);
mg_pst[type][sq] = pst_mg(type, sq);
}
}
nnue::init();
rigby::policy::init();
}
int static_eval(const Position& pos) {
int mg = 0, eg = 0, phase = 0;
u64 occ = pos.occupancy();
while (occ) {
const int sq = pop_lsb(occ);
const int piece = pos.piece_on(sq);
mg += mg_table[piece][sq];
eg += eg_table[piece][sq];
phase += PHASE_WEIGHT[piece_type(piece)];
}
phase = std::min(phase, 24);
int static_eval(const Position& pos) { return nnue::evaluate(pos); }
int score = (mg * phase + eg * (24 - phase)) / 24;
if (popcount(pos.pieces_of(WHITE, BISHOP)) >= 2) score += 30;
if (popcount(pos.pieces_of(BLACK, BISHOP)) >= 2) score -= 30;
namespace {
return (pos.stm == WHITE ? score : -score) + 10;
}
int quiescence(const Position& pos, int alpha, int beta, int ply) {
// `acc` is the network's accumulator for `pos`; each child gets its own,
// updated from it, instead of being rebuilt from the whole board.
int qsearch(const Position& pos, const nnue::Accumulator& acc, int alpha, int beta, int ply) {
const bool in_check = pos.in_check();
int best = -MATE + ply;
int stand_pat = 0;
if (!in_check) {
stand_pat = static_eval(pos);
stand_pat = nnue::evaluate(acc, pos.stm);
if (stand_pat >= beta || ply >= QS_MAX_PLY) return stand_pat;
best = stand_pat;
alpha = std::max(alpha, stand_pat);
}
// Out of check only captures and queen promotions are searched, so only
// those are generated; a position without any of them is still checked
// for stalemate.
MoveList list;
generate_legal(pos, list);
if (list.empty()) return in_check ? -MATE + ply : 0;
if (in_check && ply >= QS_MAX_PLY) return static_eval(pos);
if (in_check) {
generate_legal(pos, list);
if (list.empty()) return -MATE + ply;
if (ply >= QS_MAX_PLY) return nnue::evaluate(acc, pos.stm);
} else {
generate_noisy(pos, list);
if (list.empty()) return has_legal_move(pos) ? best : 0;
}
Move moves[256];
int scores[256];
@@ -122,6 +159,8 @@ int quiescence(const Position& pos, int alpha, int beta, int ply) {
const int victim = victim_type(pos, m);
// Delta pruning: even winning the piece for free cannot reach alpha.
if (!in_check && !m.is_promotion() && stand_pat + SEE_VALUE[victim] + 200 <= alpha) continue;
// Captures that lose material in the exchange on the square.
if (!in_check && !see_ge(pos, m, 0)) continue;
score = SEE_VALUE[victim] * 16 - piece_type(pos.piece_on(m.from()));
}
if (m.is_promotion()) score += SEE_VALUE[m.promo_type()] * 16;
@@ -136,9 +175,11 @@ int quiescence(const Position& pos, int alpha, int beta, int ply) {
std::swap(moves[i], moves[best_idx]);
std::swap(scores[i], scores[best_idx]);
nnue::Accumulator child_acc;
nnue::update(acc, pos, moves[i], child_acc);
Position child = pos;
child.make_move(moves[i]);
const int score = -quiescence(child, -beta, -alpha, ply + 1);
const int score = -qsearch(child, child_acc, -beta, -alpha, ply + 1);
if (score > best) {
best = score;
if (score > alpha) {
@@ -150,9 +191,35 @@ int quiescence(const Position& pos, int alpha, int beta, int ply) {
return best;
}
} // namespace
int quiescence(const Position& pos, int alpha, int beta, int ply) {
nnue::Accumulator acc;
nnue::refresh(pos, acc);
return qsearch(pos, acc, alpha, beta, ply);
}
float value(const Position& pos) { return cp_to_q(quiescence(pos, -MATE, MATE, 0)); }
void policy(const Position& pos, const MoveList& moves, float temperature, float* out) {
void policy(const Position& pos, const MoveList& moves, float temperature, const float* bias, float* out) {
if (rigby::policy::loaded()) {
// The network's logits, shifted by the search's bias.
rigby::policy::logits(pos, moves, out);
const float inv_temp = 1.0f / std::max(temperature, 0.01f);
float max_logit = -1e30f;
for (int i = 0; i < moves.size(); i++) {
out[i] = (out[i] + (bias ? bias[i] : 0.0f)) * inv_temp;
max_logit = std::max(max_logit, out[i]);
}
float total = 0.0f;
for (int i = 0; i < moves.size(); i++) {
out[i] = std::exp(out[i] - max_logit);
total += out[i];
}
for (int i = 0; i < moves.size(); i++) out[i] /= total;
return;
}
const int us = pos.stm;
const int them = us ^ 1;
const u64 occ = pos.occupancy();
@@ -171,6 +238,31 @@ void policy(const Position& pos, const MoveList& moves, float temperature, float
check_squares[QUEEN] = check_squares[BISHOP] | check_squares[ROOK];
check_squares[KING] = 0;
// Whether the opponent wins the piece on a square in an exchange started
// with their least valuable attacker. Worked out once per square.
Position their_turn = pos;
their_turn.stm = them;
int hanging_cache[64];
std::fill(std::begin(hanging_cache), std::end(hanging_cache), -1);
const auto hanging = [&](int sq) {
if (hanging_cache[sq] < 0) {
const u64 attackers = pos.attackers_to(sq, occ) & pos.colors[them];
int lva = -1;
for (int t = PAWN; t <= KING && lva < 0; t++)
if (attackers & pos.pieces[t]) lva = lsb(attackers & pos.pieces[t]);
bool wins = false;
if (lva >= 0) {
// A king can only take a piece nothing defends.
if (piece_type(pos.piece_on(lva)) == KING)
wins = !(pos.attackers_to(sq, occ) & pos.colors[us]);
else
wins = see_ge(their_turn, Move(lva, sq, Move::CAPTURE), 1);
}
hanging_cache[sq] = wins;
}
return hanging_cache[sq] == 1;
};
const float inv_temp = 1.0f / std::max(temperature, 0.01f);
float max_logit = -1e30f;
@@ -181,17 +273,25 @@ void policy(const Position& pos, const MoveList& moves, float temperature, float
const int type = piece_type(pos.piece_on(from));
float s = 0.0f;
if (m.is_capture()) s += 1.0f + 0.004f * SEE_VALUE[victim_type(pos, m)] - 0.0015f * SEE_VALUE[type];
// Captures are tried early, unless the exchange on the square loses material.
if (m.is_capture())
s += (see_ge(pos, m, 0) ? 1.0f : -1.0f) + 0.004f * SEE_VALUE[victim_type(pos, m)] -
0.0015f * SEE_VALUE[type];
if (m.is_promotion()) s += m.promo_type() == QUEEN ? 2.5f : -2.5f;
if (m.is_castle()) s += 0.8f;
s += 0.01f * float(mg_pst[type][relative_square(us, to)] - mg_pst[type][relative_square(us, from)]);
if (type != PAWN && type != KING) {
if (pawn_threats & bb(to)) s -= 0.004f * SEE_VALUE[type];
if (pawn_threats & bb(from)) s += 0.003f * SEE_VALUE[type];
if (m.is_capture() && (pawn_threats & bb(to))) s -= 0.004f * SEE_VALUE[type];
// Moving a piece the opponent could win (to a pawn or any other attacker).
if (hanging(from)) s += 0.003f * SEE_VALUE[type];
}
// A quiet move that puts the piece where the exchange loses it (to a
// pawn, or to any attacker it is not defended well enough against).
if (!m.is_capture() && !m.is_promotion() && !see_ge(pos, m, 0)) s -= 0.004f * SEE_VALUE[type];
if (check_squares[m.is_promotion() ? m.promo_type() : type] & bb(to)) s += 0.5f;
if (bias) s += bias[i];
out[i] = s * inv_temp;
max_logit = std::max(max_logit, out[i]);
+11 -5
View File
@@ -4,22 +4,28 @@
namespace rigby::eval {
// Stand-in evaluation until the network arrives. Everything here is replaced by
// the value and policy heads of the net trained on Lc0 data.
// Value: the network trained on Lc0 data, behind a capture-only quiescence
// search. Policy: the policy network when one is loaded (see policy.h),
// otherwise move heuristics.
void init();
// Static evaluation in centipawns, from the side to move's view.
// Static evaluation (the value network) in centipawns, side to move's view.
int static_eval(const Position& pos);
// Static exchange evaluation: true when the exchange `m` starts on its target
// square gains at least `threshold` centipawns for the side to move (pins ignored).
bool see_ge(const Position& pos, Move m, int threshold);
// Capture-only search on top of the static evaluation, side to move's view.
int quiescence(const Position& pos, int alpha, int beta, int ply);
// Expected score in [-1, 1] for the side to move.
float value(const Position& pos);
// Writes softmax-normalised priors for `moves` into `out`.
void policy(const Position& pos, const MoveList& moves, float temperature, float* out);
// Writes softmax-normalised priors for `moves` into `out`. `bias`, when not
// null, is added to each move's logit before the softmax (and the temperature).
void policy(const Position& pos, const MoveList& moves, float temperature, const float* bias, float* out);
// Conversion between centipawns and Q in [-1, 1]. One scale for both directions,
// so reported scores match what the search actually optimises.
+1230
View File
File diff suppressed because it is too large. Load diff
+336
View File
@@ -0,0 +1,336 @@
#pragma once
#include <algorithm>
#include <array>
#include <atomic>
#include <chrono>
#include <cstdlib>
#include <vector>
#include "position.h"
#include "pretty.h"
namespace rigby {
enum NodeState : u8 {
UNEXPANDED = 0,
EXPANDED,
TERMINAL_LOSS, // side to move is checkmated
TERMINAL_DRAW,
};
// The search is a graph (Monte-Carlo graph search, docs/mcgs-plan.md): one node
// per position, shared by every move order that reaches it. Q values follow
// KataGo's "Monte-Carlo Graph Search from First Principles":
// - an edge (n, a) to child c has its own visits N(n,a), how often PUCT at n
// chose a, and draws D(n,a), how many of those playouts ended in a draw of
// their path (repetition or the 50-move rule) right after a. Such draws
// belong to the path, never to a node;
// - the edge's value for the side to move at n is (N - D) / N * c.q, so a
// path draw counts 0;
// - a node has N(n) = base + sum of its edge visits, and its Q is recomputed
// from its children on every playout through it:
// q = (base * u - sum (N - D) * c.q) / N(n). `u` is the node's own
// evaluation (base 1), or the Q it had when collection took its edges
// (base = its visits then).
// A move out of a node. A node's edges sit next to each other in the edge
// arena, so the node only needs the index of the first one. The edge is linked
// to its child node the first time search selects it.
struct Edge {
u32 child = 0; // node index, 0 = not linked yet
u32 visits = 0; // N(n,a): how often search chose this move here
u32 draws = 0; // D(n,a): of those, playouts that ended in a draw of the path after this move
u16 move = 0;
u16 policy = 0; // prior scaled to 0..65535
float prior() const { return float(policy) * (1.0f / 65535.0f); }
};
static_assert(sizeof(Edge) == 16);
// A position, created (and evaluated) when search first reaches it.
struct Node {
u64 key = 0; // Zobrist key of the position
u32 first_edge = 0; // 0 = not expanded
u32 visits = 0; // N(n) = base + the edges' visits
float q = 0.0f; // from the view of the side that moved into the node
float u = 0.0f; // the same view: own evaluation, or the Q kept by collection
u32 base = 0; // weight of u
u8 num_edges = 0;
// Only facts of the position itself: checkmate, stalemate, insufficient material.
u8 state = UNEXPANDED;
u16 check = 0; // second fingerprint of the position (position_check)
};
static_assert(sizeof(Node) == 32);
// A 16-bit fingerprint of the position that does not depend on the Zobrist keys.
u16 position_check(const Position& pos);
// Two arenas, nodes and edges (index 0 of each is null), and a table from
// position to node. A position is found by its 64-bit key plus the 16-bit
// check, about 80 bits.
class Tree {
public:
// Edges per node the arenas are sized for: the edge arena gets 128 of
// every 160 bytes, the node arena 32. Measured in step 1 of the MCGS plan
// (docs/mcgs-log.md, edges per visited node): 13 on average in 5 s
// searches without collections, 19-21 in middlegames, 3.6-5.5 in simple
// endgames, and 3-9 right after collections (pruned nodes keep their node
// but lose their edges). Over the 16 bench positions at 5 s and Hash 64,
// 8 gave 184 collections (main: 200), as few as 13 did, without 13's
// 2-3x more collections in the endgames (which fill the node arena first).
static constexpr size_t EDGES_PER_NODE = 8;
// Splits `bytes` between the node arena, the edge arena and the table.
void resize_bytes(size_t bytes);
// Empties the graph. The caller then creates the root and sets it.
void clear();
// A fresh node, or 0 when the node arena is full.
u32 alloc_node();
// The index of `count` fresh edges, or 0 when the edge arena is full.
u32 alloc_edges(u32 count);
void set_root(u32 idx) { root_ = idx; }
// The node of the position with this key and check, 0 when there is none.
u32 find(u64 key, u16 check) const;
// Enters a node, which must not be in the table yet, by its key.
void insert(u32 idx);
// Makes `new_root` the root. Nothing is moved or dropped: what the new
// root no longer reaches goes at the next collection. Returns the number
// of nodes in the graph.
size_t reroot(u32 new_root);
// Frees memory when an arena is full: the least visited parts of the graph
// are cut back to leaves until at most `keep_fraction` of each arena is in
// use. Returns the number of nodes kept.
size_t collect_garbage(double keep_fraction);
// The same with explicit targets (in slots, null slots included).
size_t collect_garbage(size_t node_target, size_t edge_target);
Node& node(u32 idx) { return nodes_[idx]; }
const Node& node(u32 idx) const { return nodes_[idx]; }
Edge& edge(u32 idx) { return edges_[idx]; }
const Edge& edge(u32 idx) const { return edges_[idx]; }
u32 root() const { return root_; }
size_t nodes_used() const { return nodes_used_; }
size_t edges_used() const { return edges_used_; }
size_t node_capacity() const { return nodes_.size(); }
size_t edge_capacity() const { return edges_.size(); }
size_t table_entries() const { return table_entries_; }
size_t table_slots() const { return table_.size(); }
// The node a table slot points to (0 = empty) and the key half it holds.
u32 table_node(size_t slot) const { return table_[slot].node; }
u32 table_key_hi(size_t slot) const { return table_[slot].key_hi; }
// How full the fuller arena is, per mille.
int fill_permille() const {
return int(std::max(nodes_used_ * 1000 / nodes_.size(), edges_used_ * 1000 / edges_.size()));
}
private:
// Open addressing with linear probing. The table has at least twice as
// many slots as the node arena has nodes, so it is never more than half
// full and needs no collection of its own. Nothing is deleted from it:
// after a collection or a reroot it is rebuilt from the surviving nodes.
struct Slot {
u32 key_hi = 0; // upper half of the key
u32 node = 0; // 0 = empty
};
static_assert(sizeof(Slot) == 8);
std::vector<Node> nodes_;
std::vector<Edge> edges_;
std::vector<Slot> table_;
size_t table_mask_ = 0;
size_t table_entries_ = 0;
size_t nodes_used_ = 0;
size_t edges_used_ = 0;
u32 root_ = 0;
// Keeps what is reachable from `new_root`, dropping the edges of every
// node with fewer than `min_visits` visits, packs both arenas to the
// front in place and rebuilds the table.
size_t compact(u32 new_root, u32 min_visits);
u32 prune_threshold(size_t node_target, size_t edge_target) const;
void rebuild_table();
};
// Butterfly history (after Vine, aronpetkovski.com/blog/butterfly-history-mcts):
// every playout scores each move on its path with the playout's result, and
// the score is added to the move's policy logit when a node is expanded.
class ButterflyHistory {
public:
// Value of a move's entry at which it shifts the policy logit by 1.
static constexpr float LOGIT_SCALE = 16384.0f;
void clear() { table_ = {}; }
int get(int stm, Move m) const { return table_[stm][m.from()][m.to()]; }
// `bonus` is the playout's result for the side that played `m`, in
// centipawns. Entries pull towards it and saturate near +-8192.
void update(int stm, Move m, int bonus) {
i16& entry = table_[stm][m.from()][m.to()];
const int v = entry + bonus - entry * std::abs(bonus) / 8192;
entry = i16(std::clamp(v, -32000, 32000));
}
private:
std::array<std::array<std::array<i16, 64>, 64>, 2> table_{};
};
struct SearchLimits {
u64 nodes = 0;
i64 movetime = 0;
i64 time[2] = {0, 0};
i64 inc[2] = {0, 0};
int movestogo = 0;
int depth = 0;
bool infinite = false;
};
struct SearchParams {
float cpuct = 1.60f;
// At the root: cpuct x 1.458, Monty's root_cpuct / cpuct (0.4119 / 0.2826).
float root_cpuct = 2.33f;
// cpuct is multiplied by 1 + ln((N + scale) / scale) for a node with N visits
// (Monty: 64 x 128).
float cpuct_visit_scale = 8192.0f;
float fpu_reduction = 0.30f;
float policy_temperature = 1.00f;
i64 move_overhead = 20;
};
struct SearchResult {
Move best;
u64 nodes = 0; // playouts
u64 tree_positions = 0; // positions visited across all playouts (bench signature)
i64 time_ms = 0;
};
class Searcher {
public:
SearchParams params;
std::atomic<bool> stop_flag{false};
// Coloured output for a human at a terminal instead of UCI info lines.
bool pretty = false;
Searcher();
void set_hash(size_t mb) {
// All of it goes to the graph (its arenas, split by
// Tree::EDGES_PER_NODE, and its table). The graph shares a position's
// value between move orders, which a separate value hash did in the
// tree (plan variant 5c removed it).
tree_.resize_bytes(mb * 1024 * 1024);
tree_valid_ = false;
}
// Forget the previous tree, e.g. on ucinewgame.
void new_game() {
tree_valid_ = false;
butterfly_.clear();
}
// Synchronous search. `history` holds the keys of every position that led to
// `root`, including the key of `root` itself (for repetition detection).
SearchResult search(const Position& root, const std::vector<u64>& history, const SearchLimits& limits,
bool print_info);
#ifdef RIGBY_VERIFY_TREE
// The `verify` command: incremental keys along random games, and garbage
// collection and rerooting against a snapshot of the tree. Aborts on a failure.
void self_test();
#endif
private:
using Clock = std::chrono::steady_clock;
Tree tree_;
// Kept between moves of a game, like the tree.
ButterflyHistory butterfly_;
Position root_pos_;
std::vector<u64> history_;
size_t root_history_size_ = 0;
// The nodes of a playout, from the root, and the edges it took
// (edge_path_[i] leaves path_[i]). A playout that ends in a draw of its
// path has one edge more than nodes before the draw.
std::vector<u32> path_;
std::vector<u32> edge_path_;
// Guards against a key collision linking positions into a loop that
// repetition detection cannot see. Real playouts end long before this.
static constexpr int MAX_PLAYOUT_DEPTH = 512;
// The previous search, kept so its tree can be reused.
bool tree_valid_ = false;
Position prev_root_;
std::vector<u64> prev_history_;
Clock::time_point start_time_;
i64 time_limit_ms_ = 0; // soft limit
i64 hard_limit_ms_ = 0;
static constexpr i64 HARD_LIMIT_FACTOR = 3;
// The limit comes from the game clock (not movetime), so stopping early saves time.
bool clock_search_ = false;
std::vector<u32> root_start_visits_;
// Lc0's default: the remaining playouts are divided by this before asking
// whether another root move could still overtake the best one.
static constexpr double SMART_PRUNING_FACTOR = 1.33;
u64 iterations_ = 0;
u64 depth_sum_ = 0;
int seldepth_ = 0;
bool gc_pending_ = false;
int gc_runs_ = 0;
size_t reused_ = 0;
u64 node_limit_ = 0;
pretty::LiveView live_;
// Share of the arena kept after a collection.
static constexpr double GC_KEEP_FRACTION = 0.5;
void playout();
// First visit of a position: a new node with one visit, entered into the
// table. Settles what the position itself decides (checkmate, stalemate,
// insufficient material except at the root), otherwise evaluates.
// `value` gets the result for the side to move. Returns 0 when the node
// arena is full.
u32 create_node(const Position& pos, bool is_root, float& value);
// Second visit: creates the edges with their priors. False when the
// arena is full (a collection is then scheduled).
bool expand(u32 idx, const Position& pos);
// The edge PUCT picks at node `idx`.
u32 select_edge(u32 idx) const;
// A node's Q from its own value and its children's (see Edge).
void recompute_q(Node& node) const;
bool is_repetition(const Position& pos) const;
// Finds the node for `root` in the previous graph and makes it the root.
// Returns the number of nodes in the graph (some may no longer be
// reachable), 0 when nothing could be reused.
size_t reuse_tree(const Position& root);
// True when the root node's edges are exactly the legal moves of `root`.
bool root_edges_valid(const Position& root) const;
// Empties the graph, leaving an evaluated, unexpanded root for `root`.
void clear_tree(const Position& root);
#ifdef RIGBY_VERIFY_TREE
// Checks the graph from root_pos_; `history` ends with the root's key.
// `collected`: right after a collection, when every node must be reachable.
void verify_tree(const std::vector<u64>& history, bool collected = false) const;
#endif
void compute_time_limit(const SearchLimits& limits);
i64 elapsed_ms() const;
bool should_stop(const SearchLimits& limits) const;
bool best_move_settled(i64 ms, i64 limit_ms) const;
// The edge with the most visits at node `idx`, 0 when it has none.
u32 best_edge(u32 idx) const;
// Q of a visited edge from the view of the side choosing it: the child's
// Q, with draws of the path counted as 0.
float visited_edge_q(const Edge& e) const {
if (!e.draws) return tree_.node(e.child).q;
const u32 w = e.visits - e.draws;
return w ? float(w) / float(e.visits) * tree_.node(e.child).q : 0.0f;
}
// The same, 0 when the edge is unvisited.
float edge_q(const Edge& e) const { return e.visits ? visited_edge_q(e) : 0.0f; }
void print_info() const;
std::vector<Move> principal_variation() const;
void draw_dashboard(bool done);
};
} // namespace rigby
-442
View File
@@ -1,442 +0,0 @@
#include "mcts.h"
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include "eval.h"
#include "uci_io.h"
namespace rigby {
// ---------------------------------------------------------------------------
// Tree
// ---------------------------------------------------------------------------
void Tree::resize_mb(size_t mb) {
const size_t count = std::max<size_t>(mb * 1024 * 1024 / sizeof(Node), 1024);
nodes_.assign(count, Node{});
nodes_.shrink_to_fit();
clear();
}
void Tree::clear() {
used_ = 2; // index 0 is the null child, index 1 is the root
nodes_[root()] = Node{};
}
u32 Tree::alloc(u32 count) {
if (used_ + count > nodes_.size()) return 0;
const u32 idx = u32(used_);
used_ += count;
return idx;
}
size_t Tree::reroot(u32 new_root) {
if (new_root == root()) return used_;
// Every child block of the subtree, as (old first index, size).
std::vector<std::pair<u32, u32>> blocks;
std::vector<u32> stack{new_root};
while (!stack.empty()) {
const Node& node = nodes_[stack.back()];
stack.pop_back();
if (!node.first_child) continue;
blocks.emplace_back(node.first_child, node.num_children);
for (u32 i = 0; i < node.num_children; i++) stack.push_back(node.first_child + i);
}
// A block is always allocated after its parent's block, so packing the kept
// blocks in their original order only ever moves them towards the front, and
// never onto a block that has not moved yet. That allows doing it in place.
std::sort(blocks.begin(), blocks.end());
std::vector<u32> dest(blocks.size());
u32 next = 2;
for (size_t i = 0; i < blocks.size(); i++) {
dest[i] = next;
next += blocks[i].second;
}
const auto remap = [&](u32 old_first) -> u32 {
if (!old_first) return 0;
const auto it = std::lower_bound(blocks.begin(), blocks.end(), std::make_pair(old_first, u32(0)));
return dest[size_t(it - blocks.begin())];
};
// The new root's own slot may be overwritten by a moved block, so take it first.
Node new_root_node = nodes_[new_root];
new_root_node.first_child = remap(new_root_node.first_child);
for (size_t i = 0; i < blocks.size(); i++) {
const auto [first, count] = blocks[i];
if (dest[i] != first) std::memmove(&nodes_[dest[i]], &nodes_[first], size_t(count) * sizeof(Node));
for (u32 j = 0; j < count; j++) {
Node& node = nodes_[dest[i] + j];
node.first_child = remap(node.first_child);
}
}
nodes_[root()] = new_root_node;
used_ = next;
return used_ - 1; // everything but the null slot
}
// ---------------------------------------------------------------------------
// Searcher
// ---------------------------------------------------------------------------
Searcher::Searcher() { tree_.resize_mb(64); }
i64 Searcher::elapsed_ms() const {
return std::chrono::duration_cast<std::chrono::milliseconds>(Clock::now() - start_time_).count();
}
void Searcher::compute_time_limit(const SearchLimits& limits) {
time_limit_ms_ = 0;
if (limits.infinite) return;
if (limits.movetime) {
time_limit_ms_ = std::max<i64>(1, limits.movetime - params.move_overhead);
return;
}
const int us = root_pos_.stm;
if (limits.time[us] <= 0) return;
const i64 remaining = std::max<i64>(1, limits.time[us] - params.move_overhead);
const i64 moves_left = limits.movestogo ? std::min(limits.movestogo, 40) : 25;
const i64 target = remaining / moves_left + limits.inc[us] * 3 / 4;
time_limit_ms_ = std::clamp<i64>(target, 1, remaining / 2 + 1);
}
bool Searcher::should_stop(const SearchLimits& limits) const {
if (stop_flag.load(std::memory_order_relaxed)) return true;
if (limits.nodes && iterations_ >= limits.nodes) return true;
if (limits.depth && iterations_) {
// "depth" is the mean playout depth. Solved positions may never get
// there, so a depth limit also carries a generous playout cap.
if (int(depth_sum_ / iterations_) >= limits.depth) return true;
if (iterations_ >= (u64(1000) << std::min(2 * limits.depth, 14))) return true;
}
// The clock is cheap but not free; look at it every 64 playouts.
if (time_limit_ms_ && (iterations_ & 63) == 0 && elapsed_ms() >= time_limit_ms_) return true;
return false;
}
bool Searcher::is_repetition(const Position& pos) const {
// history_.back() is the key of `pos` itself. Any earlier occurrence with the
// same side to move inside the reversible window counts as a draw (two-fold).
const int n = int(history_.size());
for (int back = 4; back <= pos.halfmove && back < n; back += 2)
if (history_[n - 1 - back] == pos.key) return true;
return false;
}
size_t Searcher::reuse_tree(const Position& root) {
// The new game history must continue the previous one; the keys after the
// old root are the positions reached by the moves played since.
if (!tree_valid_ || history_.size() < prev_history_.size() ||
!std::equal(prev_history_.begin(), prev_history_.end(), history_.begin()))
return 0;
u32 idx = Tree::root();
Position pos = prev_root_;
for (size_t i = prev_history_.size(); i < history_.size(); i++) {
const Node& node = tree_[idx];
if (node.state != EXPANDED) return 0;
u32 next = 0;
for (u32 c = 0; c < node.num_children && !next; c++) {
Position child = pos;
child.make_move(Move::from_raw(tree_[node.first_child + c].move));
if (child.key == history_[i]) {
next = node.first_child + c;
pos = child;
}
}
if (!next) return 0;
idx = next;
}
// A node that was a draw by repetition or the 50-move rule inside the old
// tree can be a real position to play from now; start such a root afresh.
if (pos.key != root.key || tree_[idx].state != EXPANDED) return 0;
return tree_.reroot(idx);
}
#ifdef RIGBY_VERIFY_TREE
// Debug check: the tree must still describe legal play from the root, and every
// expanded node must have at least one visit more than its children together
// (more when it was evaluated as a leaf while the tree was full).
void Searcher::verify_tree() const {
struct Item {
u32 idx;
Position pos;
};
std::vector<Item> stack{{Tree::root(), root_pos_}};
u64 checked = 0;
while (!stack.empty()) {
const Item item = stack.back();
stack.pop_back();
const Node& node = tree_[item.idx];
checked++;
if (node.state != EXPANDED) continue;
MoveList legal;
generate_legal(item.pos, legal);
u64 child_visits = 0;
bool ok = node.first_child >= 2 && node.first_child + node.num_children <= tree_.used() &&
node.num_children == legal.size();
for (u32 c = 0; ok && c < node.num_children; c++) {
const Node& child = tree_[node.first_child + c];
const Move m = Move::from_raw(child.move);
ok = std::find(legal.begin(), legal.end(), m) != legal.end();
child_visits += child.visits;
Position next = item.pos;
next.make_move(m);
stack.push_back({node.first_child + c, next});
}
if (!ok || node.visits < child_visits + 1) {
std::cerr << "TREE CORRUPT at node " << item.idx << " (" << item.pos.fen() << ") ok=" << ok
<< " visits=" << node.visits << " child_visits=" << child_visits
<< " children=" << int(node.num_children) << " legal=" << legal.size()
<< " first=" << node.first_child << " used=" << tree_.used() << std::endl;
std::abort();
}
}
uci_io::send("info string tree verified: " + std::to_string(checked) + " nodes");
}
#endif
float Searcher::expand(u32 idx, const Position& pos, int depth) {
Node& node = tree_[idx];
MoveList moves;
generate_legal(pos, moves);
if (moves.empty()) {
node.state = pos.in_check() ? TERMINAL_LOSS : TERMINAL_DRAW;
return node.state == TERMINAL_LOSS ? -1.0f : 0.0f;
}
// The root must always produce a move, so it is never declared drawn.
if (depth > 0 && (pos.halfmove >= 100 || pos.insufficient_material() || is_repetition(pos))) {
node.state = TERMINAL_DRAW;
return 0.0f;
}
const u32 first = tree_.alloc(u32(moves.size()));
if (!first) {
// Out of memory: keep the node as a leaf and just evaluate it again.
tree_full_ = true;
return eval::value(pos);
}
float priors[256];
eval::policy(pos, moves, params.policy_temperature, priors);
for (int i = 0; i < moves.size(); i++) {
Node& child = tree_[first + i];
child = Node{};
child.move = moves[i].raw();
child.policy = u16(std::lround(std::clamp(priors[i], 0.0f, 1.0f) * 65535.0f));
}
node.first_child = first;
node.num_children = u8(moves.size());
node.state = EXPANDED;
return eval::value(pos);
}
u32 Searcher::select_child(u32 idx) const {
const Node& node = tree_[idx];
// node.q is from the view of the side that moved into this node, so the side
// to move here sees -q.
const float parent_q = node.visits ? -node.q : 0.0f;
float visited_policy = 0.0f;
for (u32 i = 0; i < node.num_children; i++) {
const Node& child = tree_[node.first_child + i];
if (child.visits) visited_policy += child.prior();
}
const float fpu = parent_q - params.fpu_reduction * std::sqrt(visited_policy);
const float explore = params.cpuct * std::sqrt(float(std::max<u32>(node.visits, 1)));
u32 best = node.first_child;
float best_score = -1e30f;
for (u32 i = 0; i < node.num_children; i++) {
const u32 c = node.first_child + i;
const Node& child = tree_[c];
const float q = child.visits ? child.q : fpu;
const float score = q + explore * child.prior() / float(1 + child.visits);
if (score > best_score) {
best_score = score;
best = c;
}
}
return best;
}
void Searcher::playout() {
Position pos = root_pos_;
history_.resize(root_history_size_);
path_.clear();
u32 idx = Tree::root();
path_.push_back(idx);
int depth = 0;
float value;
for (;;) {
const Node& node = tree_[idx];
if (node.state == TERMINAL_LOSS) {
value = -1.0f;
break;
}
if (node.state == TERMINAL_DRAW) {
value = 0.0f;
break;
}
if (node.state == UNEXPANDED) {
value = expand(idx, pos, depth);
break;
}
idx = select_child(idx);
pos.make_move(Move::from_raw(tree_[idx].move));
history_.push_back(pos.key);
path_.push_back(idx);
depth++;
}
// `value` is from the view of the side to move at the leaf. Each node stores
// the view of the side that moved into it, so flip before every update.
for (size_t i = path_.size(); i-- > 0;) {
value = -value;
Node& node = tree_[path_[i]];
node.visits++;
node.q += (value - node.q) / float(node.visits);
}
iterations_++;
depth_sum_ += u64(depth);
seldepth_ = std::max(seldepth_, depth);
}
u32 Searcher::best_child(u32 idx) const {
const Node& node = tree_[idx];
u32 best = 0;
for (u32 i = 0; i < node.num_children; i++) {
const u32 c = node.first_child + i;
if (!best) {
best = c;
continue;
}
const Node& a = tree_[c];
const Node& b = tree_[best];
// Most visits wins; ties go to the better Q, then to the higher prior.
if (a.visits != b.visits ? a.visits > b.visits : a.visits ? a.q > b.q : a.policy > b.policy) best = c;
}
return best;
}
void Searcher::print_info() const {
const Node& root = tree_[Tree::root()];
const i64 ms = elapsed_ms();
const u32 best = best_child(Tree::root());
std::ostringstream out;
out << "info depth " << (iterations_ ? std::max<u64>(1, depth_sum_ / iterations_) : 0) << " seldepth "
<< seldepth_;
const float q = best && tree_[best].visits ? tree_[best].q : -root.q;
out << " score cp " << eval::q_to_cp(q);
out << " nodes " << iterations_ << " nps " << (ms ? iterations_ * 1000 / u64(ms) : iterations_) << " time " << ms;
out << " hashfull " << (tree_.used() * 1000 / tree_.capacity());
out << " pv";
u32 idx = Tree::root();
for (int ply = 0; ply < 64; ply++) {
const u32 c = best_child(idx);
if (!c || !tree_[c].visits) break;
out << ' ' << Move::from_raw(tree_[c].move).to_uci();
idx = c;
}
uci_io::send(out.str());
}
SearchResult Searcher::search(const Position& root, const std::vector<u64>& history, const SearchLimits& limits,
bool print) {
start_time_ = Clock::now();
root_pos_ = root;
history_ = history;
if (history_.empty() || history_.back() != root.key) history_.push_back(root.key);
root_history_size_ = history_.size();
#ifdef RIGBY_VERIFY_TREE
// Check the previous tree as the last search left it, and again after rerooting.
if (tree_valid_ && history_.size() >= prev_history_.size()) {
root_pos_ = prev_root_;
verify_tree();
root_pos_ = root;
}
#endif
const size_t reused = reuse_tree(root);
if (!reused) tree_.clear();
#ifdef RIGBY_VERIFY_TREE
if (reused) verify_tree();
#endif
if (print && reused) uci_io::send("info string reused " + std::to_string(reused) + " nodes");
iterations_ = 0;
depth_sum_ = 0;
seldepth_ = 0;
tree_full_ = false;
compute_time_limit(limits);
SearchResult result;
MoveList root_moves;
generate_legal(root, root_moves);
if (root_moves.empty()) {
tree_valid_ = false;
if (print) uci_io::send("info depth 0 score " + std::string(root.in_check() ? "mate 0" : "cp 0"));
return result;
}
i64 last_info = 0;
// Always run at least one playout so the root gets expanded.
do {
playout();
if (print && (iterations_ & 1023) == 0) {
const i64 ms = elapsed_ms();
if (ms - last_info >= 1000) {
last_info = ms;
print_info();
}
}
} while (!should_stop(limits));
if (print) {
print_info();
if (tree_full_) uci_io::send("info string tree memory full, raise Hash");
}
const u32 best = best_child(Tree::root());
result.best = Move::from_raw(tree_[best].move);
result.nodes = iterations_;
result.tree_positions = iterations_ + depth_sum_;
result.time_ms = elapsed_ms();
tree_valid_ = true;
prev_root_ = root;
prev_history_.assign(history_.begin(), history_.begin() + std::ptrdiff_t(root_history_size_));
return result;
}
} // namespace rigby
-138
View File
@@ -1,138 +0,0 @@
#pragma once
#include <atomic>
#include <chrono>
#include <vector>
#include "position.h"
namespace rigby {
enum NodeState : u8 {
UNEXPANDED = 0,
EXPANDED,
TERMINAL_LOSS, // side to move is checkmated
TERMINAL_DRAW,
};
// 20 bytes. Children of a node sit next to each other in the arena, so a node
// only needs the index of its first child.
struct Node {
u32 first_child = 0;
u32 visits = 0;
float q = 0.0f; // running mean, from the view of the side that played `move`
u16 move = 0;
u16 policy = 0; // prior scaled to 0..65535
u8 num_children = 0;
u8 state = UNEXPANDED;
float prior() const { return float(policy) * (1.0f / 65535.0f); }
};
class Tree {
public:
void resize_mb(size_t mb);
void clear();
// Returns the index of `count` fresh nodes, or 0 when the arena is full.
u32 alloc(u32 count);
// Makes `new_root` the root and packs its subtree to the front of the arena;
// everything else is dropped. Returns the number of nodes kept.
size_t reroot(u32 new_root);
Node& operator[](u32 idx) { return nodes_[idx]; }
const Node& operator[](u32 idx) const { return nodes_[idx]; }
static constexpr u32 root() { return 1; }
size_t used() const { return used_; }
size_t capacity() const { return nodes_.size(); }
private:
std::vector<Node> nodes_;
size_t used_ = 0;
};
struct SearchLimits {
u64 nodes = 0;
i64 movetime = 0;
i64 time[2] = {0, 0};
i64 inc[2] = {0, 0};
int movestogo = 0;
int depth = 0;
bool infinite = false;
};
struct SearchParams {
float cpuct = 1.60f;
float fpu_reduction = 0.30f;
float policy_temperature = 1.00f;
i64 move_overhead = 20;
};
struct SearchResult {
Move best;
u64 nodes = 0; // playouts
u64 tree_positions = 0; // positions visited across all playouts (bench signature)
i64 time_ms = 0;
};
class Searcher {
public:
SearchParams params;
std::atomic<bool> stop_flag{false};
Searcher();
void set_hash(size_t mb) {
tree_.resize_mb(mb);
tree_valid_ = false;
}
// Forget the previous tree, e.g. on ucinewgame.
void new_game() { tree_valid_ = false; }
// Synchronous search. `history` holds the keys of every position that led to
// `root`, including the key of `root` itself (for repetition detection).
SearchResult search(const Position& root, const std::vector<u64>& history, const SearchLimits& limits,
bool print_info);
private:
using Clock = std::chrono::steady_clock;
Tree tree_;
Position root_pos_;
std::vector<u64> history_;
size_t root_history_size_ = 0;
std::vector<u32> path_;
// The previous search, kept so its tree can be reused.
bool tree_valid_ = false;
Position prev_root_;
std::vector<u64> prev_history_;
Clock::time_point start_time_;
i64 time_limit_ms_ = 0;
u64 iterations_ = 0;
u64 depth_sum_ = 0;
int seldepth_ = 0;
bool tree_full_ = false;
void playout();
float expand(u32 idx, const Position& pos, int depth);
u32 select_child(u32 idx) const;
bool is_repetition(const Position& pos) const;
// Finds the node for `root` in the previous tree and makes it the root.
// Returns the number of nodes kept, 0 when nothing could be reused.
size_t reuse_tree(const Position& root);
#ifdef RIGBY_VERIFY_TREE
void verify_tree() const;
#endif
void compute_time_limit(const SearchLimits& limits);
i64 elapsed_ms() const;
bool should_stop(const SearchLimits& limits) const;
u32 best_child(u32 idx) const;
void print_info() const;
};
} // namespace rigby
+123 -32
View File
@@ -1,3 +1,5 @@
#include <bit>
#include "position.h"
namespace rigby {
@@ -21,10 +23,25 @@ void add_pawn_move(MoveList& list, int from, int to, bool capture, bool promotio
}
}
} // namespace
// Our pieces pinned to our king by an enemy slider.
u64 pinned_pieces(const Position& pos, int us, int ksq, u64 occ) {
const u64 diag_sliders = pos.pieces[BISHOP] | pos.pieces[QUEEN];
const u64 orth_sliders = pos.pieces[ROOK] | pos.pieces[QUEEN];
u64 pinned = 0;
u64 snipers = ((attacks::rook(ksq, 0) & orth_sliders) | (attacks::bishop(ksq, 0) & diag_sliders)) & pos.colors[us ^ 1];
while (snipers) {
const int s = pop_lsb(snipers);
const u64 blockers = attacks::between[ksq][s] & occ;
if (blockers && !(blockers & (blockers - 1)) && (blockers & pos.colors[us])) pinned |= blockers;
}
return pinned;
}
// Fully legal generation using check and pin masks.
void generate_legal(const Position& pos, MoveList& list) {
// Fully legal generation using check and pin masks. With NOISY only captures
// (en passant included) and queen promotions, in the same order as the full
// generation lists them.
template <bool NOISY>
void generate(const Position& pos, MoveList& list) {
list.clear();
const int us = pos.stm;
@@ -40,7 +57,7 @@ void generate_legal(const Position& pos, MoveList& list) {
// King moves: the king itself must not block a slider ray on its destination.
{
const u64 occ_no_king = occ ^ bb(ksq);
u64 targets = attacks::king[ksq] & ~ours;
u64 targets = attacks::king[ksq] & (NOISY ? theirs : ~ours);
while (targets) {
const int to = pop_lsb(targets);
if (!pos.square_attacked(to, them, occ_no_king))
@@ -51,30 +68,23 @@ void generate_legal(const Position& pos, MoveList& list) {
if (num_checkers > 1) return;
const u64 check_mask = num_checkers ? (attacks::between[ksq][lsb(checkers)] | checkers) : ~0ULL;
// Squares a piece may move to: anything but our own pieces, or only theirs.
const u64 target_mask = check_mask & (NOISY ? theirs : ~ours);
const u64 diag_sliders = pos.pieces[BISHOP] | pos.pieces[QUEEN];
const u64 orth_sliders = pos.pieces[ROOK] | pos.pieces[QUEEN];
u64 pinned = 0;
{
u64 snipers = ((attacks::rook(ksq, 0) & orth_sliders) | (attacks::bishop(ksq, 0) & diag_sliders)) & theirs;
while (snipers) {
const int s = pop_lsb(snipers);
const u64 blockers = attacks::between[ksq][s] & occ;
if (blockers && !(blockers & (blockers - 1)) && (blockers & ours)) pinned |= blockers;
}
}
const u64 pinned = pinned_pieces(pos, us, ksq, occ);
// A pinned knight can never move.
u64 knights = pos.pieces_of(us, KNIGHT) & ~pinned;
while (knights) {
const int from = pop_lsb(knights);
add_targets(list, from, attacks::knight[from] & ~ours & check_mask, theirs);
add_targets(list, from, attacks::knight[from] & target_mask, theirs);
}
u64 diag = diag_sliders & ours;
while (diag) {
const int from = pop_lsb(diag);
u64 targets = attacks::bishop(from, occ) & ~ours & check_mask;
u64 targets = attacks::bishop(from, occ) & target_mask;
if (pinned & bb(from)) targets &= attacks::line[ksq][from];
add_targets(list, from, targets, theirs);
}
@@ -82,7 +92,7 @@ void generate_legal(const Position& pos, MoveList& list) {
u64 orth = orth_sliders & ours;
while (orth) {
const int from = pop_lsb(orth);
u64 targets = attacks::rook(from, occ) & ~ours & check_mask;
u64 targets = attacks::rook(from, occ) & target_mask;
if (pinned & bb(from)) targets &= attacks::line[ksq][from];
add_targets(list, from, targets, theirs);
}
@@ -99,10 +109,14 @@ void generate_legal(const Position& pos, MoveList& list) {
const int to = from + up;
if (!(occ & bb(to))) {
if (allowed & bb(to)) add_pawn_move(list, from, to, false, promo_rank & bb(to));
const int to2 = to + up;
if ((start_rank & bb(from)) && !(occ & bb(to2)) && (allowed & bb(to2)))
list.add(Move(from, to2, Move::DOUBLE_PUSH));
if constexpr (NOISY) {
if ((allowed & bb(to)) && (promo_rank & bb(to))) list.add(Move(from, to, Move::PROMO + 3));
} else {
if (allowed & bb(to)) add_pawn_move(list, from, to, false, promo_rank & bb(to));
const int to2 = to + up;
if ((start_rank & bb(from)) && !(occ & bb(to2)) && (allowed & bb(to2)))
list.add(Move(from, to2, Move::DOUBLE_PUSH));
}
}
u64 captures = attacks::pawn[us][from] & theirs & allowed;
@@ -124,22 +138,99 @@ void generate_legal(const Position& pos, MoveList& list) {
}
}
if (num_checkers) return;
if (NOISY || num_checkers) return;
// Castling, Chess960 rules: the king goes to the g/c file and the rook to
// the f/d file. Every square either piece crosses or lands on must be empty
// apart from the two of them, and the king must not cross or land on an
// attacked square. The moved rook is taken out of the occupancy for that
// check, since it may be what shields one of those squares.
const int rank_base = us == WHITE ? 0 : 56;
const int oo = us == WHITE ? WHITE_OO : BLACK_OO;
const int ooo = us == WHITE ? WHITE_OOO : BLACK_OOO;
const u64 our_rooks = pos.pieces_of(us, ROOK);
for (const bool king_side : {true, false}) {
const int right = us == WHITE ? (king_side ? WHITE_OO : WHITE_OOO) : (king_side ? BLACK_OO : BLACK_OOO);
if (!(pos.castling & right)) continue;
const int rook = pos.castle_rook[std::countr_zero(unsigned(right))];
if (!(our_rooks & bb(rook))) continue;
const int king_to = rank_base + (king_side ? 6 : 2);
const int rook_to = rank_base + (king_side ? 5 : 3);
const u64 others = occ ^ bb(ksq) ^ bb(rook);
const u64 king_path = attacks::between[ksq][king_to] | bb(king_to);
const u64 rook_path = attacks::between[rook][rook_to] | bb(rook_to);
if ((king_path | rook_path) & others) continue;
// The destination is checked even when the king already stands on it:
// the rook leaving can uncover an attack along the rank.
u64 check = king_path;
bool safe = true;
while (check && safe) safe = !pos.square_attacked(pop_lsb(check), them, others);
if (safe) list.add(Move(ksq, king_to, king_side ? Move::KING_CASTLE : Move::QUEEN_CASTLE));
}
}
if ((pos.castling & oo) && (our_rooks & bb(rank_base + 7)) &&
!(occ & (bb(rank_base + 5) | bb(rank_base + 6))) && !pos.square_attacked(rank_base + 5, them, occ) &&
!pos.square_attacked(rank_base + 6, them, occ))
list.add(Move(ksq, rank_base + 6, Move::KING_CASTLE));
} // namespace
if ((pos.castling & ooo) && (our_rooks & bb(rank_base + 0)) &&
!(occ & (bb(rank_base + 1) | bb(rank_base + 2) | bb(rank_base + 3))) &&
!pos.square_attacked(rank_base + 3, them, occ) && !pos.square_attacked(rank_base + 2, them, occ))
list.add(Move(ksq, rank_base + 2, Move::QUEEN_CASTLE));
void generate_legal(const Position& pos, MoveList& list) { generate<false>(pos, list); }
void generate_noisy(const Position& pos, MoveList& list) { generate<true>(pos, list); }
bool has_legal_move(const Position& pos) {
const int us = pos.stm;
const int them = us ^ 1;
const u64 occ = pos.occupancy();
const u64 ours = pos.colors[us];
const int ksq = pos.king_square(us);
// In check, with an en passant capture around, or with Chess960 castling
// that a king step cannot stand in for, just generate everything.
const int our_rights = pos.castling & (us == WHITE ? WHITE_OO | WHITE_OOO : BLACK_OO | BLACK_OOO);
const bool standard_castling = !our_rights || (ksq == (us == WHITE ? E1 : E8) &&
(!(our_rights & (WHITE_OO | BLACK_OO)) ||
file_of(pos.castle_rook[us == WHITE ? 0 : 2]) == 7) &&
(!(our_rights & (WHITE_OOO | BLACK_OOO)) ||
file_of(pos.castle_rook[us == WHITE ? 1 : 3]) == 0));
if (pos.in_check() || pos.ep != NO_SQUARE || !standard_castling) {
MoveList list;
generate<false>(pos, list);
return !list.empty();
}
// Not in check, so castling only adds moves when the king can already step
// to the square next to it; the king, the pieces and the pawns decide.
const u64 pinned = pinned_pieces(pos, us, ksq, occ);
u64 knights = pos.pieces_of(us, KNIGHT) & ~pinned;
while (knights)
if (attacks::knight[pop_lsb(knights)] & ~ours) return true;
u64 targets = attacks::king[ksq] & ~ours;
while (targets)
if (!pos.square_attacked(pop_lsb(targets), them, occ ^ bb(ksq))) return true;
u64 sliders = (pos.pieces[BISHOP] | pos.pieces[QUEEN]) & ours;
while (sliders) {
const int from = pop_lsb(sliders);
u64 t = attacks::bishop(from, occ) & ~ours;
if (pinned & bb(from)) t &= attacks::line[ksq][from];
if (t) return true;
}
sliders = (pos.pieces[ROOK] | pos.pieces[QUEEN]) & ours;
while (sliders) {
const int from = pop_lsb(sliders);
u64 t = attacks::rook(from, occ) & ~ours;
if (pinned & bb(from)) t &= attacks::line[ksq][from];
if (t) return true;
}
const int up = us == WHITE ? 8 : -8;
u64 pawns = pos.pieces_of(us, PAWN);
while (pawns) {
const int from = pop_lsb(pawns);
u64 t = attacks::pawn[us][from] & pos.colors[them];
if (!(occ & bb(from + up))) t |= bb(from + up);
if (pinned & bb(from)) t &= attacks::line[ksq][from];
if (t) return true;
}
return false;
}
} // namespace rigby
+174
View File
@@ -0,0 +1,174 @@
#include "nnue.h"
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "incbin.h"
#include "simd.h"
#ifndef EVALFILE
#error "EVALFILE must name the network file (the Makefile sets it)"
#endif
INCBIN(RigbyNet, EVALFILE);
namespace rigby::nnue {
namespace {
// Layout of bullet's quantised.bin, padded by bullet to a multiple of 64 bytes.
struct alignas(64) Network {
i16 l0w[768][HIDDEN]; // feature-major: one HIDDEN-wide column per input
i16 l0b[HIDDEN];
i16 l1w[2 * HIDDEN]; // side to move's half first
i16 l1b;
};
Network net;
// Input index from one side's point of view: its own pieces first, and the
// board flipped vertically for black (bullet's Chess768).
inline int feature(int perspective, int piece, int sq) {
const int theirs = piece_color(piece) != perspective;
const int rel_sq = perspective == WHITE ? sq : sq ^ 56;
return 384 * theirs + 64 * piece_type(piece) + rel_sq;
}
// The output layer squares the clamped hidden value with v * (v * w): v * w
// must fit 16 bits, so the weights are checked on load.
constexpr int MAX_L1W = 32767 / QA;
// The output sum is taken in blocks that fit 32 bits, then added up in 64.
constexpr int BLOCK = 128;
static_assert(i64(2) * BLOCK * QA * QA * MAX_L1W <= INT_MAX);
static_assert(HIDDEN % BLOCK == 0 && BLOCK % simd::LANES == 0);
} // namespace
void init() {
if (gRigbyNetSize < sizeof(Network)) {
std::fprintf(stderr, "network %s is %u bytes, expected at least %u\n", EVALFILE, unsigned(gRigbyNetSize),
unsigned(sizeof(Network)));
std::exit(1);
}
std::memcpy(&net, gRigbyNetData, sizeof(Network));
for (int i = 0; i < 2 * HIDDEN; i++) {
if (std::abs(net.l1w[i]) > MAX_L1W) {
std::fprintf(stderr, "network %s has an output weight of %d, the limit is %d\n", EVALFILE, net.l1w[i],
MAX_L1W);
std::exit(1);
}
}
}
void refresh(const Position& pos, Accumulator& acc) {
const i16* rows[2][32];
int count = 0;
u64 occ = pos.occupancy();
while (occ) {
const int sq = pop_lsb(occ);
const int piece = pos.piece_on(sq);
rows[WHITE][count] = net.l0w[feature(WHITE, piece, sq)];
rows[BLACK][count++] = net.l0w[feature(BLACK, piece, sq)];
}
for (int side : {WHITE, BLACK}) simd::accumulate(acc.values[side], net.l0b, rows[side], count, HIDDEN);
}
void update(const Accumulator& before, const Position& pos, Move m, Accumulator& after) {
// At most two features come and two go (castling); captures and
// promotions change three. i16 sums wrap the same way in any order, so
// this matches a refresh exactly.
int add[2][2], sub[2][3];
int adds = 0, subs = 0;
const auto add_piece = [&](int piece, int sq) {
add[WHITE][adds] = feature(WHITE, piece, sq);
add[BLACK][adds++] = feature(BLACK, piece, sq);
};
const auto sub_piece = [&](int piece, int sq) {
sub[WHITE][subs] = feature(WHITE, piece, sq);
sub[BLACK][subs++] = feature(BLACK, piece, sq);
};
const int us = pos.stm;
const int from = m.from();
const int to = m.to();
const int moving = pos.piece_on(from);
sub_piece(moving, from);
add_piece(m.is_promotion() ? make_piece(us, m.promo_type()) : moving, to);
if (m.is_en_passant()) {
const int captured_sq = us == WHITE ? to - 8 : to + 8;
sub_piece(pos.piece_on(captured_sq), captured_sq);
} else if (m.is_capture()) {
sub_piece(pos.piece_on(to), to);
} else if (m.is_castle()) {
const int rank_base = us == WHITE ? 0 : 56;
const int rook = make_piece(us, ROOK);
const bool king_side = m.flag() == Move::KING_CASTLE;
sub_piece(rook, pos.castle_rook_square(m));
add_piece(rook, rank_base + (king_side ? 5 : 3));
}
for (int side : {WHITE, BLACK}) {
const i16* src = before.values[side];
i16* dst = after.values[side];
const i16* a0 = net.l0w[add[side][0]];
const i16* s0 = net.l0w[sub[side][0]];
using simd::load, simd::store, simd::LANES;
if (adds == 1 && subs == 1) {
for (int i = 0; i < HIDDEN; i += LANES)
store(dst + i, simd::sub(simd::add(load(src + i), load(a0 + i)), load(s0 + i)));
} else if (adds == 1) { // capture or capture-promotion
const i16* s1 = net.l0w[sub[side][1]];
for (int i = 0; i < HIDDEN; i += LANES) {
const simd::vi16 added = simd::add(load(src + i), load(a0 + i));
store(dst + i, simd::sub(simd::sub(added, load(s0 + i)), load(s1 + i)));
}
} else { // castling
const i16* a1 = net.l0w[add[side][1]];
const i16* s1 = net.l0w[sub[side][1]];
for (int i = 0; i < HIDDEN; i += LANES) {
const simd::vi16 added = simd::add(simd::add(load(src + i), load(a0 + i)), load(a1 + i));
store(dst + i, simd::sub(simd::sub(added, load(s0 + i)), load(s1 + i)));
}
}
}
}
int evaluate(const Accumulator& acc, int stm) {
const i16* us = acc.values[stm];
const i16* them = acc.values[stm ^ 1];
// SCReLU as v * (v * w) with v clamped to [0, QA]: exact, since v * w fits
// 16 bits and a block of both halves fits 32 (checked above).
using namespace simd;
const vi16 lo = set1(0), hi = set1(QA);
i64 out = 0;
for (int b = 0; b < HIDDEN; b += BLOCK) {
vi32 sum_us = zero32(), sum_them = zero32();
for (int i = b; i < b + BLOCK; i += LANES) {
const vi16 u = clamp(load(us + i), lo, hi);
const vi16 t = clamp(load(them + i), lo, hi);
sum_us = dot(sum_us, mullo(u, load(net.l1w + i)), u);
sum_them = dot(sum_them, mullo(t, load(net.l1w + HIDDEN + i)), t);
}
out += reduce(add32(sum_us, sum_them));
}
out /= QA;
out += net.l1b;
out *= SCALE;
out /= i64(QA) * QB;
return int(out);
}
int evaluate(const Position& pos) {
Accumulator acc;
refresh(pos, acc);
return evaluate(acc, pos.stm);
}
} // namespace rigby::nnue
+37
View File
@@ -0,0 +1,37 @@
#pragma once
#include "position.h"
namespace rigby::nnue {
// Value network trained with bullet on Lc0 data (see train/README.md):
// (768 -> HIDDEN)x2 -> 1, SCReLU, dual perspective, quantised i16.
constexpr int HIDDEN = 1024;
constexpr int SCALE = 400;
constexpr int QA = 255;
constexpr int QB = 64;
// The hidden layer before the activation, from white's and from black's point
// of view. Kept up to date move by move along the quiescence search.
struct Accumulator {
alignas(64) i16 values[2][HIDDEN];
};
// Checks and loads the embedded network. Exits with a message if it does not fit.
void init();
// Builds the accumulator of `pos` from scratch.
void refresh(const Position& pos, Accumulator& acc);
// The accumulator after `m`, from the one before it; `pos` is the position
// before the move. Gives exactly what refresh would give for the new position.
void update(const Accumulator& before, const Position& pos, Move m, Accumulator& after);
// Evaluation in centipawns from the view of `stm`, on the network's scale:
// sigmoid(cp / SCALE) is the expected score.
int evaluate(const Accumulator& acc, int stm);
// Same, building the accumulator from scratch.
int evaluate(const Position& pos);
} // namespace rigby::nnue
+51 -1
View File
@@ -1,6 +1,10 @@
#include "perft.h"
#include <chrono>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <string>
#include <iostream>
namespace rigby {
@@ -30,13 +34,59 @@ void perft_divide(const Position& pos, int depth) {
child.make_move(m);
const u64 n = depth > 1 ? perft(child, depth - 1) : 1;
total += n;
std::cout << m.to_uci() << ": " << n << "\n";
std::cout << pos.uci(m) << ": " << n << "\n";
}
const auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start).count();
std::cout << "\nNodes: " << total << "\nTime: " << ms << " ms\nNPS: " << (ms ? total * 1000 / ms : total) << std::endl;
}
bool perft_file(const std::string& path, int max_depth) {
std::ifstream in(path);
if (!in) {
std::cout << "cannot open " << path << std::endl;
return false;
}
bool all_ok = true;
int lines = 0, failed = 0;
u64 total = 0;
const auto start = std::chrono::steady_clock::now();
std::string line;
while (std::getline(in, line)) {
const auto semi = line.find(';');
if (semi == std::string::npos) continue;
Position pos;
if (!pos.set_fen(line.substr(0, semi))) {
std::cout << "[FAIL] bad fen: " << line << std::endl;
all_ok = false;
continue;
}
lines++;
std::istringstream ss(line.substr(semi));
std::string tag;
u64 expected = 0;
bool ok = true;
while (ss >> tag >> expected) {
const int depth = std::atoi(tag.c_str() + 2); // ";D<n>"
if (depth > max_depth) break;
const u64 n = perft(pos, depth);
total += n;
if (n != expected) {
std::cout << "[FAIL] " << line.substr(0, semi) << " depth " << depth << ": " << n << " (expected "
<< expected << ")" << std::endl;
ok = false;
break;
}
}
all_ok &= ok;
failed += !ok;
}
const auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start).count();
std::cout << (all_ok ? "All perft tests passed" : "PERFT FAILED") << " - " << lines << " positions, " << failed
<< " failed, " << total << " nodes in " << ms << " ms" << std::endl;
return all_ok;
}
bool perft_suite(int max_depth) {
struct Case {
const char* fen;
+5
View File
@@ -1,5 +1,7 @@
#pragma once
#include <string>
#include "position.h"
namespace rigby {
@@ -9,5 +11,8 @@ u64 perft(const Position& pos, int depth);
void perft_divide(const Position& pos, int depth);
// Runs the standard perft positions; returns true when every count matches.
bool perft_suite(int max_depth);
// Runs every "<fen> ;D1 <nodes> ;D2 <nodes> ..." line of an EPD file up to
// max_depth (Chess960 suites use Shredder-FEN castling); true when all match.
bool perft_file(const std::string& path, int max_depth);
} // namespace rigby
+214
View File
@@ -0,0 +1,214 @@
#include "policy.h"
#include <algorithm>
#include <array>
#include <bit>
#include <cstdio>
#include <fstream>
#include <iterator>
#include <vector>
#include "simd.h"
#ifdef POLICYFILE
#include "incbin.h"
INCBIN(RigbyPolicy, POLICYFILE);
#endif
namespace rigby::policy {
namespace {
constexpr int Q = 128;
// Weights as the trainer writes them (montytrain's save_quantised): l0w is
// feature-major ([input][hidden]), l1w move-major ([output][hidden / 2]).
struct Network {
int hidden = 0;
std::vector<i8> l0w, l0b, l1w, l1b;
};
Network net;
// --- Output index (train/policy/src/inputs.rs map_move_to_index) ---
// Squares a piece of each type could ever move to from a square, on an empty
// board, from white's side (pawns: one step forward or diagonally forward).
struct Tables {
u64 destinations[64][6];
int offsets[6][65];
};
const Tables& tables() {
static const Tables t = [] {
Tables t{};
for (int sq = 0; sq < 64; sq++) {
const u64 b = bb(sq);
t.destinations[sq][PAWN] = ((b & ~FILE_A_BB) << 7) | (b << 8) | ((b & ~FILE_H_BB) << 9);
t.destinations[sq][KNIGHT] = attacks::knight[sq];
t.destinations[sq][BISHOP] = attacks::bishop(sq, 0);
t.destinations[sq][ROOK] = attacks::rook(sq, 0);
t.destinations[sq][QUEEN] = attacks::queen(sq, 0);
t.destinations[sq][KING] = attacks::king[sq];
}
int current = 0;
for (int pc = 0; pc < 6; pc++) {
for (int sq = 0; sq < 64; sq++) {
t.offsets[pc][sq] = current;
current += popcount(t.destinations[sq][pc]);
}
t.offsets[pc][64] = current;
}
return t;
}();
return t;
}
constexpr int PROMO_STRIDE = 22;
// Squares attacked by `side`, sliders seeing through the other side's king.
u64 threats_by(const Position& pos, int side) {
const u64 occ = pos.occupancy() ^ pos.pieces_of(side ^ 1, KING);
u64 threats = 0;
u64 b = pos.pieces_of(side, ROOK) | pos.pieces_of(side, QUEEN);
while (b) threats |= attacks::rook(pop_lsb(b), occ);
b = pos.pieces_of(side, BISHOP) | pos.pieces_of(side, QUEEN);
while (b) threats |= attacks::bishop(pop_lsb(b), occ);
b = pos.pieces_of(side, KNIGHT);
while (b) threats |= attacks::knight[pop_lsb(b)];
threats |= attacks::king[pos.king_square(side)];
b = pos.pieces_of(side, PAWN);
while (b) threats |= attacks::pawn[side][pop_lsb(b)];
return threats;
}
bool set(std::vector<i8> data) {
// size = INPUTS * h + h + (h / 2) * OUTPUTS + OUTPUTS
const size_t per_hidden = INPUTS + 1 + OUTPUTS / 2;
if (data.size() <= OUTPUTS || (data.size() - OUTPUTS) % per_hidden) return false;
const int h = int((data.size() - OUTPUTS) / per_hidden);
if (h % 2) return false;
Network n;
n.hidden = h;
auto it = data.begin();
const auto take = [&](std::vector<i8>& v, size_t count) {
v.assign(it, it + std::ptrdiff_t(count));
it += std::ptrdiff_t(count);
};
take(n.l0w, size_t(INPUTS) * h);
take(n.l0b, h);
take(n.l1w, size_t(OUTPUTS) * (h / 2));
take(n.l1b, OUTPUTS);
net = std::move(n);
return true;
}
bool load_builtin() {
#ifdef POLICYFILE
const auto* p = reinterpret_cast<const i8*>(gRigbyPolicyData);
return set(std::vector<i8>(p, p + gRigbyPolicySize));
#else
net = Network{};
return true;
#endif
}
} // namespace
void init() {
tables();
if (!load_builtin()) {
std::fprintf(stderr, "built-in policy network has the wrong size\n");
net = Network{};
}
}
bool load(const std::string& path) {
if (path.empty() || path == "<empty>") return load_builtin();
std::ifstream in(path, std::ios::binary);
if (!in) return false;
std::vector<char> raw((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
return set(std::vector<i8>(raw.begin(), raw.end()));
}
bool loaded() { return net.hidden > 0; }
int hidden() { return net.hidden; }
int move_index(const Position& pos, Move m) {
const Tables& t = tables();
const int hm = file_of(pos.king_square(pos.stm)) > 3 ? 7 : 0;
const int flip = hm ^ (pos.stm == BLACK ? 56 : 0);
const int src = m.from() ^ flip;
const int dst = m.to() ^ flip;
const int specials = t.offsets[KING][64];
if (m.is_promotion())
return specials + PROMO_STRIDE * (m.promo_type() - KNIGHT) + 2 * file_of(src) + file_of(dst);
if (m.is_castle()) return specials + 4 * PROMO_STRIDE + ((m.flag() == Move::KING_CASTLE) ^ (hm == 0));
if (m.flag() == Move::DOUBLE_PUSH) return specials + 4 * PROMO_STRIDE + 2 + file_of(src);
const int pc = piece_type(pos.piece_on(m.from()));
const u64 below = t.destinations[src][pc] & (bb(dst) - 1);
return t.offsets[pc][src] + popcount(below);
}
void logits(const Position& pos, const MoveList& moves, float* out) {
const int h = net.hidden;
const int half = h / 2;
const int us = pos.stm;
const int flip = (us == BLACK ? 56 : 0) ^ (file_of(pos.king_square(us)) > 3 ? 7 : 0);
const u64 threats = threats_by(pos, us ^ 1);
const u64 defences = threats_by(pos, us);
// Hidden layer: bias plus one column per active input.
const i8* rows[32];
int count = 0;
u64 occ = pos.occupancy();
while (occ) {
const int sq = pop_lsb(occ);
const int piece = pos.piece_on(sq);
int feature = 384 * (piece_color(piece) != us) + 64 * piece_type(piece) + (sq ^ flip);
if (threats & bb(sq)) feature += 768;
if (defences & bb(sq)) feature += 1536;
rows[count++] = &net.l0w[size_t(feature) * h];
}
// Output rows of the moves.
const i8* out_rows[256];
int out_idx[256];
for (int m = 0; m < moves.size(); m++) {
out_idx[m] = move_index(pos, moves[m]);
out_rows[m] = &net.l1w[size_t(out_idx[m]) * half];
}
static thread_local std::vector<i16> acc;
static thread_local std::vector<i16> act;
acc.resize(size_t(h));
act.resize(size_t(half));
simd::accumulate(acc.data(), net.l0b.data(), rows, count, h);
// CReLU on both halves, multiplied pairwise: values up to Q * Q.
{
using namespace simd;
const vi16 lo = set1(0), hi = set1(Q);
int i = 0;
for (; i + LANES <= half; i += LANES) {
const vi16 a = clamp(simd::load(&acc[i]), lo, hi);
const vi16 b = clamp(simd::load(&acc[i + half]), lo, hi);
store(&act[i], mullo(a, b));
}
for (; i < half; i++) act[i] = i16(std::clamp<int>(acc[i], 0, Q) * std::clamp<int>(acc[i + half], 0, Q));
}
// One dot product per move, at most half * Q^3 (fits 32 bits); four moves
// at a time share the activation loads.
int sums[256];
int m = 0;
for (; m + 4 <= moves.size(); m += 4) simd::dot4(act.data(), out_rows + m, half, sums + m);
for (; m < moves.size(); m++) sums[m] = simd::dot(act.data(), out_rows[m], half);
for (m = 0; m < moves.size(); m++)
out[m] = float(sums[m]) / float(Q * Q * Q) + float(net.l1b[out_idx[m]]) / float(Q);
}
} // namespace rigby::policy
+33
View File
@@ -0,0 +1,33 @@
#pragma once
#include <string>
#include "position.h"
namespace rigby::policy {
// Policy network trained on Lc0 visit distributions (train/policy):
// 3072 threat inputs -> HIDDEN, CReLU, pairwise product (HIDDEN / 2), then one
// output row per move, i8 weights quantised by 128. HIDDEN is read from the
// file's size, so any trained width loads.
constexpr int INPUTS = 3072;
constexpr int OUTPUTS = 3920;
// Loads the network built into the binary (Makefile POLICYFILE), if there is one.
void init();
// Loads a network file, replacing the current one; an empty path goes back to
// the built-in network (or none). False, keeping the old one, if the file does
// not have the size of a network.
bool load(const std::string& path);
bool loaded();
int hidden();
// Raw logits of `moves` in `pos` (before any temperature). Requires loaded().
void logits(const Position& pos, const MoveList& moves, float* out);
// The output row of a move, as the trainer maps it (exposed for tests).
int move_index(const Position& pos, Move m);
} // namespace rigby::policy
+74 -37
View File
@@ -1,5 +1,6 @@
#include "position.h"
#include <bit>
#include <cstring>
#include <sstream>
@@ -25,18 +26,8 @@ void init() {
namespace {
// rights &= CASTLE_MASK[from] & CASTLE_MASK[to] after every move.
constexpr int castle_mask(int sq) {
switch (sq) {
case A1: return ~WHITE_OOO & 15;
case E1: return ~(WHITE_OO | WHITE_OOO) & 15;
case H1: return ~WHITE_OO & 15;
case A8: return ~BLACK_OOO & 15;
case E8: return ~(BLACK_OO | BLACK_OOO) & 15;
case H8: return ~BLACK_OO & 15;
default: return 15;
}
}
// Index into castle_rook of a right (a single CastlingRight bit).
constexpr int right_index(int right) { return std::countr_zero(unsigned(right)); }
} // namespace
@@ -93,11 +84,31 @@ bool Position::set_fen(std::string_view fen) {
stm = side == "b" ? BLACK : WHITE;
// KQkq (X-FEN: the outermost rook on that side of the king) or
// Shredder-FEN file letters (HAha) naming the castling rook.
for (char c : rights) {
if (c == 'K') castling |= WHITE_OO;
if (c == 'Q') castling |= WHITE_OOO;
if (c == 'k') castling |= BLACK_OO;
if (c == 'q') castling |= BLACK_OOO;
if (c == '-') continue;
const int color = (c >= 'a' && c <= 'z') ? BLACK : WHITE;
const char upper = char(color == BLACK ? c - 32 : c);
const int rank_base = color == WHITE ? 0 : 56;
const int kfile = file_of(king_square(color));
if (rank_of(king_square(color)) != rank_of(rank_base)) continue;
const u64 rooks = pieces_of(color, ROOK) & rank_bb(rank_base);
int rook = NO_SQUARE;
if (upper == 'K') {
for (int f = 7; f > kfile && rook == NO_SQUARE; f--)
if (rooks & bb(rank_base + f)) rook = rank_base + f;
} else if (upper == 'Q') {
for (int f = 0; f < kfile && rook == NO_SQUARE; f++)
if (rooks & bb(rank_base + f)) rook = rank_base + f;
} else if (upper >= 'A' && upper <= 'H' && (rooks & bb(rank_base + (upper - 'A')))) {
rook = rank_base + (upper - 'A');
}
if (rook == NO_SQUARE || file_of(rook) == kfile) continue;
const bool king_side = file_of(rook) > kfile;
const int right = color == WHITE ? (king_side ? WHITE_OO : WHITE_OOO) : (king_side ? BLACK_OO : BLACK_OOO);
castling |= right;
castle_rook[right_index(right)] = u8(rook);
}
if (ep_str.size() == 2 && ep_str[0] >= 'a' && ep_str[0] <= 'h') {
@@ -136,10 +147,18 @@ std::string Position::fen() const {
out += stm == WHITE ? " w " : " b ";
if (!castling) out += '-';
if (castling & WHITE_OO) out += 'K';
if (castling & WHITE_OOO) out += 'Q';
if (castling & BLACK_OO) out += 'k';
if (castling & BLACK_OOO) out += 'q';
for (int right : {WHITE_OO, WHITE_OOO, BLACK_OO, BLACK_OOO}) {
if (!(castling & right)) continue;
// K/Q when the rook is the outermost one on its side (X-FEN), else its file.
const int color = right & (WHITE_OO | WHITE_OOO) ? WHITE : BLACK;
const int rook = castle_rook[right_index(right)];
const int ksq = king_square(color);
const u64 rooks = pieces_of(color, ROOK) & rank_bb(rook);
const u64 beyond = file_of(rook) > file_of(ksq) ? rooks & ~((bb(rook) << 1) - 1) : rooks & (bb(rook) - 1);
char c = beyond ? char('A' + file_of(rook)) : (file_of(rook) > file_of(ksq) ? 'K' : 'Q');
if (color == BLACK) c = char(c + 32);
out += c;
}
out += ' ';
out += ep == NO_SQUARE ? "-" : square_name(ep);
out += ' ' + std::to_string(halfmove) + ' ' + std::to_string(fullmove);
@@ -159,14 +178,24 @@ void Position::make_move(Move m) {
ep = NO_SQUARE;
}
if (m.is_capture()) {
const int captured_sq = m.is_en_passant() ? (us == WHITE ? to - 8 : to + 8) : to;
remove_piece(captured_sq);
halfmove = 0;
if (m.is_castle()) {
// Lift both pieces first: in Chess960 the king and rook squares can overlap.
const int rook_from = castle_rook_square(m);
const int rank_base = us == WHITE ? 0 : 56;
const bool king_side = m.flag() == Move::KING_CASTLE;
remove_piece(from);
remove_piece(rook_from);
put_piece(make_piece(us, KING), to);
put_piece(make_piece(us, ROOK), rank_base + (king_side ? 5 : 3));
} else {
if (m.is_capture()) {
const int captured_sq = m.is_en_passant() ? (us == WHITE ? to - 8 : to + 8) : to;
remove_piece(captured_sq);
halfmove = 0;
}
move_piece(from, to);
}
move_piece(from, to);
if (moving == PAWN) {
halfmove = 0;
if (m.flag() == Move::DOUBLE_PUSH) {
@@ -179,17 +208,20 @@ void Position::make_move(Move m) {
remove_piece(to);
put_piece(make_piece(us, m.promo_type()), to);
}
} else if (m.is_castle()) {
const int rank_base = us == WHITE ? 0 : 56;
if (m.flag() == Move::KING_CASTLE)
move_piece(rank_base + 7, rank_base + 5);
else
move_piece(rank_base + 0, rank_base + 3);
}
key ^= zobrist::castling[castling];
castling &= castle_mask(from) & castle_mask(to);
key ^= zobrist::castling[castling];
if (castling) {
// A king move drops both of its rights; a move from or to a castling
// rook's square drops that rook's right.
int lost = moving == KING ? (us == WHITE ? WHITE_OO | WHITE_OOO : BLACK_OO | BLACK_OOO) : 0;
for (int i = 0; i < 4; i++)
if (castle_rook[i] == from || castle_rook[i] == to) lost |= 1 << i;
if (castling & lost) {
key ^= zobrist::castling[castling];
castling &= ~lost;
key ^= zobrist::castling[castling];
}
}
stm = them;
key ^= zobrist::side;
@@ -217,14 +249,19 @@ bool Position::insufficient_material() const {
return popcount(occupancy()) <= 3;
}
Move Position::parse_uci(std::string_view uci) const {
Move Position::parse_uci(std::string_view text) const {
MoveList list;
generate_legal(*this, list);
for (Move m : list)
if (m.to_uci() == uci) return m;
if (uci(m) == text) return m;
return {};
}
std::string Position::uci(Move m) const {
if (!m.is_castle() || !chess960) return m.to_uci();
return square_name(m.from()) + square_name(castle_rook_square(m));
}
std::string Position::pretty() const {
std::string out = "\n +---+---+---+---+---+---+---+---+\n";
for (int rank = 7; rank >= 0; rank--) {
+21
View File
@@ -12,6 +12,11 @@ namespace zobrist {
void init();
}
// UCI_Chess960: castling moves are written as the king taking its own rook
// (e1h1) instead of the king's destination (e1g1). Positions themselves always
// support any castling rook placement.
inline bool chess960 = false;
// Plain copy-make position. Small enough to copy at every tree step.
struct Position {
u64 pieces[6] = {};
@@ -19,6 +24,9 @@ struct Position {
u8 board[64];
int stm = WHITE;
int castling = 0;
// The rook each castling right moves, indexed by the right's bit
// (WHITE_OO, WHITE_OOO, BLACK_OO, BLACK_OOO).
u8 castle_rook[4] = {H1, A1, H8, A8};
int ep = NO_SQUARE; // only set when a capture there is pseudo-legal
int halfmove = 0;
int fullmove = 1;
@@ -44,6 +52,14 @@ struct Position {
// Returns a null move when the string is not a legal move here.
Move parse_uci(std::string_view uci) const;
// The move in UCI notation, castling written as chess960 asks. Works for
// any move of the game (the castling rooks never change), so the root
// position can print a whole PV.
std::string uci(Move m) const;
// The rook a castling move takes along; the king's rank tells the colour.
int castle_rook_square(Move m) const {
return castle_rook[(rank_of(m.from()) == 0 ? 0 : 2) + (m.flag() == Move::QUEEN_CASTLE)];
}
std::string pretty() const;
@@ -54,5 +70,10 @@ private:
};
void generate_legal(const Position& pos, MoveList& list);
// Legal captures (en passant included) and queen promotions, in the order
// generate_legal lists them.
void generate_noisy(const Position& pos, MoveList& list);
// Same as a non-empty generate_legal, but stops at the first move it finds.
bool has_legal_move(const Position& pos);
} // namespace rigby
+523
View File
@@ -0,0 +1,523 @@
#include "pretty.h"
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include "eval.h"
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <io.h>
#include <windows.h>
#else
#include <sys/ioctl.h>
#include <unistd.h>
#endif
namespace rigby::pretty {
namespace {
// ---------------------------------------------------------------------------
// Colours (24-bit ANSI)
// ---------------------------------------------------------------------------
std::string fg(int r, int g, int b) {
return "\x1b[38;2;" + std::to_string(r) + ";" + std::to_string(g) + ";" + std::to_string(b) + "m";
}
std::string bg(int r, int g, int b) {
return "\x1b[48;2;" + std::to_string(r) + ";" + std::to_string(g) + ";" + std::to_string(b) + "m";
}
const std::string RESET = "\x1b[0m";
const std::string BOLD = "\x1b[1m";
const std::string BORDER = fg(98, 104, 150);
const std::string TITLE = BOLD + fg(205, 145, 255);
const std::string LABEL = fg(125, 128, 150);
const std::string FAINT = fg(85, 88, 105);
const std::string VALUE = fg(235, 236, 245);
const std::string CYAN = fg(110, 205, 235);
const std::string BLUE = fg(125, 155, 255);
const std::string VIOLET = fg(185, 130, 255);
const std::string GREEN = fg(120, 215, 120);
const std::string BRIGHT_GREEN = fg(80, 245, 125);
const std::string YELLOW = fg(245, 200, 90);
const std::string RED = fg(235, 110, 110);
const std::string BRIGHT_RED = fg(255, 75, 85);
const std::string& score_colour(int cp) {
if (cp >= 150) return BRIGHT_GREEN;
if (cp >= 25) return GREEN;
if (cp > -25) return VALUE;
if (cp > -150) return RED;
return BRIGHT_RED;
}
// ---------------------------------------------------------------------------
// Text helpers
// ---------------------------------------------------------------------------
// Visible columns of plain UTF-8 text (every code point counts as one column).
int columns(const std::string& text) {
int n = 0;
for (unsigned char c : text)
if ((c & 0xC0) != 0x80) n++;
return n;
}
std::string repeat(const std::string& s, int n) {
std::string out;
for (int i = 0; i < n; i++) out += s;
return out;
}
std::string format(const char* fmt, double value) {
char buf[32];
std::snprintf(buf, sizeof(buf), fmt, value);
return buf;
}
// 999, 12.3k, 123k, 1.23M, 12.3M, 1.23G
std::string count(u64 n) {
if (n < 1000) return std::to_string(n);
const char* units = "kMGT";
double v = double(n);
int unit = -1;
while (v >= 1000.0 && unit < 3) {
v /= 1000.0;
unit++;
}
const std::string digits = v < 10.0 ? format("%.2f", v) : v < 100.0 ? format("%.1f", v) : format("%.0f", v);
return digits + units[unit];
}
// 0.38s, 12.4s, 2m05s
std::string duration(i64 ms) {
if (ms < 10000) return format("%.2fs", double(ms) / 1000.0);
if (ms < 60000) return format("%.1fs", double(ms) / 1000.0);
const i64 s = ms / 1000;
char buf[32];
std::snprintf(buf, sizeof(buf), "%lldm%02llds", static_cast<long long>(s / 60), static_cast<long long>(s % 60));
return buf;
}
std::string pawns(int cp) { return format("%+.2f", double(cp) / 100.0); }
// A line of coloured text that knows how many columns it takes.
struct Line {
std::string text;
int width = 0;
Line& add(const std::string& plain, const std::string& colour = "") {
text += colour.empty() ? plain : colour + plain + RESET;
width += columns(plain);
return *this;
}
Line& pad_to(int target) {
if (width < target) add(std::string(size_t(target - width), ' '));
return *this;
}
Line& append(const Line& other) {
text += other.text;
width += other.width;
return *this;
}
};
std::string pad_left(const std::string& plain, int width) {
const int n = columns(plain);
return n >= width ? plain : std::string(size_t(width - n), ' ') + plain;
}
std::string pad_right(const std::string& plain, int width) {
const int n = columns(plain);
return n >= width ? plain : plain + std::string(size_t(width - n), ' ');
}
// A smooth bar: `fraction` of `width` cells filled in `fill`, the rest in `track`
// (both foreground colours); the cell at the edge uses eighth blocks.
Line bar(double fraction, int width, const std::string& fill, const std::string& track, const std::string& track_bg) {
static constexpr const char* EIGHTHS[] = {"", "▏", "▎", "▍", "▌", "▋", "▊", "▉"};
const int eighths = int(std::lround(std::clamp(fraction, 0.0, 1.0) * width * 8));
const int full = eighths / 8;
Line l;
if (full) l.add(repeat("█", full), fill);
int used = full;
if (eighths % 8 && used < width) {
l.text += track_bg + fill + EIGHTHS[eighths % 8] + RESET;
l.width++;
used++;
}
if (used < width) l.add(repeat("█", width - used), track);
return l;
}
// ---------------------------------------------------------------------------
// Terminal
// ---------------------------------------------------------------------------
bool stdin_is_terminal = false;
struct TermSize {
int cols = 100;
int rows = 40;
};
TermSize terminal_size() {
#ifdef _WIN32
CONSOLE_SCREEN_BUFFER_INFO info;
if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info))
return {info.srWindow.Right - info.srWindow.Left + 1, info.srWindow.Bottom - info.srWindow.Top + 1};
#else
winsize w{};
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == 0 && w.ws_col) return {int(w.ws_col), int(w.ws_row)};
#endif
return {};
}
// ---------------------------------------------------------------------------
// Box drawing
// ---------------------------------------------------------------------------
struct Box {
int width; // total columns, borders included
std::vector<std::string> lines;
int inner() const { return width - 4; }
void top(const Line& left, const Line& right) {
// ╭─ left ───── right ─╮
const int fill = width - 8 - left.width - right.width;
lines.push_back(BORDER + "╭─ " + RESET + left.text + BORDER + " " + repeat("─", std::max(fill, 1)) + " " +
RESET + right.text + BORDER + " ─╮" + RESET);
}
void section(const Line& title) {
// ├─ title ─────┤
const int fill = width - 5 - title.width;
lines.push_back(BORDER + "├─ " + RESET + title.text + BORDER + " " + repeat("─", std::max(fill, 0)) + "┤" +
RESET);
}
void row(Line content) {
content.pad_to(inner());
lines.push_back(BORDER + "│ " + RESET + content.text + BORDER + " │" + RESET);
}
void bottom() { lines.push_back(BORDER + "╰" + repeat("─", width - 2) + "╯" + RESET); }
};
// ---------------------------------------------------------------------------
// Statistics, nine lines
// ---------------------------------------------------------------------------
constexpr int LABEL_WIDTH = 10;
Line label(const std::string& text) {
Line l;
l.add(pad_right(text, LABEL_WIDTH), LABEL);
return l;
}
std::vector<Line> stats(const Dashboard& d, int width) {
std::vector<Line> out;
// Score, and white's expected score as a bar.
Line score = label("score");
score.add(pawns(d.cp), BOLD + score_colour(d.cp));
score.add(d.root.stm == WHITE ? " white to move" : " black to move", FAINT);
out.push_back(score);
const double q = eval::cp_to_q(d.cp);
const double white = d.root.stm == WHITE ? (q + 1.0) / 2.0 : (1.0 - q) / 2.0;
Line eval_bar = label("white");
const int bar_width = std::clamp(width - LABEL_WIDTH - 5, 4, 48);
eval_bar.append(bar(white, bar_width, fg(240, 240, 245), fg(55, 55, 68), bg(55, 55, 68)));
eval_bar.add(pad_left(format("%.0f%%", white * 100.0), 5), VALUE);
out.push_back(eval_bar);
out.push_back(Line{});
Line depth = label("depth");
depth.add(std::to_string(d.depth), VALUE).add(" avg ", FAINT).add(std::to_string(d.seldepth), VALUE).add(" max", FAINT);
out.push_back(depth);
Line playouts = label("playouts");
playouts.add(pad_right(count(d.playouts), 8), CYAN).add("speed ", LABEL).add(count(d.nps), BLUE).add("/s", FAINT);
out.push_back(playouts);
Line time = label("time");
time.add(duration(d.ms), VALUE);
double progress = -1.0;
if (d.time_limit_ms) {
time.add(" / " + duration(d.time_limit_ms), FAINT);
progress = double(d.ms) / double(d.time_limit_ms);
} else if (d.node_limit) {
time.add(" " + count(d.playouts) + "/" + count(d.node_limit), FAINT);
progress = double(d.playouts) / double(d.node_limit);
} else {
time.add(d.done ? " stopped" : " infinite", FAINT);
}
out.push_back(time);
Line progress_bar = label("");
if (progress >= 0.0)
progress_bar.append(bar(d.done ? 1.0 : progress, bar_width + 5, CYAN, fg(45, 50, 66), bg(45, 50, 66)));
out.push_back(progress_bar);
// Tree memory: one square per tenth.
Line tree = label("tree");
const int filled = std::clamp((d.hashfull + 50) / 100, 0, 10);
const std::string& colour = d.hashfull < 500 ? GREEN : d.hashfull < 900 ? YELLOW : RED;
tree.add(repeat("■", filled), colour).add(repeat("■", 10 - filled), fg(55, 58, 72));
tree.add(pad_left(std::to_string((d.hashfull + 5) / 10) + "%", 5), VALUE);
out.push_back(tree);
Line notes = label("");
std::string text;
if (d.reused) text += "reused " + count(d.reused);
if (d.collections) text += std::string(text.empty() ? "" : " · ") + "collected " + std::to_string(d.collections) + "×";
notes.add(text, FAINT);
out.push_back(notes);
return out;
}
// ---------------------------------------------------------------------------
// Principal variation in SAN, wrapped
// ---------------------------------------------------------------------------
std::vector<Line> pv_lines(const Dashboard& d, int width, int max_lines) {
struct Token {
std::string text;
std::string colour;
};
std::vector<Token> tokens;
Position pos = d.root;
for (size_t i = 0; i < d.pv.size(); i++) {
if (pos.stm == WHITE) tokens.push_back({std::to_string(pos.fullmove) + ".", FAINT});
else if (i == 0) tokens.push_back({std::to_string(pos.fullmove) + "...", FAINT});
const std::string colour = i == 0 ? BOLD + fg(255, 255, 255) : i < 5 ? VALUE : i < 10 ? LABEL : FAINT;
tokens.push_back({san(pos, d.pv[i]), colour});
pos.make_move(d.pv[i]);
}
std::vector<Line> lines(1);
for (const Token& t : tokens) {
const int need = (lines.back().width ? 1 : 0) + columns(t.text);
if (lines.back().width + need > width) {
if (int(lines.size()) == max_lines) {
lines.back().add(" …", FAINT);
break;
}
lines.emplace_back();
}
if (lines.back().width) lines.back().add(" ");
lines.back().add(t.text, t.colour);
}
if (d.pv.empty()) lines.back().add("…", FAINT);
return lines;
}
// ---------------------------------------------------------------------------
// Root moves table
// ---------------------------------------------------------------------------
void root_moves(Box& box, const Dashboard& d, size_t rows) {
std::vector<RootMove> moves = d.moves;
std::stable_sort(moves.begin(), moves.end(), [](const RootMove& a, const RootMove& b) { return a.visits > b.visits; });
u64 total = 0;
for (const RootMove& m : moves) total += m.visits;
const int bar_width = std::max(box.inner() - 8 - 8 - 2 - 7 - 8 - 8, 6);
Line header;
header.add(pad_right("move", 8) + pad_left("visits", 8) + " " + pad_right("share", bar_width) + pad_left("%", 7) +
pad_left("score", 8) + pad_left("prior", 8),
FAINT);
box.row(header);
for (size_t i = 0; i < std::min(rows, moves.size()); i++) {
const RootMove& m = moves[i];
const double share = total ? double(m.visits) / double(total) : 0.0;
Line l;
l.add(pad_right(san(d.root, m.move), 8), i == 0 ? BOLD + fg(255, 255, 255) : VALUE);
l.add(pad_left(count(m.visits), 8), CYAN).add(" ");
l.append(bar(share, bar_width, i == 0 ? VIOLET : BLUE, fg(40, 44, 58), bg(40, 44, 58)));
l.add(pad_left(format("%.1f%%", share * 100.0), 7), VALUE);
if (m.visits) l.add(pad_left(pawns(m.cp), 8), score_colour(m.cp));
else l.add(pad_left("-", 8), FAINT);
l.add(pad_left(format("%.1f%%", double(m.prior) * 100.0), 8), LABEL);
box.row(l);
}
}
std::vector<std::string> render(const Dashboard& d, int frame) {
static constexpr const char* SPINNER[] = {"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"};
const TermSize term = terminal_size();
Box box{std::clamp(term.cols - 1, 52, 104), {}};
const int inner = box.inner();
// Fit the height: fewer root moves first, then no blank lines.
const int pv_max = 2;
const int available = term.rows - 1;
int fixed = 1 + 1 + 9 + 1 + 1 + pv_max + 1 + 1 + 1;
bool blanks = true;
int rows = std::clamp(available - fixed, 0, 8);
if (rows < 3) {
blanks = false;
fixed -= 2;
rows = std::clamp(available - fixed, 0, 8);
}
const bool show_moves = rows >= 1;
Line title;
title.add("Rigby", TITLE);
Line status;
if (d.done) status.add("✓ done", BOLD + BRIGHT_GREEN);
else status.add(std::string(SPINNER[frame % 10]) + " searching", YELLOW);
box.top(title, status);
if (blanks) box.row(Line{});
for (const Line& l : stats(d, inner)) box.row(l);
if (blanks) box.row(Line{});
Line pv_title;
pv_title.add("principal variation", LABEL);
box.section(pv_title);
for (const Line& l : pv_lines(d, inner, pv_max)) box.row(l);
if (show_moves) {
Line moves_title;
moves_title.add("root moves", LABEL).add(" · " + std::to_string(d.moves.size()) + " legal", FAINT);
box.section(moves_title);
root_moves(box, d, size_t(rows));
}
box.bottom();
return box.lines;
}
} // namespace
// ---------------------------------------------------------------------------
// Public interface
// ---------------------------------------------------------------------------
bool init_terminal() {
if (std::getenv("NO_COLOR")) return false;
// RIGBY_PRETTY forces the dashboard even into a pipe, e.g. for `less -R`.
const bool forced = std::getenv("RIGBY_PRETTY") != nullptr;
#ifdef _WIN32
if (!forced && !_isatty(_fileno(stdout))) return false;
const HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD mode = 0;
const bool vt = GetConsoleMode(out, &mode) && SetConsoleMode(out, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
if (!forced && !vt) return false;
SetConsoleOutputCP(CP_UTF8);
stdin_is_terminal = _isatty(_fileno(stdin));
return true;
#else
if (!forced && !isatty(STDOUT_FILENO)) return false;
stdin_is_terminal = isatty(STDIN_FILENO);
return true;
#endif
}
std::atomic<int>& typed_lines() {
static std::atomic<int> lines{0};
return lines;
}
std::string banner(const std::string& name, const std::string& version, const std::string& author) {
Box box{58, {}};
Line title;
title.add(name, TITLE).add(" " + version, VALUE);
Line right;
right.add("MCGS chess engine", LABEL);
box.top(title, right);
box.row(Line{});
Line by;
by.add("by ", FAINT).add(author, VALUE);
box.row(by);
Line help;
help.add("try ", FAINT).add("go movetime 5000", CYAN).add(" or ", FAINT).add("go infinite", CYAN).add(" + ", FAINT)
.add("stop", CYAN);
box.row(help);
Line uci;
uci.add("type ", FAINT).add("uci", CYAN).add(" for plain UCI output", FAINT);
box.row(uci);
box.bottom();
std::string out = "\n";
for (const std::string& l : box.lines) out += " " + l + "\n";
return out;
}
std::string LiveView::draw(const Dashboard& d) {
const std::vector<std::string> lines = render(d, frame_++);
std::string out;
if (lines_) {
// Back to the first line of the previous dashboard (and over any line
// the user typed below it), then clear everything from there down.
const int typed = stdin_is_terminal ? typed_lines().exchange(0) : 0;
out += "\x1b[" + std::to_string(lines_ + typed) + "F\x1b[J";
}
for (size_t i = 0; i < lines.size(); i++) out += (i ? "\n" : "") + lines[i];
lines_ = int(lines.size());
return out;
}
std::string note(const std::string& text) { return " " + LABEL + text + RESET; }
std::string bestmove(const Position& root, Move move) {
return " " + LABEL + "bestmove " + RESET + BOLD + BRIGHT_GREEN + san(root, move) + RESET + FAINT + " (" +
root.uci(move) + ")" + RESET + "\n";
}
std::string san(const Position& pos, Move m) {
if (!m) return "--";
std::string s;
if (m.is_castle()) {
s = m.flag() == Move::KING_CASTLE ? "O-O" : "O-O-O";
} else {
const int type = piece_type(pos.piece_on(m.from()));
if (type == PAWN) {
if (m.is_capture()) s += char('a' + file_of(m.from()));
} else {
s += "PNBRQK"[type];
// Disambiguate between pieces of the same type that reach the same square.
MoveList legal;
generate_legal(pos, legal);
bool clash = false, same_file = false, same_rank = false;
for (Move o : legal) {
if (o == m || o.to() != m.to() || o.from() == m.from()) continue;
if (piece_type(pos.piece_on(o.from())) != type) continue;
clash = true;
same_file |= file_of(o.from()) == file_of(m.from());
same_rank |= rank_of(o.from()) == rank_of(m.from());
}
if (clash) {
if (!same_file) s += char('a' + file_of(m.from()));
else if (!same_rank) s += char('1' + rank_of(m.from()));
else s += square_name(m.from());
}
}
if (m.is_capture()) s += 'x';
s += square_name(m.to());
if (m.is_promotion()) s += std::string("=") + "NBRQ"[m.promo_type() - KNIGHT];
}
Position next = pos;
next.make_move(m);
if (next.in_check()) {
MoveList replies;
generate_legal(next, replies);
s += replies.empty() ? '#' : '+';
}
return s;
}
} // namespace rigby::pretty
+76
View File
@@ -0,0 +1,76 @@
#pragma once
#include <atomic>
#include <string>
#include <vector>
#include "position.h"
#include "types.h"
namespace rigby::pretty {
// Human-readable search display for a terminal: a framed dashboard with the
// board, the score, search statistics, the principal variation and the root
// moves, redrawn in place while the search runs. The engine uses it until the
// first "uci" command; GUIs and match runners always send "uci" (and read
// stdout through a pipe), so they only ever see plain UCI.
// True when stdout is a terminal (and NO_COLOR is not set). Turns on ANSI
// colours and UTF-8 output on the Windows console.
bool init_terminal();
std::string banner(const std::string& name, const std::string& version, const std::string& author);
// Lines the user typed (and the terminal echoed) since the dashboard was last
// drawn; each one pushed the cursor a line further down.
std::atomic<int>& typed_lines();
struct RootMove {
Move move;
u32 visits = 0;
int cp = 0; // from Q, side to move's view
float prior = 0.0f;
};
// One snapshot of a running search.
struct Dashboard {
Position root;
int depth = 0;
int seldepth = 0;
u64 playouts = 0;
u64 nps = 0;
i64 ms = 0;
i64 time_limit_ms = 0; // 0: no time limit
u64 node_limit = 0; // 0: no playout limit
int hashfull = 0; // per mille
int cp = 0; // side to move's view
std::vector<Move> pv;
std::vector<RootMove> moves;
u64 reused = 0;
int collections = 0;
bool done = false;
};
// Draws dashboards in place: each call returns the text that replaces the
// previous dashboard of the same search.
class LiveView {
public:
void begin() {
lines_ = 0;
frame_ = 0;
typed_lines() = 0;
}
std::string draw(const Dashboard& d);
private:
int lines_ = 0;
int frame_ = 0;
};
std::string note(const std::string& text);
std::string bestmove(const Position& root, Move move);
// Standard algebraic notation of a legal move, with + and #.
std::string san(const Position& pos, Move m);
} // namespace rigby::pretty
+248
View File
@@ -0,0 +1,248 @@
#pragma once
// Hand-written vector kernels for the networks, one set per instruction set,
// picked at compile time (the Makefile builds with -march=native;
// -DRIGBY_NO_SIMD forces the scalar fallback). Every op is
// exact integer arithmetic, so all paths give the same results as the scalar
// fallback, and the bench does not depend on the machine.
#include <cstdint>
#include "types.h"
#if defined(RIGBY_NO_SIMD)
#define RIGBY_SIMD_SCALAR
#elif defined(__AVX512F__) && defined(__AVX512BW__)
#define RIGBY_SIMD_AVX512
#include <immintrin.h>
#elif defined(__AVX2__)
#define RIGBY_SIMD_AVX2
#include <immintrin.h>
#elif defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64)
#define RIGBY_SIMD_SSE2
#include <immintrin.h>
#elif defined(__ARM_NEON) && defined(__aarch64__)
#define RIGBY_SIMD_NEON
#include <arm_neon.h>
#else
#define RIGBY_SIMD_SCALAR
#endif
namespace rigby::simd {
using i32 = std::int32_t;
// vi16: LANES 16-bit lanes. vi32: 32-bit sums of the same register width.
// ACC_REGS: registers a kernel may keep accumulating in without spilling.
#if defined(RIGBY_SIMD_AVX512)
using vi16 = __m512i;
using vi32 = __m512i;
constexpr int LANES = 32;
constexpr int ACC_REGS = 16;
constexpr const char* NAME = "avx512";
inline vi16 load(const i16* p) { return _mm512_loadu_si512(p); }
inline vi16 load(const i8* p) { return _mm512_cvtepi8_epi16(_mm256_loadu_si256(reinterpret_cast<const __m256i*>(p))); }
inline void store(i16* p, vi16 v) { _mm512_storeu_si512(p, v); }
inline vi16 set1(i16 x) { return _mm512_set1_epi16(x); }
inline vi16 add(vi16 a, vi16 b) { return _mm512_add_epi16(a, b); }
inline vi16 sub(vi16 a, vi16 b) { return _mm512_sub_epi16(a, b); }
inline vi16 min(vi16 a, vi16 b) { return _mm512_min_epi16(a, b); }
inline vi16 max(vi16 a, vi16 b) { return _mm512_max_epi16(a, b); }
inline vi16 mullo(vi16 a, vi16 b) { return _mm512_mullo_epi16(a, b); }
inline vi32 zero32() { return _mm512_setzero_si512(); }
inline vi32 add32(vi32 a, vi32 b) { return _mm512_add_epi32(a, b); }
// acc + a[2i] * b[2i] + a[2i+1] * b[2i+1] in each 32-bit lane.
inline vi32 dot(vi32 acc, vi16 a, vi16 b) {
#if defined(__AVX512VNNI__)
return _mm512_dpwssd_epi32(acc, a, b);
#else
return _mm512_add_epi32(acc, _mm512_madd_epi16(a, b));
#endif
}
inline i32 reduce(vi32 v) { return _mm512_reduce_add_epi32(v); }
#elif defined(RIGBY_SIMD_AVX2)
using vi16 = __m256i;
using vi32 = __m256i;
constexpr int LANES = 16;
constexpr int ACC_REGS = 8;
constexpr const char* NAME = "avx2";
inline vi16 load(const i16* p) { return _mm256_loadu_si256(reinterpret_cast<const __m256i*>(p)); }
inline vi16 load(const i8* p) { return _mm256_cvtepi8_epi16(_mm_loadu_si128(reinterpret_cast<const __m128i*>(p))); }
inline void store(i16* p, vi16 v) { _mm256_storeu_si256(reinterpret_cast<__m256i*>(p), v); }
inline vi16 set1(i16 x) { return _mm256_set1_epi16(x); }
inline vi16 add(vi16 a, vi16 b) { return _mm256_add_epi16(a, b); }
inline vi16 sub(vi16 a, vi16 b) { return _mm256_sub_epi16(a, b); }
inline vi16 min(vi16 a, vi16 b) { return _mm256_min_epi16(a, b); }
inline vi16 max(vi16 a, vi16 b) { return _mm256_max_epi16(a, b); }
inline vi16 mullo(vi16 a, vi16 b) { return _mm256_mullo_epi16(a, b); }
inline vi32 zero32() { return _mm256_setzero_si256(); }
inline vi32 add32(vi32 a, vi32 b) { return _mm256_add_epi32(a, b); }
inline vi32 dot(vi32 acc, vi16 a, vi16 b) {
#if defined(__AVXVNNI__)
return _mm256_dpwssd_avx_epi32(acc, a, b);
#else
return _mm256_add_epi32(acc, _mm256_madd_epi16(a, b));
#endif
}
inline i32 reduce(vi32 v) {
__m128i x = _mm_add_epi32(_mm256_castsi256_si128(v), _mm256_extracti128_si256(v, 1));
x = _mm_add_epi32(x, _mm_shuffle_epi32(x, _MM_SHUFFLE(1, 0, 3, 2)));
x = _mm_add_epi32(x, _mm_shuffle_epi32(x, _MM_SHUFFLE(2, 3, 0, 1)));
return _mm_cvtsi128_si32(x);
}
#elif defined(RIGBY_SIMD_SSE2)
using vi16 = __m128i;
using vi32 = __m128i;
constexpr int LANES = 8;
constexpr int ACC_REGS = 8;
constexpr const char* NAME = "sse2";
inline vi16 load(const i16* p) { return _mm_loadu_si128(reinterpret_cast<const __m128i*>(p)); }
inline vi16 load(const i8* p) {
const __m128i x = _mm_loadl_epi64(reinterpret_cast<const __m128i*>(p));
#if defined(__SSE4_1__)
return _mm_cvtepi8_epi16(x);
#else
return _mm_srai_epi16(_mm_unpacklo_epi8(x, x), 8);
#endif
}
inline void store(i16* p, vi16 v) { _mm_storeu_si128(reinterpret_cast<__m128i*>(p), v); }
inline vi16 set1(i16 x) { return _mm_set1_epi16(x); }
inline vi16 add(vi16 a, vi16 b) { return _mm_add_epi16(a, b); }
inline vi16 sub(vi16 a, vi16 b) { return _mm_sub_epi16(a, b); }
inline vi16 min(vi16 a, vi16 b) { return _mm_min_epi16(a, b); }
inline vi16 max(vi16 a, vi16 b) { return _mm_max_epi16(a, b); }
inline vi16 mullo(vi16 a, vi16 b) { return _mm_mullo_epi16(a, b); }
inline vi32 zero32() { return _mm_setzero_si128(); }
inline vi32 add32(vi32 a, vi32 b) { return _mm_add_epi32(a, b); }
inline vi32 dot(vi32 acc, vi16 a, vi16 b) { return _mm_add_epi32(acc, _mm_madd_epi16(a, b)); }
inline i32 reduce(vi32 x) {
x = _mm_add_epi32(x, _mm_shuffle_epi32(x, _MM_SHUFFLE(1, 0, 3, 2)));
x = _mm_add_epi32(x, _mm_shuffle_epi32(x, _MM_SHUFFLE(2, 3, 0, 1)));
return _mm_cvtsi128_si32(x);
}
#elif defined(RIGBY_SIMD_NEON)
using vi16 = int16x8_t;
using vi32 = int32x4_t;
constexpr int LANES = 8;
constexpr int ACC_REGS = 16;
constexpr const char* NAME = "neon";
inline vi16 load(const i16* p) { return vld1q_s16(p); }
inline vi16 load(const i8* p) { return vmovl_s8(vld1_s8(p)); }
inline void store(i16* p, vi16 v) { vst1q_s16(p, v); }
inline vi16 set1(i16 x) { return vdupq_n_s16(x); }
inline vi16 add(vi16 a, vi16 b) { return vaddq_s16(a, b); }
inline vi16 sub(vi16 a, vi16 b) { return vsubq_s16(a, b); }
inline vi16 min(vi16 a, vi16 b) { return vminq_s16(a, b); }
inline vi16 max(vi16 a, vi16 b) { return vmaxq_s16(a, b); }
inline vi16 mullo(vi16 a, vi16 b) { return vmulq_s16(a, b); }
inline vi32 zero32() { return vdupq_n_s32(0); }
inline vi32 add32(vi32 a, vi32 b) { return vaddq_s32(a, b); }
// Pairs lanes differently from x86's madd, but every caller only needs the total.
inline vi32 dot(vi32 acc, vi16 a, vi16 b) {
acc = vmlal_s16(acc, vget_low_s16(a), vget_low_s16(b));
return vmlal_high_s16(acc, a, b);
}
inline i32 reduce(vi32 v) { return vaddvq_s32(v); }
#else
// One lane: the generic kernels below become the plain scalar loops.
using vi16 = i16;
using vi32 = i32;
constexpr int LANES = 1;
constexpr int ACC_REGS = 8;
constexpr const char* NAME = "scalar";
inline vi16 load(const i16* p) { return *p; }
inline vi16 load(const i8* p) { return *p; }
inline void store(i16* p, vi16 v) { *p = v; }
inline vi16 set1(i16 x) { return x; }
inline vi16 add(vi16 a, vi16 b) { return i16(a + b); }
inline vi16 sub(vi16 a, vi16 b) { return i16(a - b); }
inline vi16 min(vi16 a, vi16 b) { return a < b ? a : b; }
inline vi16 max(vi16 a, vi16 b) { return a > b ? a : b; }
inline vi16 mullo(vi16 a, vi16 b) { return i16(a * b); }
inline vi32 zero32() { return 0; }
inline vi32 add32(vi32 a, vi32 b) { return a + b; }
inline vi32 dot(vi32 acc, vi16 a, vi16 b) { return acc + i32(a) * i32(b); }
inline i32 reduce(vi32 v) { return v; }
#endif
inline vi16 clamp(vi16 x, vi16 lo, vi16 hi) { return min(max(x, lo), hi); }
namespace detail {
// R registers wide: dst = base + rows[0] + ... + rows[count - 1], from `offset`.
template <int R, typename B, typename W>
inline void accumulate_tile(i16* dst, const B* base, const W* const* rows, int count, int offset) {
vi16 r[R];
for (int k = 0; k < R; k++) r[k] = load(base + offset + k * LANES);
for (int f = 0; f < count; f++) {
const W* w = rows[f] + offset;
for (int k = 0; k < R; k++) r[k] = add(r[k], load(w + k * LANES));
}
for (int k = 0; k < R; k++) store(dst + offset + k * LANES, r[k]);
}
} // namespace detail
// dst[i] = base[i] + sum of rows[f][i] for i < n, wrapping in 16 bits like the
// scalar sum in any order. Rows are summed in registers one tile at a time,
// so dst is written once instead of once per row.
template <int TILE_REGS = ACC_REGS, typename B, typename W>
inline void accumulate(i16* dst, const B* base, const W* const* rows, int count, int n) {
constexpr int TILE = TILE_REGS * LANES;
int i = 0;
for (; i + TILE <= n; i += TILE) detail::accumulate_tile<TILE_REGS>(dst, base, rows, count, i);
for (; i + LANES <= n; i += LANES) detail::accumulate_tile<1>(dst, base, rows, count, i);
for (; i < n; i++) {
i16 v = i16(base[i]);
for (int f = 0; f < count; f++) v = i16(v + rows[f][i]);
dst[i] = v;
}
}
// Sum of a[i] * b[i] for i < n, in 32 bits (the caller makes sure it fits).
template <typename W>
inline i32 dot(const i16* a, const W* b, int n) {
vi32 s0 = zero32(), s1 = zero32();
int i = 0;
for (; i + 2 * LANES <= n; i += 2 * LANES) {
s0 = dot(s0, load(a + i), load(b + i));
s1 = dot(s1, load(a + i + LANES), load(b + i + LANES));
}
for (; i + LANES <= n; i += LANES) s0 = dot(s0, load(a + i), load(b + i));
i32 sum = reduce(add32(s0, s1));
for (; i < n; i++) sum += i32(a[i]) * i32(b[i]);
return sum;
}
// dot(a, b[k], n) for four rows at once, sharing the loads of `a`.
template <typename W>
inline void dot4(const i16* a, const W* const* b, int n, i32* out) {
vi32 s[4] = {zero32(), zero32(), zero32(), zero32()};
int i = 0;
for (; i + LANES <= n; i += LANES) {
const vi16 x = load(a + i);
for (int k = 0; k < 4; k++) s[k] = dot(s[k], x, load(b[k] + i));
}
for (int k = 0; k < 4; k++) {
out[k] = reduce(s[k]);
for (int j = i; j < n; j++) out[k] += i32(a[j]) * i32(b[k][j]);
}
}
} // namespace rigby::simd
+2
View File
@@ -11,6 +11,8 @@ using u32 = std::uint32_t;
using u16 = std::uint16_t;
using u8 = std::uint8_t;
using i64 = std::int64_t;
using i8 = std::int8_t;
using i16 = std::int16_t;
constexpr std::string_view START_FEN = "rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1";
+97 -2
View File
@@ -1,6 +1,7 @@
#include "uci.h"
#include <algorithm>
#include <cstdio>
#include <chrono>
#include <iostream>
#include <memory>
@@ -10,9 +11,11 @@
#include <vector>
#include "eval.h"
#include "mcts.h"
#include "mcgs.h"
#include "perft.h"
#include "policy.h"
#include "position.h"
#include "pretty.h"
#include "uci_io.h"
namespace rigby {
@@ -51,8 +54,12 @@ void print_id() {
send("option name Hash type spin default " + std::to_string(DEFAULT_HASH_MB) + " min 1 max 65536");
send("option name Threads type spin default 1 min 1 max 1");
send("option name MoveOverhead type spin default 20 min 0 max 5000");
send("option name UCI_Chess960 type check default false");
// A policy network file to use instead of the built-in one (or the move heuristics).
send("option name PolicyFile type string default <empty>");
// Search constants, exposed as integers (x100) so SPSA can tune them.
send("option name CPuct type spin default 160 min 1 max 1000");
send("option name RootCPuct type spin default 233 min 1 max 1000");
send("option name FPUReduction type spin default 30 min 0 max 200");
send("option name PolicyTemp type spin default 100 min 10 max 500");
send("uciok");
@@ -67,6 +74,17 @@ void set_option(Engine& e, std::istringstream& is) {
std::string lname = name;
std::transform(lname.begin(), lname.end(), lname.begin(), [](unsigned char c) { return char(std::tolower(c)); });
if (lname == "uci_chess960") {
chess960 = value == "true";
return;
}
if (lname == "policyfile") {
if (!policy::load(value)) send("info string cannot load policy network " + value);
else if (policy::loaded()) send("info string policy network " + std::to_string(policy::hidden()) + " hidden");
else send("info string no policy network, using move heuristics");
return;
}
int v = 0;
try {
v = std::stoi(value);
@@ -83,6 +101,8 @@ void set_option(Engine& e, std::istringstream& is) {
e.searcher.params.move_overhead = std::clamp(v, 0, 5000);
else if (lname == "cpuct")
e.searcher.params.cpuct = float(v) / 100.0f;
else if (lname == "rootcpuct")
e.searcher.params.root_cpuct = float(v) / 100.0f;
else if (lname == "fpureduction")
e.searcher.params.fpu_reduction = float(v) / 100.0f;
else if (lname == "policytemp")
@@ -143,7 +163,7 @@ void go(Engine& e, std::istringstream& is) {
e.searcher.stop_flag = false;
e.worker = std::thread([&e, pos = e.pos, history = e.history, limits] {
const SearchResult result = e.searcher.search(pos, history, limits, true);
send("bestmove " + result.best.to_uci());
send(e.searcher.pretty ? pretty::bestmove(pos, result.best) : "bestmove " + pos.uci(result.best));
});
}
@@ -197,13 +217,23 @@ void uci_loop() {
auto engine = std::make_unique<Engine>();
Engine& e = *engine;
// A human at a terminal gets coloured search output until "uci" arrives.
e.searcher.pretty = pretty::init_terminal();
if (e.searcher.pretty) send(pretty::banner(ENGINE_NAME, ENGINE_VERSION, ENGINE_AUTHOR));
std::string line;
while (std::getline(std::cin, line)) {
// The terminal echoed the line under a live dashboard; it redraws over it.
if (e.searcher.pretty) pretty::typed_lines()++;
std::istringstream is(line);
std::string cmd;
is >> cmd;
if (cmd == "uci") {
if (e.searcher.pretty) {
e.stop();
e.searcher.pretty = false;
}
print_id();
} else if (cmd == "isready") {
send("readyok");
@@ -229,6 +259,59 @@ void uci_loop() {
} else if (cmd == "eval") {
send("static " + std::to_string(eval::static_eval(e.pos)) + " cp, qsearch " +
std::to_string(eval::quiescence(e.pos, -30000, 30000, 0)) + " cp (side to move)");
} else if (cmd == "evalfens") {
// Same positions as the trainer's --check, to compare inference
static constexpr const char* FENS[] = {
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b KQkq - 0 1",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R b KQkq - 0 1",
"6k1/5pp1/1p2p2p/1Pq1Pn2/2P2P2/6P1/4Q1BP/6K1 w - - 1 30",
"8/8/3k4/2p1p3/2P1P3/3K4/8/8 w - - 0 1",
"4k3/8/8/8/8/8/8/R3K3 w - - 0 1",
"4k3/8/8/8/8/8/8/R3K3 b - - 0 1",
};
for (const char* fen : FENS) {
Position pos;
pos.set_fen(fen);
char line[160];
std::snprintf(line, sizeof(line), "%6d cp %s", eval::static_eval(pos), fen);
send(line);
}
} else if (cmd == "policyfens") {
// Same positions as the policy trainer's --check, to compare inference
static constexpr const char* FENS[] = {
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R b KQkq - 0 1",
"6k1/5pp1/1p2p2p/1Pq1Pn2/2P2P2/6P1/4Q1BP/6K1 w - - 1 30",
"8/2P2k2/8/8/8/8/5K2/8 w - - 0 1",
};
if (!policy::loaded()) {
send("info string no policy network loaded");
continue;
}
for (const char* fen : FENS) {
Position pos;
pos.set_fen(fen);
MoveList moves;
generate_legal(pos, moves);
float priors[256];
eval::policy(pos, moves, 1.0f, nullptr, priors);
std::vector<std::pair<float, std::string>> lines;
for (int i = 0; i < moves.size(); i++) lines.push_back({priors[i], pos.uci(moves[i])});
std::sort(lines.begin(), lines.end(), [](const auto& a, const auto& b) {
return a.first != b.first ? a.first > b.first : a.second < b.second;
});
send("");
send(fen);
for (const auto& [p, uci] : lines) {
char line[64];
std::snprintf(line, sizeof(line), " %-6s %6.2f%%", uci.c_str(), p * 100.0f);
send(line);
}
}
} else if (cmd == "perft") {
int depth = 5;
is >> depth;
@@ -239,11 +322,23 @@ void uci_loop() {
is >> depth;
e.stop();
perft_suite(depth);
} else if (cmd == "perftfile") {
// perftfile <epd> [max depth]: lines of "<fen> ;D1 <nodes> ;D2 <nodes> ..."
std::string path;
int depth = 6;
is >> path >> depth;
e.stop();
perft_file(path, depth);
} else if (cmd == "bench") {
int playouts = DEFAULT_BENCH_PLAYOUTS;
is >> playouts;
e.stop();
run_bench(playouts);
#ifdef RIGBY_VERIFY_TREE
} else if (cmd == "verify") {
e.stop();
e.searcher.self_test();
#endif
} else if (!cmd.empty()) {
send("info string unknown command: " + cmd);
}
+960
View File
@@ -0,0 +1,960 @@
bqnb1rkr/pp3ppp/3ppn2/2p5/5P2/P2P4/NPP1P1PP/BQ1BNRKR w HFhf - 2 9 ;D1 21 ;D2 528 ;D3 12189 ;D4 326672 ;D5 8146062 ;D6 227689589
2nnrbkr/p1qppppp/8/1ppb4/6PP/3PP3/PPP2P2/BQNNRBKR w HEhe - 1 9 ;D1 21 ;D2 807 ;D3 18002 ;D4 667366 ;D5 16253601 ;D6 590751109
b1q1rrkb/pppppppp/3nn3/8/P7/1PPP4/4PPPP/BQNNRKRB w GE - 1 9 ;D1 20 ;D2 479 ;D3 10471 ;D4 273318 ;D5 6417013 ;D6 177654692
qbbnnrkr/2pp2pp/p7/1p2pp2/8/P3PP2/1PPP1KPP/QBBNNR1R w hf - 0 9 ;D1 22 ;D2 593 ;D3 13440 ;D4 382958 ;D5 9183776 ;D6 274103539
1nbbnrkr/p1p1ppp1/3p4/1p3P1p/3Pq2P/8/PPP1P1P1/QNBBNRKR w HFhf - 0 9 ;D1 28 ;D2 1120 ;D3 31058 ;D4 1171749 ;D5 34030312 ;D6 1250970898
qnbnr1kr/ppp1b1pp/4p3/3p1p2/8/2NPP3/PPP1BPPP/QNB1R1KR w HEhe - 1 9 ;D1 29 ;D2 899 ;D3 26578 ;D4 824055 ;D5 24851983 ;D6 775718317
q1bnrkr1/ppppp2p/2n2p2/4b1p1/2NP4/8/PPP1PPPP/QNB1RRKB w ge - 1 9 ;D1 30 ;D2 860 ;D3 24566 ;D4 732757 ;D5 21093346 ;D6 649209803
qbn1brkr/ppp1p1p1/2n4p/3p1p2/P7/6PP/QPPPPP2/1BNNBRKR w HFhf - 0 9 ;D1 25 ;D2 635 ;D3 17054 ;D4 465806 ;D5 13203304 ;D6 377184252
qnnbbrkr/1p2ppp1/2pp3p/p7/1P5P/2NP4/P1P1PPP1/Q1NBBRKR w HFhf - 0 9 ;D1 24 ;D2 572 ;D3 15243 ;D4 384260 ;D5 11110203 ;D6 293989890
qn1rbbkr/ppp2p1p/1n1pp1p1/8/3P4/P6P/1PP1PPPK/QNNRBB1R w hd - 2 9 ;D1 28 ;D2 811 ;D3 23175 ;D4 679699 ;D5 19836606 ;D6 594527992
qnr1bkrb/pppp2pp/3np3/5p2/8/P2P2P1/NPP1PP1P/QN1RBKRB w GDg - 3 9 ;D1 33 ;D2 823 ;D3 26895 ;D4 713420 ;D5 23114629 ;D6 646390782
qb1nrkbr/1pppp1p1/1n3p2/p1B4p/8/3P1P1P/PPP1P1P1/QBNNRK1R w HEhe - 0 9 ;D1 31 ;D2 855 ;D3 25620 ;D4 735703 ;D5 21796206 ;D6 651054626
qnnbrk1r/1p1ppbpp/2p5/p4p2/2NP3P/8/PPP1PPP1/Q1NBRKBR w HEhe - 0 9 ;D1 26 ;D2 790 ;D3 21238 ;D4 642367 ;D5 17819770 ;D6 544866674
1qnrkbbr/1pppppp1/p1n4p/8/P7/1P1N1P2/2PPP1PP/QN1RKBBR w HDhd - 0 9 ;D1 37 ;D2 883 ;D3 32187 ;D4 815535 ;D5 29370838 ;D6 783201510
qn1rkrbb/pp1p1ppp/2p1p3/3n4/4P2P/2NP4/PPP2PP1/Q1NRKRBB w FDfd - 1 9 ;D1 24 ;D2 585 ;D3 14769 ;D4 356950 ;D5 9482310 ;D6 233468620
bb1qnrkr/pp1p1pp1/1np1p3/4N2p/8/1P4P1/P1PPPP1P/BBNQ1RKR w HFhf - 0 9 ;D1 29 ;D2 864 ;D3 25747 ;D4 799727 ;D5 24219627 ;D6 776836316
bnqbnr1r/p1p1ppkp/3p4/1p4p1/P7/3NP2P/1PPP1PP1/BNQB1RKR w HF - 0 9 ;D1 26 ;D2 889 ;D3 24353 ;D4 832956 ;D5 23701014 ;D6 809194268
bnqnrbkr/1pp2pp1/p7/3pP2p/4P1P1/8/PPPP3P/BNQNRBKR w HEhe d6 0 9 ;D1 31 ;D2 984 ;D3 28677 ;D4 962591 ;D5 29032175 ;D6 1008880643
b1qnrrkb/ppp1pp1p/n2p1Pp1/8/8/P7/1PPPP1PP/BNQNRKRB w GE - 0 9 ;D1 20 ;D2 484 ;D3 10532 ;D4 281606 ;D5 6718715 ;D6 193594729
n1bqnrkr/pp1ppp1p/2p5/6p1/2P2b2/PN6/1PNPPPPP/1BBQ1RKR w HFhf - 2 9 ;D1 23 ;D2 732 ;D3 17746 ;D4 558191 ;D5 14481581 ;D6 457140569
n1bb1rkr/qpnppppp/2p5/p7/P1P5/5P2/1P1PPRPP/NQBBN1KR w Hhf - 1 9 ;D1 27 ;D2 697 ;D3 18724 ;D4 505089 ;D5 14226907 ;D6 400942568
nqb1rbkr/pppppp1p/4n3/6p1/4P3/1NP4P/PP1P1PP1/1QBNRBKR w HEhe - 1 9 ;D1 28 ;D2 641 ;D3 18811 ;D4 456916 ;D5 13780398 ;D6 354122358
n1bnrrkb/pp1pp2p/2p2p2/6p1/5B2/3P4/PPP1PPPP/NQ1NRKRB w GE - 2 9 ;D1 28 ;D2 606 ;D3 16883 ;D4 381646 ;D5 10815324 ;D6 254026570
nbqnbrkr/2ppp1p1/pp3p1p/8/4N2P/1N6/PPPPPPP1/1BQ1BRKR w HFhf - 0 9 ;D1 26 ;D2 626 ;D3 17268 ;D4 437525 ;D5 12719546 ;D6 339132046
nq1bbrkr/pp2nppp/2pp4/4p3/1PP1P3/1B6/P2P1PPP/NQN1BRKR w HFhf - 2 9 ;D1 21 ;D2 504 ;D3 11812 ;D4 302230 ;D5 7697880 ;D6 207028745
nqnrb1kr/2pp1ppp/1p1bp3/p1B5/5P2/3N4/PPPPP1PP/NQ1R1BKR w HDhd - 0 9 ;D1 30 ;D2 672 ;D3 19307 ;D4 465317 ;D5 13454573 ;D6 345445468
nqn2krb/p1prpppp/1pbp4/7P/5P2/8/PPPPPKP1/NQNRB1RB w g - 3 9 ;D1 21 ;D2 461 ;D3 10608 ;D4 248069 ;D5 6194124 ;D6 152861936
nb1n1kbr/ppp1rppp/3pq3/P3p3/8/4P3/1PPPRPPP/NBQN1KBR w Hh - 1 9 ;D1 19 ;D2 566 ;D3 11786 ;D4 358337 ;D5 8047916 ;D6 249171636
nqnbrkbr/1ppppp1p/p7/6p1/6P1/P6P/1PPPPP2/NQNBRKBR w HEhe - 1 9 ;D1 20 ;D2 382 ;D3 8694 ;D4 187263 ;D5 4708975 ;D6 112278808
nq1rkb1r/pp1pp1pp/1n2bp1B/2p5/8/5P1P/PPPPP1P1/NQNRKB1R w HDhd - 2 9 ;D1 24 ;D2 809 ;D3 20090 ;D4 673811 ;D5 17647882 ;D6 593457788
nqnrkrb1/pppppp2/7p/4b1p1/8/PN1NP3/1PPP1PPP/1Q1RKRBB w FDfd - 1 9 ;D1 26 ;D2 683 ;D3 18102 ;D4 473911 ;D5 13055173 ;D6 352398011
bb1nqrkr/1pp1ppp1/pn5p/3p4/8/P2NNP2/1PPPP1PP/BB2QRKR w HFhf - 0 9 ;D1 29 ;D2 695 ;D3 21193 ;D4 552634 ;D5 17454857 ;D6 483785639
bnn1qrkr/pp1ppp1p/2p5/b3Q1p1/8/5P1P/PPPPP1P1/BNNB1RKR w HFhf - 2 9 ;D1 44 ;D2 920 ;D3 35830 ;D4 795317 ;D5 29742670 ;D6 702867204
bnnqrbkr/pp1p2p1/2p1p2p/5p2/1P5P/1R6/P1PPPPP1/BNNQRBK1 w Ehe - 0 9 ;D1 33 ;D2 1022 ;D3 32724 ;D4 1024721 ;D5 32898113 ;D6 1047360456
b1nqrkrb/2pppppp/p7/1P6/1n6/P4P2/1P1PP1PP/BNNQRKRB w GEge - 0 9 ;D1 23 ;D2 638 ;D3 15744 ;D4 446539 ;D5 11735969 ;D6 344211589
n1bnqrkr/3ppppp/1p6/pNp1b3/2P3P1/8/PP1PPP1P/NBB1QRKR w HFhf - 1 9 ;D1 29 ;D2 728 ;D3 20768 ;D4 532084 ;D5 15621236 ;D6 415766465
n2bqrkr/p1p1pppp/1pn5/3p1b2/P6P/1NP5/1P1PPPP1/1NBBQRKR w HFhf - 3 9 ;D1 20 ;D2 533 ;D3 12152 ;D4 325059 ;D5 8088751 ;D6 223068417
nnbqrbkr/1pp1p1p1/p2p4/5p1p/2P1P3/N7/PPQP1PPP/N1B1RBKR w HEhe - 0 9 ;D1 27 ;D2 619 ;D3 18098 ;D4 444421 ;D5 13755384 ;D6 357222394
nnbqrkr1/pp1pp2p/2p2b2/5pp1/1P5P/4P1P1/P1PP1P2/NNBQRKRB w GEge - 1 9 ;D1 32 ;D2 1046 ;D3 33721 ;D4 1111186 ;D5 36218182 ;D6 1202830851
nb1qbrkr/p1pppp2/1p1n2pp/8/1P6/2PN3P/P2PPPP1/NB1QBRKR w HFhf - 0 9 ;D1 25 ;D2 521 ;D3 14021 ;D4 306427 ;D5 8697700 ;D6 201455191
nnq1brkr/pp1pppp1/8/2p4P/8/5K2/PPPbPP1P/NNQBBR1R w hf - 0 9 ;D1 23 ;D2 724 ;D3 18263 ;D4 571072 ;D5 15338230 ;D6 484638597
nnqrbb1r/pppppk2/5pp1/7p/1P6/3P2PP/P1P1PP2/NNQRBBKR w HD - 0 9 ;D1 30 ;D2 717 ;D3 21945 ;D4 547145 ;D5 17166700 ;D6 450069742
nnqr1krb/p1p1pppp/2bp4/8/1p1P4/4P3/PPP2PPP/NNQRBKRB w GDgd - 0 9 ;D1 25 ;D2 873 ;D3 20796 ;D4 728628 ;D5 18162741 ;D6 641708630
nbnqrkbr/p2ppp2/1p4p1/2p4p/3P3P/3N4/PPP1PPPR/NB1QRKB1 w Ehe - 0 9 ;D1 24 ;D2 589 ;D3 15190 ;D4 382317 ;D5 10630667 ;D6 279474189
n1qbrkbr/p1ppp2p/2n2pp1/1p6/1P6/2P3P1/P2PPP1P/NNQBRKBR w HEhe - 0 9 ;D1 22 ;D2 592 ;D3 14269 ;D4 401976 ;D5 10356818 ;D6 301583306
2qrkbbr/ppn1pppp/n1p5/3p4/5P2/P1PP4/1P2P1PP/NNQRKBBR w HDhd - 1 9 ;D1 27 ;D2 750 ;D3 20584 ;D4 605458 ;D5 16819085 ;D6 516796736
1nqr1rbb/pppkp1pp/1n3p2/3p4/1P6/5P1P/P1PPPKP1/NNQR1RBB w - - 1 9 ;D1 24 ;D2 623 ;D3 15921 ;D4 429446 ;D5 11594634 ;D6 322745925
bbn1rqkr/pp1pp2p/4npp1/2p5/1P6/2BPP3/P1P2PPP/1BNNRQKR w HEhe - 0 9 ;D1 23 ;D2 730 ;D3 17743 ;D4 565340 ;D5 14496370 ;D6 468608864
bn1brqkr/pppp2p1/3npp2/7p/PPP5/8/3PPPPP/BNNBRQKR w HEhe - 0 9 ;D1 25 ;D2 673 ;D3 17835 ;D4 513696 ;D5 14284338 ;D6 434008567
bn1rqbkr/ppp1ppp1/1n6/2p4p/7P/3P4/PPP1PPP1/BN1RQBKR w HDhd - 0 9 ;D1 25 ;D2 776 ;D3 20562 ;D4 660217 ;D5 18486027 ;D6 616653869
bnnr1krb/ppp2ppp/3p4/3Bp3/q1P3PP/8/PP1PPP2/BNNRQKR1 w GDgd - 0 9 ;D1 29 ;D2 1040 ;D3 30772 ;D4 1053113 ;D5 31801525 ;D6 1075147725
1bbnrqkr/pp1ppppp/8/2p5/n7/3PNPP1/PPP1P2P/NBB1RQKR w HEhe - 1 9 ;D1 24 ;D2 598 ;D3 15673 ;D4 409766 ;D5 11394778 ;D6 310589129
nnbbrqkr/p2ppp1p/1pp5/8/6p1/N1P5/PPBPPPPP/N1B1RQKR w HEhe - 0 9 ;D1 26 ;D2 530 ;D3 14031 ;D4 326312 ;D5 8846766 ;D6 229270702
nnbrqbkr/2p1p1pp/p4p2/1p1p4/8/NP6/P1PPPPPP/N1BRQBKR w HDhd - 0 9 ;D1 17 ;D2 496 ;D3 10220 ;D4 303310 ;D5 7103549 ;D6 217108001
nnbrqk1b/pp2pprp/2pp2p1/8/3PP1P1/8/PPP2P1P/NNBRQRKB w d - 1 9 ;D1 33 ;D2 820 ;D3 27856 ;D4 706784 ;D5 24714401 ;D6 645835197
1bnrbqkr/ppnpp1p1/2p2p1p/8/1P6/4PPP1/P1PP3P/NBNRBQKR w HDhd - 0 9 ;D1 27 ;D2 705 ;D3 19760 ;D4 548680 ;D5 15964771 ;D6 464662032
n1rbbqkr/pp1pppp1/7p/P1p5/1n6/2PP4/1P2PPPP/NNRBBQKR w HChc - 0 9 ;D1 22 ;D2 631 ;D3 14978 ;D4 431801 ;D5 10911545 ;D6 320838556
n1rqb1kr/p1pppp1p/1pn4b/3P2p1/P7/1P6/2P1PPPP/NNRQBBKR w HChc - 0 9 ;D1 24 ;D2 477 ;D3 12506 ;D4 263189 ;D5 7419372 ;D6 165945904
nnrqbkrb/pppp1pp1/7p/4p3/6P1/2N2B2/PPPPPP1P/NR1QBKR1 w Ggc - 2 9 ;D1 29 ;D2 658 ;D3 19364 ;D4 476620 ;D5 14233587 ;D6 373744834
n1nrqkbr/ppb2ppp/3pp3/2p5/2P3P1/5P2/PP1PPB1P/NBNRQK1R w HDhd - 1 9 ;D1 32 ;D2 801 ;D3 25861 ;D4 681428 ;D5 22318948 ;D6 619857455
2rbqkbr/p1pppppp/1nn5/1p6/7P/P4P2/1PPPP1PB/NNRBQK1R w HChc - 2 9 ;D1 27 ;D2 647 ;D3 18030 ;D4 458057 ;D5 13189156 ;D6 354689323
nn1qkbbr/pp2ppp1/2rp4/2p4p/P2P4/1N5P/1PP1PPP1/1NRQKBBR w HCh - 1 9 ;D1 24 ;D2 738 ;D3 18916 ;D4 586009 ;D5 16420659 ;D6 519075930
nnrqk1bb/p1ppp2p/5rp1/1p3p2/1P4P1/5P1P/P1PPP3/NNRQKRBB w FCc - 1 9 ;D1 25 ;D2 795 ;D3 20510 ;D4 648945 ;D5 17342527 ;D6 556144017
bb1nrkqr/ppppn2p/4ppp1/8/1P4P1/4P3/P1PPKP1P/BBNNR1QR w he - 0 9 ;D1 29 ;D2 664 ;D3 20024 ;D4 498376 ;D5 15373803 ;D6 406016364
bnnbrkqr/1p1ppp2/8/p1p3pp/1P6/N4P2/PBPPP1PP/2NBRKQR w HEhe - 0 9 ;D1 31 ;D2 770 ;D3 24850 ;D4 677212 ;D5 22562080 ;D6 662029574
1nnrkbqr/p1pp1ppp/4p3/1p6/1Pb1P3/6PB/P1PP1P1P/BNNRK1QR w HDhd - 0 9 ;D1 27 ;D2 776 ;D3 22133 ;D4 641002 ;D5 19153245 ;D6 562738257
bnr1kqrb/pppp1pp1/1n5p/4p3/P3P3/3P2P1/1PP2P1P/BNNRKQRB w GDg - 0 9 ;D1 26 ;D2 624 ;D3 16411 ;D4 435426 ;D5 11906515 ;D6 338092952
nbbnrkqr/p1ppp1pp/1p3p2/8/2P5/4P3/PP1P1PPP/NBBNRKQR w HEhe - 1 9 ;D1 25 ;D2 624 ;D3 15561 ;D4 419635 ;D5 10817378 ;D6 311138112
nn1brkqr/pp1bpppp/8/2pp4/P4P2/1PN5/2PPP1PP/N1BBRKQR w HEhe - 1 9 ;D1 23 ;D2 659 ;D3 16958 ;D4 476567 ;D5 13242252 ;D6 373557073
n1brkbqr/ppp1pp1p/6pB/3p4/2Pn4/8/PP2PPPP/NN1RKBQR w HDhd - 0 9 ;D1 32 ;D2 1026 ;D3 30360 ;D4 978278 ;D5 29436320 ;D6 957904151
nnbrkqrb/p2ppp2/Q5pp/1pp5/4PP2/2N5/PPPP2PP/N1BRK1RB w GDgd - 0 9 ;D1 36 ;D2 843 ;D3 29017 ;D4 715537 ;D5 24321197 ;D6 630396940
nbnrbk1r/pppppppq/8/7p/8/1N2QPP1/PPPPP2P/NB1RBK1R w HDhd - 2 9 ;D1 36 ;D2 973 ;D3 35403 ;D4 1018054 ;D5 37143354 ;D6 1124883780
nnrbbkqr/2pppp1p/p7/6p1/1p2P3/4QPP1/PPPP3P/NNRBBK1R w HChc - 0 9 ;D1 36 ;D2 649 ;D3 22524 ;D4 489526 ;D5 16836636 ;D6 416139320
nnrkbbqr/1p2pppp/p2p4/2p5/8/1N2P1P1/PPPP1P1P/1NKRBBQR w hc - 0 9 ;D1 26 ;D2 672 ;D3 18136 ;D4 477801 ;D5 13342771 ;D6 363074681
n1rkbqrb/pp1ppp2/2n3p1/2p4p/P5PP/1P6/2PPPP2/NNRKBQRB w GCgc - 0 9 ;D1 24 ;D2 804 ;D3 20712 ;D4 684001 ;D5 18761475 ;D6 617932151
nbkr1qbr/1pp1pppp/pn1p4/8/3P2P1/5R2/PPP1PP1P/NBN1KQBR w H - 2 9 ;D1 30 ;D2 627 ;D3 18669 ;D4 423329 ;D5 12815016 ;D6 312798696
nnr1kqbr/pp1pp1p1/2p5/b4p1p/P7/1PNP4/2P1PPPP/N1RBKQBR w HChc - 1 9 ;D1 12 ;D2 421 ;D3 6530 ;D4 227044 ;D5 4266410 ;D6 149176979
n1rkqbbr/p1pp1pp1/np2p2p/8/8/N4PP1/PPPPP1BP/N1RKQ1BR w HChc - 0 9 ;D1 27 ;D2 670 ;D3 19119 ;D4 494690 ;D5 14708490 ;D6 397268628
nnr1qrbb/p2kpppp/1p1p4/2p5/6P1/PP1P4/2P1PP1P/NNRKQRBB w FC - 0 9 ;D1 27 ;D2 604 ;D3 17043 ;D4 409665 ;D5 11993332 ;D6 308518181
bbnnrkrq/ppp1pp2/6p1/3p4/7p/7P/PPPPPPP1/BBNNRRKQ w ge - 0 9 ;D1 20 ;D2 559 ;D3 12242 ;D4 355326 ;D5 8427161 ;D6 252274233
bnnbrkr1/ppp2p1p/5q2/3pp1p1/4P3/1N4P1/PPPPRP1P/BN1B1KRQ w Gge - 0 9 ;D1 26 ;D2 1036 ;D3 27228 ;D4 1028084 ;D5 28286576 ;D6 1042120495
bn1rkbrq/1pppppp1/p6p/1n6/3P4/6PP/PPPRPP2/BNN1KBRQ w Ggd - 2 9 ;D1 29 ;D2 633 ;D3 19278 ;D4 455476 ;D5 14333034 ;D6 361900466
b1nrkrqb/1p1npppp/p2p4/2p5/5P2/4P2P/PPPP1RP1/BNNRK1QB w Dfd - 1 9 ;D1 25 ;D2 475 ;D3 12603 ;D4 270909 ;D5 7545536 ;D6 179579818
1bbnrkrq/ppppppp1/8/7p/1n4P1/1PN5/P1PPPP1P/NBBR1KRQ w Gge - 0 9 ;D1 30 ;D2 803 ;D3 25473 ;D4 709716 ;D5 23443854 ;D6 686365049
nnbbrkrq/2pp1pp1/1p5p/pP2p3/7P/N7/P1PPPPP1/N1BBRKRQ w GEge - 0 9 ;D1 18 ;D2 432 ;D3 9638 ;D4 242350 ;D5 6131124 ;D6 160393505
nnbrkbrq/1pppp1p1/p7/7p/1P2Pp2/BN6/P1PP1PPP/1N1RKBRQ w GDgd - 0 9 ;D1 27 ;D2 482 ;D3 13441 ;D4 282259 ;D5 8084701 ;D6 193484216
n1brkrqb/pppp3p/n3pp2/6p1/3P1P2/N1P5/PP2P1PP/N1BRKRQB w FDfd - 0 9 ;D1 28 ;D2 642 ;D3 19005 ;D4 471729 ;D5 14529434 ;D6 384837696
nbnrbk2/p1pppp1p/1p3qr1/6p1/1B1P4/1N6/PPP1PPPP/1BNR1RKQ w d - 2 9 ;D1 30 ;D2 796 ;D3 22780 ;D4 687302 ;D5 20120565 ;D6 641832725
nnrbbrkq/1pp2ppp/3p4/p3p3/3P1P2/1P2P3/P1P3PP/NNRBBKRQ w GC - 1 9 ;D1 31 ;D2 827 ;D3 24538 ;D4 663082 ;D5 19979594 ;D6 549437308
nnrkbbrq/1pp2p1p/p2pp1p1/2P5/8/8/PP1PPPPP/NNRKBBRQ w Ggc - 0 9 ;D1 24 ;D2 762 ;D3 19283 ;D4 624598 ;D5 16838099 ;D6 555230555
nnr1brqb/1ppkp1pp/8/p2p1p2/1P1P4/N1P5/P3PPPP/N1RKBRQB w FC - 1 9 ;D1 23 ;D2 640 ;D3 15471 ;D4 444905 ;D5 11343507 ;D6 334123513
nbnrkrbq/2ppp2p/p4p2/1P4p1/4PP2/8/1PPP2PP/NBNRKRBQ w FDfd - 0 9 ;D1 31 ;D2 826 ;D3 26137 ;D4 732175 ;D5 23555139 ;D6 686250413
1nrbkr1q/1pppp1pp/1n6/p4p2/N1b4P/8/PPPPPPPB/N1RBKR1Q w FCfc - 2 9 ;D1 27 ;D2 862 ;D3 24141 ;D4 755171 ;D5 22027695 ;D6 696353497
nnrkrbbq/pppp2pp/8/4pp2/4P3/P7/1PPPBPPP/NNKRR1BQ w c - 0 9 ;D1 25 ;D2 792 ;D3 19883 ;D4 636041 ;D5 16473376 ;D6 532214177
n1rk1qbb/pppprpp1/2n4p/4p3/2PP3P/8/PP2PPP1/NNRKRQBB w ECc - 1 9 ;D1 25 ;D2 622 ;D3 16031 ;D4 425247 ;D5 11420973 ;D6 321855685
bbq1rnkr/pnp1pp1p/1p1p4/6p1/2P5/2Q1P2P/PP1P1PP1/BB1NRNKR w HEhe - 2 9 ;D1 36 ;D2 870 ;D3 30516 ;D4 811047 ;D5 28127620 ;D6 799738334
bq1brnkr/1p1ppp1p/1np5/p5p1/8/1N5P/PPPPPPP1/BQ1BRNKR w HEhe - 0 9 ;D1 22 ;D2 588 ;D3 13524 ;D4 380068 ;D5 9359618 ;D6 273795898
bq1rn1kr/1pppppbp/Nn4p1/8/8/P7/1PPPPPPP/BQ1RNBKR w HDhd - 1 9 ;D1 24 ;D2 711 ;D3 18197 ;D4 542570 ;D5 14692779 ;D6 445827351
bqnr1kr1/pppppp1p/6p1/5n2/4B3/3N2PP/PbPPPP2/BQNR1KR1 w GDgd - 2 9 ;D1 31 ;D2 1132 ;D3 36559 ;D4 1261476 ;D5 43256823 ;D6 1456721391
qbb1rnkr/ppp3pp/4n3/3ppp2/1P3PP1/8/P1PPPN1P/QBB1RNKR w HEhe - 0 9 ;D1 28 ;D2 696 ;D3 20502 ;D4 541886 ;D5 16492398 ;D6 456983120
qnbbr1kr/pp1ppp1p/4n3/6p1/2p3P1/2PP1P2/PP2P2P/QNBBRNKR w HEhe - 0 9 ;D1 25 ;D2 655 ;D3 16520 ;D4 450189 ;D5 11767038 ;D6 335414976
1nbrnbkr/p1ppp1pp/1p6/5p2/4q1PP/3P4/PPP1PP2/QNBRNBKR w HDhd - 1 9 ;D1 30 ;D2 1162 ;D3 33199 ;D4 1217278 ;D5 36048727 ;D6 1290346802
q1brnkrb/p1pppppp/n7/1p6/P7/3P1P2/QPP1P1PP/1NBRNKRB w GDgd - 0 9 ;D1 32 ;D2 827 ;D3 26106 ;D4 718243 ;D5 23143989 ;D6 673147648
qbnrb1kr/ppp1pp1p/3p4/2n3p1/1P6/6N1/P1PPPPPP/QBNRB1KR w HDhd - 2 9 ;D1 29 ;D2 751 ;D3 23132 ;D4 610397 ;D5 19555214 ;D6 530475036
q1rbbnkr/pppp1p2/2n3pp/2P1p3/3P4/8/PP1NPPPP/Q1RBBNKR w HChc - 2 9 ;D1 29 ;D2 806 ;D3 24540 ;D4 687251 ;D5 21694330 ;D6 619907316
q1r1bbkr/pnpp1ppp/2n1p3/1p6/2P2P2/2N1N3/PP1PP1PP/Q1R1BBKR w HChc - 2 9 ;D1 32 ;D2 1017 ;D3 32098 ;D4 986028 ;D5 31204371 ;D6 958455898
2rnbkrb/pqppppp1/1pn5/7p/2P5/P1R5/QP1PPPPP/1N1NBKRB w Ggc - 4 9 ;D1 26 ;D2 625 ;D3 16506 ;D4 434635 ;D5 11856964 ;D6 336672890
qbnr1kbr/p2ppppp/2p5/1p6/4n2P/P4N2/1PPP1PP1/QBNR1KBR w HDhd - 0 9 ;D1 27 ;D2 885 ;D3 23828 ;D4 767273 ;D5 21855658 ;D6 706272554
qnrbnk1r/pp1pp2p/5p2/2pbP1p1/3P4/1P6/P1P2PPP/QNRBNKBR w HChc - 0 9 ;D1 26 ;D2 954 ;D3 24832 ;D4 892456 ;D5 24415089 ;D6 866744329
qnrnk1br/p1p2ppp/8/1pbpp3/8/PP2N3/1QPPPPPP/1NR1KBBR w HChc - 0 9 ;D1 26 ;D2 783 ;D3 20828 ;D4 634267 ;D5 17477825 ;D6 539674275
qnrnkrbb/Bpppp2p/6p1/5p2/5P2/3PP3/PPP3PP/QNRNKR1B w FCfc - 1 9 ;D1 28 ;D2 908 ;D3 25730 ;D4 861240 ;D5 25251641 ;D6 869525254
bbnqrn1r/ppppp2k/5p2/6pp/7P/1QP5/PP1PPPP1/B1N1RNKR w HE - 0 9 ;D1 33 ;D2 643 ;D3 21790 ;D4 487109 ;D5 16693640 ;D6 410115900
b1qbrnkr/ppp1pp2/2np4/6pp/4P3/2N4P/PPPP1PP1/BQ1BRNKR w HEhe - 0 9 ;D1 28 ;D2 837 ;D3 24253 ;D4 745617 ;D5 22197063 ;D6 696399065
bnqr1bkr/pp1ppppp/2p5/4N3/5P2/P7/1PPPPnPP/BNQR1BKR w HDhd - 3 9 ;D1 25 ;D2 579 ;D3 13909 ;D4 341444 ;D5 8601011 ;D6 225530258
b1qr1krb/pp1ppppp/n2n4/8/2p5/2P3P1/PP1PPP1P/BNQRNKRB w GDgd - 0 9 ;D1 28 ;D2 707 ;D3 19721 ;D4 549506 ;D5 15583376 ;D6 468399900
nbbqr1kr/1pppp1pp/8/p1n2p2/4P3/PN6/1PPPQPPP/1BB1RNKR w HEhe - 0 9 ;D1 30 ;D2 745 ;D3 23416 ;D4 597858 ;D5 19478789 ;D6 515473678
nqbbrn1r/p1pppp1k/1p4p1/7p/4P3/1R3B2/PPPP1PPP/NQB2NKR w H - 0 9 ;D1 24 ;D2 504 ;D3 13512 ;D4 317355 ;D5 9002073 ;D6 228726497
nqbr1bkr/p1p1ppp1/1p1n4/3pN2p/1P6/8/P1PPPPPP/NQBR1BKR w HDhd - 0 9 ;D1 29 ;D2 898 ;D3 26532 ;D4 809605 ;D5 24703467 ;D6 757166494
nqbrn1rb/pppp1kp1/5p1p/4p3/P4B2/3P2P1/1PP1PP1P/NQ1RNKRB w GD - 0 9 ;D1 34 ;D2 671 ;D3 22332 ;D4 473110 ;D5 15556806 ;D6 353235120
nb1r1nkr/ppp1ppp1/2bp4/7p/3P2qP/P6R/1PP1PPP1/NBQRBNK1 w Dhd - 1 9 ;D1 38 ;D2 1691 ;D3 60060 ;D4 2526992 ;D5 88557078 ;D6 3589649998
n1rbbnkr/1p1pp1pp/p7/2p1qp2/1B3P2/3P4/PPP1P1PP/NQRB1NKR w HChc - 0 9 ;D1 24 ;D2 913 ;D3 21595 ;D4 807544 ;D5 19866918 ;D6 737239330
nqrnbbkr/p2p1p1p/1pp5/1B2p1p1/1P3P2/4P3/P1PP2PP/NQRNB1KR w HChc - 0 9 ;D1 33 ;D2 913 ;D3 30159 ;D4 843874 ;D5 28053260 ;D6 804687975
nqr1bkrb/ppp1pp2/2np2p1/P6p/8/2P4P/1P1PPPP1/NQRNBKRB w GCgc - 0 9 ;D1 24 ;D2 623 ;D3 16569 ;D4 442531 ;D5 12681936 ;D6 351623879
nb1rnkbr/pqppppp1/1p5p/8/1PP4P/8/P2PPPP1/NBQRNKBR w HDhd - 1 9 ;D1 31 ;D2 798 ;D3 24862 ;D4 694386 ;D5 22616076 ;D6 666227466
nqrbnkbr/2p1p1pp/3p4/pp3p2/6PP/3P1N2/PPP1PP2/NQRB1KBR w HChc - 0 9 ;D1 24 ;D2 590 ;D3 14409 ;D4 383690 ;D5 9698432 ;D6 274064911
nqrnkbbr/pp1p1p1p/4p1p1/1p6/8/5P1P/P1PPP1P1/NQRNKBBR w HChc - 0 9 ;D1 30 ;D2 1032 ;D3 31481 ;D4 1098116 ;D5 34914919 ;D6 1233362066
nqrnkrbb/p2ppppp/1p6/2p5/2P3P1/5P2/PP1PPN1P/NQR1KRBB w FCfc - 1 9 ;D1 30 ;D2 775 ;D3 23958 ;D4 668000 ;D5 21141738 ;D6 621142773
bbnrqrk1/pp2pppp/4n3/2pp4/P7/1N5P/BPPPPPP1/B2RQNKR w HD - 2 9 ;D1 23 ;D2 708 ;D3 17164 ;D4 554089 ;D5 14343443 ;D6 481405144
bnr1qnkr/p1pp1p1p/1p4p1/4p1b1/2P1P3/1P6/PB1P1PPP/1NRBQNKR w HChc - 1 9 ;D1 30 ;D2 931 ;D3 29249 ;D4 921746 ;D5 30026687 ;D6 968109774
b1rqnbkr/ppp1ppp1/3p3p/2n5/P3P3/2NP4/1PP2PPP/B1RQNBKR w HChc - 0 9 ;D1 24 ;D2 596 ;D3 15533 ;D4 396123 ;D5 11099382 ;D6 294180723
bnrqnr1b/pp1pkppp/2p1p3/P7/2P5/7P/1P1PPPP1/BNRQNKRB w GC - 0 9 ;D1 24 ;D2 572 ;D3 15293 ;D4 390903 ;D5 11208688 ;D6 302955778
n1brq1kr/bppppppp/p7/8/4P1Pn/8/PPPP1P2/NBBRQNKR w HDhd - 0 9 ;D1 20 ;D2 570 ;D3 13139 ;D4 371247 ;D5 9919113 ;D6 284592289
1rbbqnkr/ppn1ppp1/3p3p/2p5/3P4/1N4P1/PPPBPP1P/1R1BQNKR w HBhb - 0 9 ;D1 29 ;D2 1009 ;D3 29547 ;D4 1040816 ;D5 31059587 ;D6 1111986835
nrbq2kr/ppppppb1/5n1p/5Pp1/8/P5P1/1PPPP2P/NRBQNBKR w HBhb - 1 9 ;D1 20 ;D2 520 ;D3 11745 ;D4 316332 ;D5 7809837 ;D6 216997152
nrb1nkrb/pp3ppp/1qBpp3/2p5/8/P5P1/1PPPPP1P/NRBQNKR1 w GBgb - 2 9 ;D1 32 ;D2 850 ;D3 25642 ;D4 734088 ;D5 21981567 ;D6 664886187
1br1bnkr/ppqppp1p/1np3p1/8/1PP4P/4N3/P2PPPP1/NBRQB1KR w HChc - 1 9 ;D1 32 ;D2 798 ;D3 24765 ;D4 691488 ;D5 22076141 ;D6 670296871
nrqbb1kr/1p1pp1pp/2p3n1/p4p2/3PP3/P5N1/1PP2PPP/NRQBB1KR w HBhb - 0 9 ;D1 32 ;D2 791 ;D3 26213 ;D4 684890 ;D5 23239122 ;D6 634260266
nrqn1bkr/ppppp1pp/4b3/8/4P1p1/5P2/PPPP3P/NRQNBBKR w HBhb - 0 9 ;D1 29 ;D2 687 ;D3 20223 ;D4 506088 ;D5 15236287 ;D6 398759980
nrqnbrkb/pppp1p2/4p2p/3B2p1/8/1P4P1/PQPPPP1P/NR1NBKR1 w GB - 0 9 ;D1 37 ;D2 764 ;D3 27073 ;D4 610950 ;D5 21284835 ;D6 514864869
nbrq1kbr/Bp3ppp/2pnp3/3p4/5P2/2P4P/PP1PP1P1/NBRQNK1R w HChc - 0 9 ;D1 40 ;D2 1271 ;D3 48022 ;D4 1547741 ;D5 56588117 ;D6 1850696281
nrqbnkbr/1p2ppp1/p1p4p/3p4/1P6/8/PQPPPPPP/1RNBNKBR w HBhb - 0 9 ;D1 28 ;D2 757 ;D3 23135 ;D4 668025 ;D5 21427496 ;D6 650939962
nrqn1bbr/2ppkppp/4p3/pB6/8/2P1P3/PP1P1PPP/NRQNK1BR w HB - 1 9 ;D1 27 ;D2 642 ;D3 17096 ;D4 442653 ;D5 11872805 ;D6 327545120
nrqnkrb1/p1ppp2p/1p4p1/4bp2/4PP1P/4N3/PPPP2P1/NRQ1KRBB w FBfb - 1 9 ;D1 27 ;D2 958 ;D3 27397 ;D4 960350 ;D5 28520172 ;D6 995356563
1bnrnqkr/pbpp2pp/8/1p2pp2/P6P/3P1N2/1PP1PPP1/BBNR1QKR w HDhd - 0 9 ;D1 27 ;D2 859 ;D3 23475 ;D4 773232 ;D5 21581178 ;D6 732696327
b1rbnqkr/1pp1ppp1/2n4p/p2p4/5P2/1PBP4/P1P1P1PP/1NRBNQKR w HChc - 0 9 ;D1 26 ;D2 545 ;D3 14817 ;D4 336470 ;D5 9537260 ;D6 233549184
1nrnqbkr/p1pppppp/1p6/8/2b2P2/P1N5/1PP1P1PP/BNR1QBKR w HChc - 2 9 ;D1 24 ;D2 668 ;D3 17716 ;D4 494866 ;D5 14216070 ;D6 406225409
1nrnqkrb/2ppp1pp/p7/1p3p2/5P2/N5K1/PPPPP2P/B1RNQ1RB w gc - 0 9 ;D1 33 ;D2 725 ;D3 23572 ;D4 559823 ;D5 18547476 ;D6 471443091
nbbr1qkr/p1pppppp/8/1p1n4/3P4/1N3PP1/PPP1P2P/1BBRNQKR w HDhd - 1 9 ;D1 28 ;D2 698 ;D3 20527 ;D4 539625 ;D5 16555068 ;D6 458045505
1rbbnqkr/1pnppp1p/p5p1/2p5/2P4P/5P2/PP1PP1PR/NRBBNQK1 w Bhb - 1 9 ;D1 24 ;D2 554 ;D3 14221 ;D4 362516 ;D5 9863080 ;D6 269284081
nrb1qbkr/2pppppp/2n5/p7/2p5/4P3/PPNP1PPP/1RBNQBKR w HBhb - 0 9 ;D1 23 ;D2 618 ;D3 15572 ;D4 443718 ;D5 12044358 ;D6 360311412
nrb1qkrb/2ppppp1/p3n3/1p1B3p/2P5/6P1/PP1PPPRP/NRBNQK2 w Bgb - 2 9 ;D1 27 ;D2 593 ;D3 16770 ;D4 401967 ;D5 11806808 ;D6 303338935
nbrn1qkr/ppp1pp2/3p2p1/3Q3P/b7/8/PPPPPP1P/NBRNB1KR w HChc - 2 9 ;D1 39 ;D2 1056 ;D3 40157 ;D4 1133446 ;D5 42201531 ;D6 1239888683
nr1bbqkr/pp1pp2p/1n3pp1/2p5/8/1P4P1/P1PPPPQP/NRNBBK1R w hb - 0 9 ;D1 25 ;D2 585 ;D3 15719 ;D4 406544 ;D5 11582539 ;D6 320997679
nr2bbkr/ppp1pppp/1n1p4/8/6PP/1NP4q/PP1PPP2/1RNQBBKR w HBhb - 1 9 ;D1 22 ;D2 742 ;D3 15984 ;D4 545231 ;D5 13287051 ;D6 457010195
1rnqbkrb/ppp1p1p1/1n3p2/3p3p/P6P/4P3/1PPP1PP1/NRNQBRKB w gb - 0 9 ;D1 22 ;D2 574 ;D3 14044 ;D4 379648 ;D5 9968830 ;D6 281344367
nb1rqkbr/1pppp1pp/4n3/p4p2/6PP/5P2/PPPPPN2/NBR1QKBR w HCh - 0 9 ;D1 25 ;D2 621 ;D3 16789 ;D4 462600 ;D5 13378840 ;D6 396575613
nrnbqkbr/2pp2pp/4pp2/pp6/8/1P3P2/P1PPPBPP/NRNBQ1KR w hb - 0 9 ;D1 25 ;D2 656 ;D3 16951 ;D4 466493 ;D5 12525939 ;D6 358763789
nrnqkbbr/ppppp1p1/7p/5p2/8/P4PP1/NPPPP2P/NR1QKBBR w HBhb - 0 9 ;D1 28 ;D2 723 ;D3 20621 ;D4 547522 ;D5 15952533 ;D6 439046803
1rnqkr1b/ppppp2p/1n3pp1/8/2P3P1/Pb1N4/1P1PPP1P/NR1QKRBB w FBfb - 0 9 ;D1 26 ;D2 713 ;D3 19671 ;D4 548875 ;D5 15865528 ;D6 454532806
bbnrnkqr/1pppp1pp/5p2/p7/7P/1P6/PBPPPPPR/1BNRNKQ1 w D - 2 9 ;D1 26 ;D2 649 ;D3 17834 ;D4 502279 ;D5 14375839 ;D6 435585252
bnrbk1qr/1ppp1ppp/p2np3/8/P7/2N2P2/1PPPP1PP/B1RBNKQR w HC - 0 9 ;D1 26 ;D2 621 ;D3 17569 ;D4 451452 ;D5 13514201 ;D6 364421088
br1nkbqr/ppppppp1/8/n6p/8/N1P2PP1/PP1PP2P/B1RNKBQR w HCh - 1 9 ;D1 29 ;D2 664 ;D3 20182 ;D4 512316 ;D5 16125924 ;D6 442508159
bnr1kqrb/pp1pppp1/2n5/2p5/1P4Pp/4N3/P1PPPP1P/BNKR1QRB w gc - 0 9 ;D1 36 ;D2 888 ;D3 31630 ;D4 789863 ;D5 27792175 ;D6 719015345
1bbrnkqr/pp1p1ppp/2p1p3/1n6/5P2/3Q4/PPPPP1PP/NBBRNK1R w HDhd - 2 9 ;D1 36 ;D2 891 ;D3 31075 ;D4 781792 ;D5 26998966 ;D6 702903862
nrbbnk1r/pp2pppq/8/2pp3p/3P2P1/1N6/PPP1PP1P/1RBBNKQR w HBhb - 0 9 ;D1 29 ;D2 1036 ;D3 31344 ;D4 1139166 ;D5 35627310 ;D6 1310683359
nr1nkbqr/ppp3pp/5p2/3pp3/6b1/3PP3/PPP2PPP/NRBNKBQR w hb - 0 9 ;D1 18 ;D2 664 ;D3 13306 ;D4 483892 ;D5 10658989 ;D6 386307449
nrbnk1rb/ppp1pq1p/3p4/5pp1/2P1P3/1N6/PP1PKPPP/1RBN1QRB w gb - 2 9 ;D1 25 ;D2 966 ;D3 24026 ;D4 920345 ;D5 23957242 ;D6 913710194
1brnbkqr/pppppp2/6p1/7p/1Pn5/P1NP4/2P1PPPP/NBR1BKQR w HChc - 0 9 ;D1 22 ;D2 627 ;D3 13760 ;D4 395829 ;D5 9627826 ;D6 285900573
nrnbbk1r/p1pppppq/8/7p/1p6/P5PP/1PPPPPQ1/NRNBBK1R w HBhb - 2 9 ;D1 29 ;D2 888 ;D3 26742 ;D4 874270 ;D5 27229468 ;D6 930799376
n1nkb1qr/prppppbp/6p1/1p6/2P2P2/P7/1P1PP1PP/NRNKBBQR w HBh - 1 9 ;D1 29 ;D2 804 ;D3 24701 ;D4 688520 ;D5 21952444 ;D6 623156747
nr2bqrb/ppkpp1pp/1np5/5p1P/5P2/2P5/PP1PP1P1/NRNKBQRB w GB - 0 9 ;D1 22 ;D2 530 ;D3 13055 ;D4 347657 ;D5 9244693 ;D6 264088392
nbr1kqbr/p3pppp/2ppn3/1p4P1/4P3/1P6/P1PP1P1P/NBRNKQBR w HChc - 1 9 ;D1 23 ;D2 555 ;D3 14291 ;D4 350917 ;D5 9692630 ;D6 247479180
nr1bkqbr/1p1pp1pp/pnp2p2/8/6P1/P1PP4/1P2PP1P/NRNBKQBR w HBhb - 0 9 ;D1 22 ;D2 565 ;D3 13343 ;D4 365663 ;D5 9305533 ;D6 268612479
nr1kqbbr/np2pppp/p1p5/1B1p1P2/8/4P3/PPPP2PP/NRNKQ1BR w HBhb - 0 9 ;D1 32 ;D2 730 ;D3 23391 ;D4 556995 ;D5 18103280 ;D6 454569900
nrnk1rbb/p1p2ppp/3pq3/Qp2p3/1P1P4/8/P1P1PPPP/NRN1KRBB w fb - 2 9 ;D1 28 ;D2 873 ;D3 25683 ;D4 791823 ;D5 23868737 ;D6 747991356
bbnrnkrq/pp1ppp1p/6p1/2p5/6P1/P5RP/1PPPPP2/BBNRNK1Q w Dgd - 3 9 ;D1 37 ;D2 1260 ;D3 45060 ;D4 1542086 ;D5 54843403 ;D6 1898432768
bnrb1rkq/ppnpppp1/3Q4/2p4p/7P/N7/PPPPPPP1/B1RBNKR1 w GC - 2 9 ;D1 38 ;D2 878 ;D3 31944 ;D4 800440 ;D5 28784300 ;D6 784569826
bnrnkbrq/p1ppppp1/1p5p/8/P2PP3/5P2/1PP3PP/BNRNKBRQ w GCgc - 1 9 ;D1 26 ;D2 617 ;D3 16992 ;D4 419099 ;D5 11965544 ;D6 311309576
bnrnkrqb/pp2p2p/2pp1pp1/8/P7/2PP1P2/1P2P1PP/BNRNKRQB w FCfc - 0 9 ;D1 26 ;D2 721 ;D3 19726 ;D4 560824 ;D5 15966934 ;D6 467132503
nbbrnkr1/1pppp1p1/p6q/P4p1p/8/5P2/1PPPP1PP/NBBRNRKQ w gd - 2 9 ;D1 18 ;D2 556 ;D3 10484 ;D4 316634 ;D5 6629293 ;D6 202528241
nrb1nkrq/2pp1ppp/p4b2/1p2p3/P4B2/3P4/1PP1PPPP/NR1BNRKQ w gb - 0 9 ;D1 24 ;D2 562 ;D3 14017 ;D4 355433 ;D5 9227883 ;D6 247634489
nrbnkbrq/p3p1pp/1p6/2pp1P2/8/3PP3/PPP2P1P/NRBNKBRQ w GBgb - 0 9 ;D1 31 ;D2 746 ;D3 24819 ;D4 608523 ;D5 21019301 ;D6 542954168
nrbnkrqb/pppp1p1p/4p1p1/8/7P/2P1P3/PPNP1PP1/1RBNKRQB w FBfb - 0 9 ;D1 20 ;D2 459 ;D3 9998 ;D4 242762 ;D5 5760165 ;D6 146614723
nbrn1krq/ppp1p2p/6b1/3p1pp1/8/4N1PP/PPPPPP2/NBR1BRKQ w gc - 1 9 ;D1 27 ;D2 835 ;D3 23632 ;D4 766397 ;D5 22667987 ;D6 760795567
nrnbbkrq/p1pp2pp/5p2/1p6/2P1pP1B/1P6/P2PP1PP/NRNB1KRQ w GBgb - 0 9 ;D1 24 ;D2 646 ;D3 16102 ;D4 444472 ;D5 11489727 ;D6 324948755
nrn1bbrq/1ppkppp1/p2p3p/8/1P3N2/4P3/P1PP1PPP/NR1KBBRQ w GB - 2 9 ;D1 32 ;D2 591 ;D3 18722 ;D4 381683 ;D5 12069159 ;D6 269922838
n1krbrqb/1ppppppp/p7/8/4n3/P4P1P/1PPPPQP1/NRNKBR1B w FB - 2 9 ;D1 26 ;D2 639 ;D3 16988 ;D4 417190 ;D5 12167153 ;D6 312633873
n1rnkrbq/1p1ppp1p/8/p1p1b1p1/3PQ1P1/4N3/PPP1PP1P/NBR1KRB1 w FCfc - 0 9 ;D1 35 ;D2 1027 ;D3 35731 ;D4 1040417 ;D5 35738410 ;D6 1060661628
nrnbkrbq/2pp1pp1/pp6/4p2p/P7/5PPP/1PPPP3/NRNBKRBQ w FBfb - 0 9 ;D1 26 ;D2 628 ;D3 16731 ;D4 436075 ;D5 11920087 ;D6 331498921
1rnkrbbq/pp1p2pp/1n3p2/1Bp1p3/1P6/1N2P3/P1PP1PPP/1RNKR1BQ w EBeb - 0 9 ;D1 33 ;D2 992 ;D3 32244 ;D4 983481 ;D5 31703749 ;D6 980306735
nr1krqbb/p1ppppp1/8/1p5p/1Pn5/5P2/P1PPP1PP/NRNKRQBB w EBeb - 0 9 ;D1 24 ;D2 670 ;D3 15985 ;D4 445492 ;D5 11371067 ;D6 325556465
bbq1rkr1/1ppppppp/p1n2n2/8/2P2P2/1P6/PQ1PP1PP/BB1NRKNR w HEe - 3 9 ;D1 32 ;D2 794 ;D3 26846 ;D4 689334 ;D5 24085223 ;D6 645633370
b1nbrknr/1qppp1pp/p4p2/1p6/6P1/P2NP3/1PPP1P1P/BQ1BRKNR w HEhe - 1 9 ;D1 25 ;D2 663 ;D3 17138 ;D4 482994 ;D5 13157826 ;D6 389603029
bqnrk1nr/pp2ppbp/6p1/2pp4/2P5/5P2/PPQPP1PP/B1NRKBNR w HDhd - 0 9 ;D1 26 ;D2 850 ;D3 22876 ;D4 759768 ;D5 21341087 ;D6 719712622
bqnrknrb/1ppp1p1p/p7/6p1/1P2p3/P1PN4/3PPPPP/BQ1RKNRB w GDgd - 0 9 ;D1 25 ;D2 721 ;D3 19290 ;D4 581913 ;D5 16391601 ;D6 511725087
q1b1rknr/pp1pppp1/4n2p/2p1b3/1PP5/4P3/PQ1P1PPP/1BBNRKNR w HEhe - 1 9 ;D1 32 ;D2 975 ;D3 32566 ;D4 955493 ;D5 32649943 ;D6 962536105
qnbbrknr/1p1ppppp/8/p1p5/5P2/PP1P4/2P1P1PP/QNBBRKNR w HEhe - 0 9 ;D1 27 ;D2 573 ;D3 16331 ;D4 391656 ;D5 11562434 ;D6 301166330
q1brkb1r/p1pppppp/np3B2/8/6n1/1P5N/P1PPPPPP/QN1RKB1R w HDhd - 0 9 ;D1 32 ;D2 984 ;D3 31549 ;D4 1007217 ;D5 32597704 ;D6 1075429389
qn1rk1rb/p1pppppp/1p2n3/8/2b5/4NPP1/PPPPP1RP/QNBRK2B w Dgd - 4 9 ;D1 22 ;D2 802 ;D3 19156 ;D4 697722 ;D5 17761431 ;D6 650603534
qbnrbknr/ppp2p1p/8/3pp1p1/1PP1B3/5N2/P2PPPPP/Q1NRBK1R w HDhd - 0 9 ;D1 34 ;D2 943 ;D3 32506 ;D4 930619 ;D5 32523099 ;D6 955802240
qnrbb1nr/pp1p1ppp/2p2k2/4p3/4P3/5PPP/PPPP4/QNRBBKNR w HC - 0 9 ;D1 20 ;D2 460 ;D3 10287 ;D4 241640 ;D5 5846781 ;D6 140714047
qnr1bbnr/ppk1p1pp/3p4/2p2p2/8/2P5/PP1PPPPP/QNKRBBNR w - - 1 9 ;D1 19 ;D2 572 ;D3 11834 ;D4 357340 ;D5 7994547 ;D6 243724815
qnrkbnrb/1p1p1ppp/2p5/4p3/p7/N1BP4/PPP1PPPP/Q1R1KNRB w gc - 0 9 ;D1 27 ;D2 579 ;D3 16233 ;D4 375168 ;D5 10845146 ;D6 268229097
qbnrkn1r/1pppp1p1/p3bp2/2BN3p/8/5P2/PPPPP1PP/QBNRK2R w HDhd - 0 9 ;D1 40 ;D2 1027 ;D3 38728 ;D4 1059229 ;D5 38511307 ;D6 1104094381
qnrbknbr/1pp2ppp/4p3/p6N/2p5/8/PPPPPPPP/Q1RBK1BR w HChc - 0 9 ;D1 22 ;D2 510 ;D3 11844 ;D4 300180 ;D5 7403327 ;D6 200581103
1qkrnbbr/p1pppppp/2n5/1p6/8/5NP1/PPPPPP1P/QNRK1BBR w HC - 4 9 ;D1 24 ;D2 549 ;D3 13987 ;D4 352037 ;D5 9396521 ;D6 255676649
q1rknr1b/1ppppppb/2n5/p2B3p/8/1PN3P1/P1PPPP1P/Q1RKNRB1 w FCfc - 3 9 ;D1 31 ;D2 924 ;D3 28520 ;D4 861944 ;D5 27463479 ;D6 847726572
bbnqrk1r/pp1pppp1/2p4p/8/6n1/1N1P1P2/PPP1P1PP/BBQ1RKNR w HEhe - 4 9 ;D1 24 ;D2 804 ;D3 20147 ;D4 666341 ;D5 18024195 ;D6 595947631
bn1brknr/ppp1p1pp/5p2/3p4/6qQ/3P3P/PPP1PPP1/BN1BRKNR w HEhe - 4 9 ;D1 25 ;D2 854 ;D3 22991 ;D4 704173 ;D5 20290974 ;D6 600195008
1nqrkbnr/2pp1ppp/pp2p3/3b4/2P5/N7/PP1PPPPP/B1QRKBNR w HDhd - 0 9 ;D1 22 ;D2 651 ;D3 16173 ;D4 479152 ;D5 13133439 ;D6 390886040
bnqrk1rb/1pp1pppp/p2p4/4n3/2PPP3/8/PP3PPP/BNQRKNRB w GDgd - 1 9 ;D1 30 ;D2 950 ;D3 28169 ;D4 889687 ;D5 27610213 ;D6 880739164
nbb1rknr/1ppq1ppp/3p4/p3p3/4P3/1N2R3/PPPP1PPP/1BBQ1KNR w Hhe - 2 9 ;D1 33 ;D2 988 ;D3 31293 ;D4 967575 ;D5 30894863 ;D6 985384035
nqbbrknr/2ppp2p/pp4p1/5p2/7P/3P1P2/PPPBP1P1/NQ1BRKNR w HEhe - 0 9 ;D1 27 ;D2 492 ;D3 13266 ;D4 276569 ;D5 7583292 ;D6 175376176
1qbrkb1r/pppppppp/8/3n4/4P1n1/PN6/1PPP1P1P/1QBRKBNR w HDhd - 3 9 ;D1 28 ;D2 800 ;D3 21982 ;D4 630374 ;D5 17313279 ;D6 507140861
1qbrknrb/1p1ppppp/1np5/8/p4P1P/4P1N1/PPPP2P1/NQBRK1RB w GDgd - 0 9 ;D1 21 ;D2 482 ;D3 10581 ;D4 267935 ;D5 6218644 ;D6 168704845
nbqrbkr1/ppp1pppp/8/3p4/6n1/2P2PPN/PP1PP2P/NBQRBK1R w HDd - 1 9 ;D1 29 ;D2 921 ;D3 25748 ;D4 840262 ;D5 24138518 ;D6 806554650
nqrb1knr/1ppbpp1p/p7/3p2p1/2P3P1/5P1P/PP1PP3/NQRBBKNR w HChc - 1 9 ;D1 31 ;D2 803 ;D3 25857 ;D4 665799 ;D5 21998733 ;D6 583349773
1qrkbbr1/pppp1ppp/1n3n2/4p3/5P2/1N6/PPPPP1PP/1QRKBBNR w HCc - 0 9 ;D1 25 ;D2 715 ;D3 19118 ;D4 556325 ;D5 15514933 ;D6 459533767
nqrkb1rb/pp2pppp/2p1n3/3p4/3PP1N1/8/PPP2PPP/NQRKB1RB w GCgc - 0 9 ;D1 26 ;D2 795 ;D3 21752 ;D4 679387 ;D5 19185851 ;D6 616508881
nb1rknbr/pp2ppp1/8/2Bp3p/6P1/2P2P1q/PP1PP2P/NBQRKN1R w HDhd - 0 9 ;D1 35 ;D2 1391 ;D3 43025 ;D4 1726888 ;D5 53033675 ;D6 2139267832
nqrbkn1r/pp1pp1pp/8/2p2p2/5P2/P3B2P/1PbPP1P1/NQRBKN1R w HChc - 0 9 ;D1 23 ;D2 758 ;D3 19439 ;D4 653854 ;D5 18296195 ;D6 628403401
nqrknbbr/pp1pppp1/7p/2p5/7P/1P1N4/P1PPPPPB/NQRK1B1R w HChc - 2 9 ;D1 29 ;D2 824 ;D3 23137 ;D4 683686 ;D5 19429491 ;D6 595493802
1qrknrbb/B1p1pppp/8/1p1p4/2n2P2/1P6/P1PPP1PP/NQRKNR1B w FCfc - 0 9 ;D1 28 ;D2 771 ;D3 20237 ;D4 581721 ;D5 16065378 ;D6 483037840
bbnrqk1r/1ppppppp/8/7n/1p6/P6P/1BPPPPP1/1BNRQKNR w HDhd - 0 9 ;D1 25 ;D2 601 ;D3 15471 ;D4 396661 ;D5 10697065 ;D6 289472497
bnrbqknr/ppp3p1/3ppp1Q/7p/3P4/1P6/P1P1PPPP/BNRB1KNR w HChc - 0 9 ;D1 32 ;D2 845 ;D3 26876 ;D4 742888 ;D5 23717883 ;D6 682154649
bn1qkb1r/pprppppp/8/2p5/2PPP1n1/8/PPR2PPP/BN1QKBNR w Hh - 1 9 ;D1 32 ;D2 856 ;D3 27829 ;D4 768595 ;D5 25245957 ;D6 727424329
1nrqknrb/p1pp1ppp/1p2p3/3N4/5P1P/5b2/PPPPP3/B1RQKNRB w GCgc - 2 9 ;D1 33 ;D2 873 ;D3 27685 ;D4 779473 ;D5 25128076 ;D6 745401024
nbbrqrk1/pppppppp/8/2N1n3/P7/6P1/1PPPPP1P/1BBRQKNR w HD - 3 9 ;D1 25 ;D2 555 ;D3 14339 ;D4 342296 ;D5 9153089 ;D6 234841945
1rbbqknr/1ppp1pp1/1n2p3/p6p/4P1P1/P6N/1PPP1P1P/NRBBQK1R w HBhb - 0 9 ;D1 25 ;D2 693 ;D3 18652 ;D4 528070 ;D5 15133381 ;D6 439344945
nrq1kbnr/p1pbpppp/3p4/1p6/6P1/1N3N2/PPPPPP1P/1RBQKB1R w HBhb - 4 9 ;D1 24 ;D2 648 ;D3 16640 ;D4 471192 ;D5 12871967 ;D6 380436777
nr1qknr1/p1pppp1p/b5p1/1p6/8/P4PP1/1bPPP1RP/NRBQKN1B w Bgb - 0 9 ;D1 18 ;D2 533 ;D3 11215 ;D4 331243 ;D5 7777833 ;D6 234905172
nbrqbknr/1ppp2pp/8/4pp2/p2PP1P1/7N/PPP2P1P/NBRQBK1R w HChc - 0 9 ;D1 29 ;D2 803 ;D3 24416 ;D4 706648 ;D5 22305910 ;D6 672322762
nr1b1k1r/ppp1pppp/2bp1n2/6P1/2P3q1/5P2/PP1PP2P/NRQBBKNR w HBhb - 1 9 ;D1 27 ;D2 1199 ;D3 30908 ;D4 1296241 ;D5 35121759 ;D6 1418677099
nrqkbbnr/2pppp1p/p7/1p6/2P1Pp2/8/PPNP2PP/1RQKBBNR w HBhb - 0 9 ;D1 28 ;D2 613 ;D3 17874 ;D4 432750 ;D5 13097064 ;D6 345294379
1rqkbnrb/pp1ppp1p/1n4p1/B1p5/3PP3/4N3/PPP2PPP/NRQK2RB w GBgb - 0 9 ;D1 33 ;D2 723 ;D3 23991 ;D4 590970 ;D5 19715083 ;D6 535650233
nbrqkn1r/1pppp2p/5pp1/p2b4/5P2/P2PN3/1PP1P1PP/NBRQK1BR w HChc - 2 9 ;D1 23 ;D2 607 ;D3 15482 ;D4 400970 ;D5 11026383 ;D6 290708878
nrqbknbr/pp1pppp1/8/2p4p/P3PP2/8/1PPP2PP/NRQBKNBR w HBhb - 1 9 ;D1 26 ;D2 700 ;D3 19371 ;D4 556026 ;D5 16058815 ;D6 485460242
nrqknbbr/p2pppp1/1pp5/6Qp/3P4/1P3P2/P1P1P1PP/NR1KNBBR w HBhb - 0 9 ;D1 40 ;D2 905 ;D3 32932 ;D4 829746 ;D5 29263502 ;D6 791963709
nrqknrbb/1p3ppp/p2p4/2p1p3/1P6/3PP1P1/P1P2P1P/NRQKNRBB w FBfb - 0 9 ;D1 29 ;D2 780 ;D3 22643 ;D4 654495 ;D5 19532077 ;D6 593181101
1bnrkqnr/p1pppp2/7p/1p4p1/4b3/7N/PPPP1PPP/BBNRKQ1R w HDhd - 0 9 ;D1 25 ;D2 725 ;D3 19808 ;D4 565006 ;D5 16661676 ;D6 487354613
bnrbkq1r/pp2p1pp/5n2/2pp1p2/P7/N1PP4/1P2PPPP/B1RBKQNR w HChc - 1 9 ;D1 24 ;D2 745 ;D3 18494 ;D4 584015 ;D5 15079602 ;D6 488924040
2rkqbnr/p1pppppp/2b5/1pn5/1P3P1Q/2B5/P1PPP1PP/1NRK1BNR w HChc - 3 9 ;D1 33 ;D2 904 ;D3 30111 ;D4 840025 ;D5 28194726 ;D6 801757709
bnrkqnrb/2pppp2/8/pp4pp/1P5P/6P1/P1PPPPB1/BNRKQNR1 w GCgc - 0 9 ;D1 34 ;D2 1059 ;D3 34090 ;D4 1054311 ;D5 33195397 ;D6 1036498304
1bbrkq1r/pppp2pp/1n2pp1n/8/2PP4/1N4P1/PP2PP1P/1BBRKQNR w HDhd - 1 9 ;D1 33 ;D2 891 ;D3 28907 ;D4 814247 ;D5 26970098 ;D6 788040469
nrbbkqnr/1p2pp1p/p1p3p1/3p4/8/1PP5/P2PPPPP/NRBBKQNR w HBhb - 0 9 ;D1 21 ;D2 567 ;D3 13212 ;D4 376487 ;D5 9539687 ;D6 284426039
1rbkqbr1/ppp1pppp/1n5n/3p4/3P4/1PP3P1/P3PP1P/NRBKQBNR w HBb - 1 9 ;D1 27 ;D2 752 ;D3 20686 ;D4 606783 ;D5 16986290 ;D6 521817800
nrbkq1rb/1ppp1pp1/4p1n1/p6p/2PP4/5P2/PPK1P1PP/NRB1QNRB w gb - 0 9 ;D1 35 ;D2 697 ;D3 23678 ;D4 505836 ;D5 16906409 ;D6 390324794
nbrkbqnr/p2pp1p1/5p2/1pp4p/7P/3P2P1/PPP1PP2/NBKRBQNR w hc - 0 9 ;D1 25 ;D2 679 ;D3 17223 ;D4 484921 ;D5 12879258 ;D6 376652259
nrkb1qnr/ppppp1p1/6bp/5p2/1PP1P1P1/8/P2P1P1P/NRKBBQNR w HBhb - 1 9 ;D1 32 ;D2 761 ;D3 24586 ;D4 632916 ;D5 20671433 ;D6 568524724
nrk1bbnr/p1q1pppp/1ppp4/8/3P3P/4K3/PPP1PPP1/NR1QBBNR w hb - 0 9 ;D1 30 ;D2 719 ;D3 21683 ;D4 541389 ;D5 16278120 ;D6 423649784
nrkqbr1b/1pppp1pp/5pn1/p6N/1P3P2/8/P1PPP1PP/NRKQB1RB w GBb - 0 9 ;D1 26 ;D2 494 ;D3 13815 ;D4 296170 ;D5 8763742 ;D6 206993496
nbrkq2r/pppp1bpp/4p1n1/5p2/7P/2P3N1/PP1PPPP1/NBKRQ1BR w hc - 0 9 ;D1 27 ;D2 701 ;D3 19536 ;D4 535052 ;D5 15394667 ;D6 443506342
nrkbqnbr/2ppp2p/pp6/5pp1/P1P5/8/1P1PPPPP/NRKBQNBR w HBhb - 0 9 ;D1 21 ;D2 487 ;D3 11341 ;D4 285387 ;D5 7218486 ;D6 193586674
nr1qnbbr/pk1pppp1/1pp4p/8/3P4/5P1P/PPP1P1P1/NRKQNBBR w HB - 0 9 ;D1 22 ;D2 546 ;D3 13615 ;D4 352855 ;D5 9587439 ;D6 259830255
nrkq1rbb/pp1ppp1p/2pn4/8/PP3Pp1/7P/2PPP1P1/NRKQNRBB w FBfb - 0 9 ;D1 26 ;D2 839 ;D3 22075 ;D4 723845 ;D5 19867117 ;D6 658535326
b2rknqr/pp1ppppp/8/2P5/n7/P7/1PPNPPPb/BBNRK1QR w HDhd - 2 9 ;D1 24 ;D2 699 ;D3 19523 ;D4 575172 ;D5 17734818 ;D6 535094237
bnrbknqr/pp2p2p/2p3p1/3p1p2/8/3P4/PPPNPPPP/B1RBKNQR w HChc - 0 9 ;D1 23 ;D2 580 ;D3 14320 ;D4 385917 ;D5 10133092 ;D6 288041554
bnrknb1r/pppp2pp/8/4pp2/6P1/3P3P/qPP1PPQ1/BNRKNB1R w HChc - 0 9 ;D1 28 ;D2 1100 ;D3 31813 ;D4 1217514 ;D5 36142423 ;D6 1361341249
b1rknqrb/ppp1p1p1/2np1p1p/8/4N3/6PQ/PPPPPP1P/B1RKN1RB w GCgc - 0 9 ;D1 36 ;D2 629 ;D3 23082 ;D4 453064 ;D5 16897544 ;D6 367503974
nb1rknqr/pbppp2p/6p1/1p3p2/5P2/3KP3/PPPP2PP/NBBR1NQR w hd - 2 9 ;D1 18 ;D2 557 ;D3 9779 ;D4 300744 ;D5 5822387 ;D6 180936551
nr1bknqr/1ppb1ppp/p7/3pp3/B7/2P3NP/PP1PPPP1/NRB1K1QR w HBhb - 2 9 ;D1 28 ;D2 688 ;D3 19541 ;D4 519785 ;D5 15153092 ;D6 425149249
nrbkn2r/pppp1pqp/4p1p1/8/3P2P1/P3B3/P1P1PP1P/NR1KNBQR w HBhb - 1 9 ;D1 32 ;D2 808 ;D3 25578 ;D4 676525 ;D5 22094260 ;D6 609377239
nrbknqrb/2p1ppp1/1p6/p2p2Bp/1P6/3P1P2/P1P1P1PP/NR1KNQRB w GBgb - 0 9 ;D1 30 ;D2 625 ;D3 18288 ;D4 418895 ;D5 12225742 ;D6 301834282
nbr1knqr/1pp1p1pp/3p1pb1/8/7P/5P2/PPPPPQP1/NBRKBN1R w HC - 2 9 ;D1 29 ;D2 863 ;D3 25767 ;D4 800239 ;D5 24965592 ;D6 799182442
n1kbbnqr/prp2ppp/1p1p4/4p3/1P2P3/3P1B2/P1P2PPP/NRK1BNQR w HBh - 2 9 ;D1 26 ;D2 653 ;D3 17020 ;D4 449719 ;D5 12187583 ;D6 336872952
nrknbbqr/pp3p1p/B3p1p1/2pp4/4P3/2N3P1/PPPP1P1P/NRK1B1QR w HBhb - 0 9 ;D1 29 ;D2 683 ;D3 19755 ;D4 501807 ;D5 14684565 ;D6 394951291
n1knbqrb/pr1p1ppp/Qp6/2p1p3/4P3/6P1/PPPP1P1P/NRKNB1RB w GBg - 2 9 ;D1 31 ;D2 552 ;D3 17197 ;D4 371343 ;D5 11663330 ;D6 283583340
nbrknqbr/p3p1pp/1p1p1p2/2p5/2Q1PP2/8/PPPP2PP/NBRKN1BR w HChc - 0 9 ;D1 37 ;D2 913 ;D3 32470 ;D4 825748 ;D5 28899548 ;D6 759875563
nrkb1qbr/pp1pppp1/5n2/7p/2p5/1N1NPP2/PPPP2PP/1RKB1QBR w HBhb - 0 9 ;D1 25 ;D2 712 ;D3 18813 ;D4 543870 ;D5 15045589 ;D6 445074372
nrk2bbr/pppqpppp/3p4/8/1P3nP1/3P4/P1P1PP1P/NRKNQBBR w HBhb - 1 9 ;D1 24 ;D2 814 ;D3 19954 ;D4 670162 ;D5 17603960 ;D6 592121050
nrknqrbb/1p2ppp1/2pp4/Q6p/P2P3P/8/1PP1PPP1/NRKN1RBB w FBfb - 0 9 ;D1 34 ;D2 513 ;D3 16111 ;D4 303908 ;D5 9569590 ;D6 206509331
bbnrk1rq/pp2p1pp/2ppn3/5p2/8/3NNP1P/PPPPP1P1/BB1RK1RQ w GDgd - 1 9 ;D1 28 ;D2 697 ;D3 20141 ;D4 517917 ;D5 15301879 ;D6 410843713
bnrbknrq/ppppp2p/6p1/5p2/4QPP1/8/PPPPP2P/BNRBKNR1 w GCgc - 0 9 ;D1 37 ;D2 901 ;D3 32612 ;D4 877372 ;D5 31385912 ;D6 903831981
bnkrnbrq/ppppp1p1/B6p/5p2/8/4P3/PPPP1PPP/BNKRN1RQ w - - 0 9 ;D1 26 ;D2 417 ;D3 11124 ;D4 217095 ;D5 5980981 ;D6 133080499
bnrk1rqb/2pppp1p/3n4/pp4p1/3Q1P2/2N3P1/PPPPP2P/B1RKNR1B w FCfc - 0 9 ;D1 49 ;D2 1655 ;D3 74590 ;D4 2512003 ;D5 107234294 ;D6 3651608327
nbbrk1rq/pp2pppp/2pp4/8/2P2n2/6N1/PP1PP1PP/NBBRKR1Q w Dgd - 0 9 ;D1 28 ;D2 960 ;D3 26841 ;D4 884237 ;D5 26083252 ;D6 846682836
nrbb2rq/pppk1ppp/4p1n1/3p4/6P1/1BP5/PP1PPPQP/NRB1KNR1 w GB - 0 9 ;D1 28 ;D2 735 ;D3 22048 ;D4 593839 ;D5 18588316 ;D6 512048946
nrbk1brq/p1ppppp1/7p/1p6/4P1nP/P7/1PPP1PP1/NRBKNBRQ w GBgb - 0 9 ;D1 22 ;D2 572 ;D3 12739 ;D4 351494 ;D5 8525056 ;D6 247615348
nrbk1rqb/1pp2ppp/5n2/p2pp3/5B2/1N1P2P1/PPP1PP1P/1R1KNRQB w FBfb - 0 9 ;D1 35 ;D2 927 ;D3 31559 ;D4 849932 ;D5 28465693 ;D6 783048748
nbrkb1rq/p1pp1ppp/4n3/4p3/Pp6/6N1/1PPPPPPP/NBRKBRQ1 w Cgc - 0 9 ;D1 20 ;D2 456 ;D3 10271 ;D4 247733 ;D5 6124625 ;D6 154766108
nrkb1nrq/p2pp1pp/1pp2p2/7b/6PP/5P2/PPPPP2N/NRKBB1RQ w GBgb - 0 9 ;D1 21 ;D2 479 ;D3 11152 ;D4 264493 ;D5 6696458 ;D6 165253524
nr1nbbr1/pppkpp1p/6p1/3p4/P6P/1P6/1RPPPPP1/N1KNBBRQ w G - 1 9 ;D1 20 ;D2 498 ;D3 11304 ;D4 288813 ;D5 7197322 ;D6 188021682
nrknbrqb/3p1ppp/ppN1p3/8/6P1/8/PPPPPP1P/1RKNBRQB w FBfb - 0 9 ;D1 32 ;D2 526 ;D3 17267 ;D4 319836 ;D5 10755190 ;D6 220058991
nbrkn1bq/p1pppr1p/1p6/5pp1/8/1N2PP2/PPPP2PP/1BKRNRBQ w c - 1 9 ;D1 19 ;D2 491 ;D3 10090 ;D4 277313 ;D5 6230616 ;D6 180748649
nrkbnrbq/ppppppp1/8/8/7p/PP3P2/2PPPRPP/NRKBN1BQ w Bfb - 0 9 ;D1 16 ;D2 353 ;D3 6189 ;D4 156002 ;D5 3008668 ;D6 82706705
nrknrbbq/p4ppp/2p1p3/1p1p4/1P2P3/2P5/P1NP1PPP/1RKNRBBQ w EBeb - 0 9 ;D1 29 ;D2 728 ;D3 21915 ;D4 587668 ;D5 18231199 ;D6 511686397
nrknr1bb/pppp1p2/7p/2qPp1p1/8/1P5P/P1P1PPP1/NRKNRQBB w EBeb - 0 9 ;D1 20 ;D2 714 ;D3 14336 ;D4 500458 ;D5 11132758 ;D6 386064577
bbqnrrkn/ppp2p1p/3pp1p1/8/1PP5/2Q5/P1BPPPPP/B2NRKRN w GE - 0 9 ;D1 39 ;D2 593 ;D3 23446 ;D4 424799 ;D5 16764576 ;D6 346185058
bqn1rkrn/p1p2ppp/1p1p4/4p3/3PP2b/8/PPP2PPP/BQNBRKRN w GEge - 2 9 ;D1 25 ;D2 773 ;D3 20042 ;D4 616817 ;D5 16632403 ;D6 515838333
bqnrkb1n/p1p1pprp/3p4/1p2P1p1/2PP4/8/PP3PPP/BQNRKBRN w GDd - 1 9 ;D1 31 ;D2 860 ;D3 28102 ;D4 810379 ;D5 27233018 ;D6 813751250
bqr1krnb/ppppppp1/7p/3n4/1P4P1/P4N2/2PPPP1P/BQNRKR1B w FDf - 3 9 ;D1 31 ;D2 709 ;D3 22936 ;D4 559830 ;D5 18608857 ;D6 480498340
qbbn1krn/pp3ppp/4r3/2ppp3/P1P4P/8/1P1PPPP1/QBBNRKRN w GEg - 1 9 ;D1 26 ;D2 775 ;D3 21100 ;D4 649673 ;D5 18476807 ;D6 582542257
qnbbrkrn/1p1pp2p/p7/2p2pp1/8/4P2P/PPPP1PPK/QNBBRR1N w ge - 0 9 ;D1 25 ;D2 599 ;D3 15139 ;D4 389104 ;D5 10260500 ;D6 279222412
qnbrkbrn/1ppp2p1/p3p2p/5p2/P4P2/1P6/2PPP1PP/QNBRKBRN w GDgd - 0 9 ;D1 27 ;D2 588 ;D3 16735 ;D4 394829 ;D5 11640416 ;D6 293541380
1nbrkrnb/p1pppp1p/1pq3p1/8/4P3/P1P4N/1P1P1PPP/QNBRKR1B w FDfd - 1 9 ;D1 18 ;D2 609 ;D3 11789 ;D4 406831 ;D5 8604788 ;D6 299491047
qb1r1krn/pppp2pp/1n2ppb1/4P3/7P/8/PPPP1PP1/QBNRBKRN w GDgd - 0 9 ;D1 20 ;D2 578 ;D3 12205 ;D4 349453 ;D5 7939483 ;D6 229142178
qnr1bkrn/p3pppp/1bpp4/1p6/2P2PP1/8/PP1PPN1P/QNRBBKR1 w GCgc - 0 9 ;D1 30 ;D2 865 ;D3 26617 ;D4 771705 ;D5 24475596 ;D6 719842237
1nkrbbrn/qppppppp/8/8/p2P4/1P5P/P1P1PPP1/QNKRBBRN w - - 0 9 ;D1 27 ;D2 672 ;D3 18371 ;D4 505278 ;D5 14065717 ;D6 410130412
1qrkbrnb/ppp1p1pp/n2p4/5p2/4N3/8/PPPPPPPP/Q1RKBRNB w Ffc - 2 9 ;D1 25 ;D2 718 ;D3 18573 ;D4 536771 ;D5 14404324 ;D6 424279467
q1nrkrbn/pp1pppp1/2p4p/8/P7/5Pb1/BPPPPNPP/Q1NRKRB1 w FDfd - 0 9 ;D1 22 ;D2 558 ;D3 12911 ;D4 336042 ;D5 8516966 ;D6 228074630
qnrbkrbn/1p1p1pp1/p1p5/4p2p/8/3P1P2/PPP1P1PP/QNRBKRBN w FCfc - 0 9 ;D1 28 ;D2 669 ;D3 17713 ;D4 440930 ;D5 12055174 ;D6 313276304
qnrkr1bn/p1pp1ppp/8/1p2p3/3P1P2/bP4P1/P1P1P2P/QNRKRBBN w ECec - 1 9 ;D1 23 ;D2 845 ;D3 20973 ;D4 759778 ;D5 19939053 ;D6 718075943
q1krrnbb/p1p1pppp/2np4/1pB5/5P2/8/PPPPP1PP/QNRKRN1B w EC - 0 9 ;D1 29 ;D2 776 ;D3 21966 ;D4 631941 ;D5 18110831 ;D6 549019739
bbn1rkrn/pp1p1ppp/8/2p1p1q1/6P1/P7/BPPPPP1P/B1NQRKRN w GEge - 0 9 ;D1 26 ;D2 936 ;D3 25177 ;D4 906801 ;D5 24984621 ;D6 901444251
bn1brkrn/pp1qpp1p/2p3p1/3p4/1PPP4/P7/4PPPP/BNQBRKRN w GEge - 1 9 ;D1 29 ;D2 755 ;D3 22858 ;D4 645963 ;D5 20128587 ;D6 600207069
b2rkbrn/p1pppppp/qp6/8/1n6/2B2P2/P1PPP1PP/1NQRKBRN w GDgd - 0 9 ;D1 24 ;D2 878 ;D3 21440 ;D4 791007 ;D5 20840078 ;D6 775795187
b2rkrnb/pqp1pppp/n7/1p1p4/P7/N1P2N2/1P1PPPPP/B1QRKR1B w FDfd - 4 9 ;D1 26 ;D2 724 ;D3 19558 ;D4 571891 ;D5 16109522 ;D6 492933398
1bbqrkrn/ppppp1p1/8/5p1p/P1n3P1/3P4/1PP1PP1P/NBBQRRKN w ge - 1 9 ;D1 25 ;D2 678 ;D3 17351 ;D4 461211 ;D5 12173245 ;D6 329661421
nqb1rrkn/ppp1bppp/3pp3/8/3P4/1P6/PQP1PPPP/N1BBRRKN w - - 1 9 ;D1 23 ;D2 503 ;D3 12465 ;D4 290341 ;D5 7626054 ;D6 188215608
nqbrkbr1/p1pppppp/1p6/2N2n2/2P5/5P2/PP1PP1PP/1QBRKBRN w GDgd - 1 9 ;D1 29 ;D2 688 ;D3 20289 ;D4 506302 ;D5 15167248 ;D6 399015237
nqbrkrn1/1ppppp2/6pp/p7/1P6/2Q5/P1PPPPPP/N1BRKRNB w FDfd - 0 9 ;D1 36 ;D2 602 ;D3 20985 ;D4 397340 ;D5 13706856 ;D6 291708797
nbqrbrkn/pp1p1pp1/2p5/4p2p/2P3P1/1P3P2/P2PP2P/NBQRBKRN w GD - 0 9 ;D1 34 ;D2 655 ;D3 22581 ;D4 474396 ;D5 16613630 ;D6 379344541
nqrbbrkn/1p1pppp1/8/p1p4p/4P2P/1N4P1/PPPP1P2/1QRBBKRN w GC - 0 9 ;D1 23 ;D2 597 ;D3 14468 ;D4 400357 ;D5 10096863 ;D6 294900903
nqrkbbrn/2p1p1pp/pp1p1p2/8/P2N4/2P5/1P1PPPPP/1QRKBBRN w GCgc - 0 9 ;D1 32 ;D2 744 ;D3 23310 ;D4 550728 ;D5 17597164 ;D6 428786656
n1krbrnb/q1pppppp/p7/1p6/3Q4/2P2P2/PP1PP1PP/N1RKBRNB w FC - 1 9 ;D1 43 ;D2 1038 ;D3 41327 ;D4 1074450 ;D5 40918952 ;D6 1126603824
nb1rkrbn/p1pp1p1p/qp6/4p1p1/5PP1/P7/1PPPPB1P/NBQRKR1N w FDfd - 2 9 ;D1 26 ;D2 645 ;D3 16463 ;D4 445464 ;D5 11911314 ;D6 342563372
nqr1krbn/pppp1ppp/8/8/3pP3/5P2/PPPb1NPP/NQRBKRB1 w FCfc - 3 9 ;D1 2 ;D2 51 ;D3 1047 ;D4 27743 ;D5 612305 ;D6 17040200
n1rkrbbn/pqppppp1/7p/1p6/8/1NPP4/PP1KPPPP/1QR1RBBN w ec - 0 9 ;D1 25 ;D2 674 ;D3 17553 ;D4 505337 ;D5 13421727 ;D6 403551903
1qrkrnbb/1p1p1ppp/pnp1p3/8/3PP3/P6P/1PP2PP1/NQRKRNBB w ECec - 0 9 ;D1 24 ;D2 688 ;D3 17342 ;D4 511444 ;D5 13322502 ;D6 403441498
1bnrqkrn/2ppppp1/p7/1p1b3p/3PP1P1/8/PPPQ1P1P/BBNR1KRN w GDgd - 1 9 ;D1 35 ;D2 925 ;D3 32238 ;D4 857060 ;D5 30458921 ;D6 824344087
bnrbqkr1/ppp2pp1/6n1/3pp2p/1P6/2N3N1/P1PPPPPP/B1RBQRK1 w gc - 0 9 ;D1 23 ;D2 704 ;D3 17345 ;D4 539587 ;D5 14154852 ;D6 450893738
1nrqkbrn/p1pppppp/8/1p1b4/P6P/5P2/1PPPP1P1/BNRQKBRN w GCgc - 1 9 ;D1 19 ;D2 505 ;D3 10619 ;D4 281422 ;D5 6450025 ;D6 175593967
b1rqkrnb/ppppppp1/8/6p1/3n4/NP6/P1PPPP1P/B1RQKRNB w FCfc - 0 9 ;D1 25 ;D2 614 ;D3 15578 ;D4 377660 ;D5 10391021 ;D6 259629603
nbbrqkrn/ppp3p1/3pp3/5p1p/1P2P3/P7/2PPQPPP/NBBR1KRN w GDgd - 0 9 ;D1 30 ;D2 833 ;D3 25719 ;D4 717713 ;D5 22873901 ;D6 649556666
nr1bqrk1/ppp1pppp/6n1/3pP3/8/5PQb/PPPP2PP/NRBB1KRN w GB - 3 9 ;D1 26 ;D2 734 ;D3 20161 ;D4 582591 ;D5 17199594 ;D6 512134836
1rbqkbr1/ppppp1pp/1n6/4np2/3P1P2/6P1/PPPQP2P/NRB1KBRN w GBgb - 1 9 ;D1 27 ;D2 662 ;D3 17897 ;D4 447464 ;D5 13038519 ;D6 338365642
nr1qkr1b/ppp1pp1p/4bn2/3p2p1/4P3/1Q6/PPPP1PPP/NRB1KRNB w FBfb - 4 9 ;D1 33 ;D2 939 ;D3 30923 ;D4 942138 ;D5 30995969 ;D6 991509814
nb1qbkrn/pprp1pp1/7p/2p1pB2/Q1PP4/8/PP2PPPP/N1R1BKRN w GCg - 2 9 ;D1 47 ;D2 1128 ;D3 50723 ;D4 1306753 ;D5 56747878 ;D6 1560584212
nrqb1rkn/pp2pppp/2bp4/2p5/6P1/2P3N1/PP1PPP1P/NRQBBRK1 w - - 3 9 ;D1 24 ;D2 828 ;D3 21148 ;D4 723705 ;D5 19506135 ;D6 668969549
nrq1bbrn/ppkpp2p/2p3p1/P4p2/8/4P1N1/1PPP1PPP/NRQKBBR1 w GB - 0 9 ;D1 25 ;D2 525 ;D3 13533 ;D4 309994 ;D5 8250997 ;D6 201795680
Br1kbrn1/pqpppp2/8/6pp/3b2P1/1N6/PPPPPP1P/1RQKBRN1 w FBfb - 3 9 ;D1 20 ;D2 790 ;D3 18175 ;D4 695905 ;D5 17735648 ;D6 669854148
nbrqkrbn/2p1p1pp/p7/1p1p1p2/4P1P1/5P2/PPPP3P/NBRQKRBN w FCfc - 0 9 ;D1 29 ;D2 771 ;D3 22489 ;D4 647106 ;D5 19192982 ;D6 591335970
1rqbkrbn/1ppppp1p/1n6/p1N3p1/8/2P4P/PP1PPPP1/1RQBKRBN w FBfb - 0 9 ;D1 29 ;D2 502 ;D3 14569 ;D4 287739 ;D5 8652810 ;D6 191762235
1rqkrbbn/ppnpp1pp/8/2p5/6p1/3P4/PPP1PPPP/NRK1RBBN w eb - 0 9 ;D1 19 ;D2 531 ;D3 10812 ;D4 300384 ;D5 6506674 ;D6 184309316
nrqkrnbb/p1pp2pp/5p2/4P3/2p5/4N3/PP1PP1PP/NRQKR1BB w EBeb - 0 9 ;D1 26 ;D2 800 ;D3 23256 ;D4 756695 ;D5 23952941 ;D6 809841274
bbnrkqrn/pp3pp1/4p2p/2pp4/4P1P1/1PB5/P1PP1P1P/1BNRKQRN w GDgd - 0 9 ;D1 33 ;D2 915 ;D3 30536 ;D4 878648 ;D5 29602610 ;D6 881898159
bnrbkqr1/1p2pppp/6n1/p1pp4/7P/P3P3/1PPPKPP1/BNRB1QRN w gc - 0 9 ;D1 19 ;D2 457 ;D3 9332 ;D4 238944 ;D5 5356253 ;D6 144653627
b1rkqbrn/pp1p2pp/2n1p3/2p2p2/3P2PP/8/PPP1PP2/BNKRQBRN w gc - 0 9 ;D1 30 ;D2 985 ;D3 30831 ;D4 1011700 ;D5 32684185 ;D6 1080607773
b1rkqrnb/2ppppp1/np6/p6p/1P6/P2P3P/2P1PPP1/BNRKQRNB w FCfc - 0 9 ;D1 26 ;D2 692 ;D3 18732 ;D4 517703 ;D5 14561181 ;D6 413226841
nbbrkqrn/1ppp1p2/p6p/4p1p1/5P2/1P5P/P1PPPNP1/NBBRKQR1 w GDgd - 0 9 ;D1 22 ;D2 561 ;D3 13222 ;D4 367487 ;D5 9307003 ;D6 273928315
nrbbkqrn/p1pppppp/8/1p6/4P3/7Q/PPPP1PPP/NRBBK1RN w GBgb - 0 9 ;D1 38 ;D2 769 ;D3 28418 ;D4 632310 ;D5 23091070 ;D6 560139600
nrbkqbrn/1pppp2p/8/p4pp1/P4PQ1/8/1PPPP1PP/NRBK1BRN w GBgb - 0 9 ;D1 23 ;D2 507 ;D3 13067 ;D4 321423 ;D5 8887567 ;D6 237475184
nr1kqr1b/pp2pppp/5n2/2pp4/P5b1/5P2/1PPPPRPP/NRBK1QNB w Bfb - 2 9 ;D1 18 ;D2 626 ;D3 12386 ;D4 434138 ;D5 9465555 ;D6 335004239
nbkrbqrn/1pppppp1/8/4P2p/pP6/P7/2PP1PPP/NBRKBQRN w GC - 0 9 ;D1 22 ;D2 329 ;D3 8475 ;D4 148351 ;D5 4160034 ;D6 82875306
nrkb1qrn/pp1pp1pp/8/5p1b/P1p4P/6N1/1PPPPPP1/NRKBBQR1 w GBgb - 2 9 ;D1 16 ;D2 479 ;D3 9037 ;D4 275354 ;D5 5862341 ;D6 184959796
1rkq1brn/ppppp1pp/1n6/3b1p2/3N3P/5P2/PPPPP1P1/1RKQBBRN w GBgb - 3 9 ;D1 23 ;D2 614 ;D3 15324 ;D4 418395 ;D5 11090645 ;D6 313526088
nrk1brnb/pp1ppppp/2p5/3q4/5P2/PP6/1KPPP1PP/NR1QBRNB w fb - 1 9 ;D1 25 ;D2 942 ;D3 21765 ;D4 792179 ;D5 19318837 ;D6 685549171
nbrkqr1n/1pppp2p/p4pp1/2Bb4/5P2/6P1/PPPPP2P/NBRKQ1RN w Cfc - 2 9 ;D1 30 ;D2 841 ;D3 24775 ;D4 677876 ;D5 20145765 ;D6 557578726
n1kbqrbn/2p1pppp/1r6/pp1p4/P7/3P4/1PP1PPPP/NRKBQRBN w FBf - 2 9 ;D1 21 ;D2 591 ;D3 14101 ;D4 394289 ;D5 10295086 ;D6 292131422
nrkqrbb1/ppp1pppp/3p4/8/4P3/2Pn1P2/PP4PP/NRKQRBBN w EBeb - 0 9 ;D1 4 ;D2 88 ;D3 3090 ;D4 73414 ;D5 2640555 ;D6 66958031
nrkqrnbb/ppppp1p1/7p/1P3p2/3P4/2P5/P3PPPP/NRKQRNBB w EBeb - 0 9 ;D1 29 ;D2 689 ;D3 21091 ;D4 508789 ;D5 16226660 ;D6 408570219
bbnr1rqn/pp2pkpp/2pp1p2/8/4P1P1/8/PPPP1P1P/BBNRKRQN w FD - 0 9 ;D1 21 ;D2 463 ;D3 11135 ;D4 256244 ;D5 6826249 ;D6 165025370
bnrbk1qn/1pppprpp/8/p4p1P/6P1/3P4/PPP1PP2/BNRBKRQN w FCc - 0 9 ;D1 22 ;D2 459 ;D3 11447 ;D4 268157 ;D5 7371098 ;D6 190583454
1nrkrbqn/p1pp1ppp/4p3/1p6/1PP5/6PB/P2PPPbP/BNRKR1QN w ECec - 0 9 ;D1 30 ;D2 931 ;D3 29012 ;D4 887414 ;D5 28412902 ;D6 869228014
b1rkr1nb/pppppqp1/n4B2/7p/8/1P4P1/P1PPPP1P/1NKRRQNB w ec - 1 9 ;D1 36 ;D2 934 ;D3 31790 ;D4 930926 ;D5 30392925 ;D6 952871799
nbbrkrqn/p1ppp1p1/8/1p3p1p/2P3PP/8/PP1PPPQ1/NBBRKR1N w FDfd - 0 9 ;D1 34 ;D2 938 ;D3 31848 ;D4 921716 ;D5 31185844 ;D6 944483246
1rbbkrqn/ppp1pp2/1n1p2p1/7p/P3P1P1/3P4/1PP2P1P/NRBBKRQN w FBfb - 0 9 ;D1 26 ;D2 646 ;D3 18083 ;D4 472744 ;D5 14006203 ;D6 384101783
nrbkrbq1/Qpppp1pp/2n5/5p2/P4P2/6N1/1PPPP1PP/NRBKRB2 w EBeb - 1 9 ;D1 27 ;D2 619 ;D3 16713 ;D4 421845 ;D5 11718463 ;D6 313794027
1rbkr1nb/pppp1qpp/1n6/4pp2/1PP1P3/8/PB1P1PPP/NR1KRQNB w EBeb - 1 9 ;D1 32 ;D2 1029 ;D3 32970 ;D4 1080977 ;D5 35483796 ;D6 1181835398
nbrk1rqn/p1ppp2p/1p6/5ppb/8/1N2P2P/PPPP1PP1/1BKRBRQN w fc - 0 9 ;D1 18 ;D2 594 ;D3 12350 ;D4 408544 ;D5 9329122 ;D6 315021712
nrkbbrqn/3pppp1/7p/ppp5/P7/1N5P/1PPPPPP1/1RKBBRQN w FBfb - 0 9 ;D1 19 ;D2 417 ;D3 9026 ;D4 218513 ;D5 5236331 ;D6 137024458
nrkr1bqn/ppp1pppp/3p4/1b6/7P/P7/1PPPPPP1/NRKRBBQN w DBdb - 1 9 ;D1 17 ;D2 457 ;D3 9083 ;D4 243872 ;D5 5503579 ;D6 150091997
nrkrbqnb/p4ppp/1p2p3/2pp4/6P1/2P2N2/PPNPPP1P/1RKRBQ1B w DBdb - 0 9 ;D1 27 ;D2 755 ;D3 21012 ;D4 620093 ;D5 17883987 ;D6 547233320
nbkrr1bn/ppB2ppp/4p3/2qp4/4P3/5P2/PPPP2PP/NBRKRQ1N w EC - 1 9 ;D1 37 ;D2 1473 ;D3 51939 ;D4 1956521 ;D5 68070015 ;D6 2490912491
n1kbrqbn/p1pp1pp1/4p2p/2B5/1r3P2/8/PPPPP1PP/NRKBRQ1N w EBe - 2 9 ;D1 30 ;D2 1029 ;D3 30874 ;D4 1053163 ;D5 32318550 ;D6 1106487743
nrkrqbbn/2pppp1p/8/pp6/1P1P2p1/P5P1/2P1PP1P/NRKRQBBN w DBdb - 0 9 ;D1 22 ;D2 421 ;D3 10034 ;D4 221927 ;D5 5754555 ;D6 141245633
nrkr1nbb/1ppp2pp/p3q3/4pp2/2P5/P3P3/1PKP1PPP/NR1RQNBB w db - 0 9 ;D1 22 ;D2 619 ;D3 13953 ;D4 411392 ;D5 9905109 ;D6 301403003
bbnrkrnq/1pp1p2p/6p1/p2p1p2/8/1P2P3/P1PP1PPP/BBNRKRNQ w FDfd - 0 9 ;D1 27 ;D2 805 ;D3 21915 ;D4 688224 ;D5 19133881 ;D6 620749189
bnrbkrn1/pp1ppp2/2p3pp/8/2Pq4/P4PP1/1P1PP2P/BNRBKRNQ w FCfc - 1 9 ;D1 20 ;D2 770 ;D3 16593 ;D4 577980 ;D5 13581691 ;D6 456736500
b1rkrbnq/1pp1pppp/2np4/p5N1/8/1P2P3/P1PP1PPP/BNRKRB1Q w ECec - 0 9 ;D1 37 ;D2 740 ;D3 27073 ;D4 581744 ;D5 21156664 ;D6 485803600
b1krrnqb/pp1ppp1p/n1p3p1/2N5/6P1/8/PPPPPP1P/B1RKRNQB w EC - 0 9 ;D1 34 ;D2 850 ;D3 28494 ;D4 752350 ;D5 25360295 ;D6 698159474
1bbr1rnq/ppppkppp/8/3np3/4P3/3P4/PPP1KPPP/NBBRR1NQ w - - 1 9 ;D1 27 ;D2 704 ;D3 18290 ;D4 480474 ;D5 12817011 ;D6 341026662
nrbbk1nq/p1p1prpp/1p6/N2p1p2/P7/8/1PPPPPPP/R1BBKRNQ w Fb - 2 9 ;D1 23 ;D2 552 ;D3 13710 ;D4 348593 ;D5 9236564 ;D6 248469879
1rbkrb1q/1pppp1pp/1n5n/p4p2/P3P3/1P6/2PPNPPP/NRBKRB1Q w EBeb - 1 9 ;D1 22 ;D2 415 ;D3 10198 ;D4 217224 ;D5 5735644 ;D6 135295774
nrbkr1qb/1pp1pppp/6n1/p2p4/2P1P3/1N4N1/PP1P1PPP/1RBKR1QB w EBeb - 0 9 ;D1 27 ;D2 709 ;D3 19126 ;D4 506214 ;D5 14192779 ;D6 380516508
nbrkbrnq/p3p1pp/1pp2p2/3p4/1PP5/4P3/P1KP1PPP/NBR1BRNQ w fc - 0 9 ;D1 24 ;D2 715 ;D3 18009 ;D4 535054 ;D5 14322279 ;D6 427269976
nrk1brnq/pp1p1pp1/7p/b1p1p3/1P6/6P1/P1PPPPQP/NRKBBRN1 w FBfb - 2 9 ;D1 29 ;D2 675 ;D3 20352 ;D4 492124 ;D5 15316285 ;D6 389051744
nrkr1bnq/1p2pppp/p2p4/1bp5/PP6/1R5N/2PPPPPP/N1KRBB1Q w Ddb - 2 9 ;D1 27 ;D2 744 ;D3 20494 ;D4 571209 ;D5 16188945 ;D6 458900901
nrk1b1qb/pppn1ppp/3rp3/3p4/2P3P1/3P4/PPN1PP1P/1RKRBNQB w DBb - 3 9 ;D1 35 ;D2 941 ;D3 33203 ;D4 935791 ;D5 33150360 ;D6 968024386
nb1rrnbq/ppkp1ppp/8/2p1p3/P7/1N2P3/1PPP1PPP/1BKRRNBQ w - - 1 9 ;D1 19 ;D2 451 ;D3 9655 ;D4 235472 ;D5 5506897 ;D6 139436165
nrkbrnbq/4pppp/1ppp4/p7/2P1P3/3P2N1/PP3PPP/NRKBR1BQ w EBeb - 0 9 ;D1 29 ;D2 591 ;D3 17132 ;D4 384358 ;D5 11245508 ;D6 270967202
nrkrnbbq/3p1ppp/1p6/p1p1p3/3P2P1/P4Q2/1PP1PP1P/NRKRNBB1 w DBdb - 0 9 ;D1 38 ;D2 792 ;D3 28597 ;D4 640961 ;D5 22654797 ;D6 540864616
nr1rnqbb/ppp1pp1p/3k2p1/3p4/1P5P/3P1N2/P1P1PPP1/NRKR1QBB w DB - 1 9 ;D1 25 ;D2 758 ;D3 18547 ;D4 543643 ;D5 13890077 ;D6 402109399
bbqrnnkr/1ppp1p1p/5p2/p5p1/P7/1P4P1/2PPPP1P/1BQRNNKR w HDhd - 0 9 ;D1 20 ;D2 322 ;D3 7224 ;D4 145818 ;D5 3588435 ;D6 82754650
bqrb2k1/pppppppr/5nnp/8/3P1P2/4P1N1/PPP3PP/BQRBN1KR w HCc - 1 9 ;D1 25 ;D2 597 ;D3 15872 ;D4 397970 ;D5 11162476 ;D6 295682250
bqrnn1kr/1pppbppp/8/4p3/1p6/2P1N2P/P2PPPP1/BQR1NBKR w HChc - 1 9 ;D1 34 ;D2 921 ;D3 31695 ;D4 864023 ;D5 30126510 ;D6 850296236
bqr1nkr1/pppppp2/2n3p1/7p/1P1b1P2/8/PQP1P1PP/B1RNNKRB w GCgc - 0 9 ;D1 23 ;D2 788 ;D3 21539 ;D4 686795 ;D5 20849374 ;D6 645694580
qbbrnn1r/1pppp1pk/p7/5p1p/P2P3P/3N4/1PP1PPP1/QBBR1NKR w HD - 0 9 ;D1 34 ;D2 713 ;D3 24475 ;D4 562189 ;D5 19494094 ;D6 482645160
qrbb2kr/p1pppppp/1p1n4/8/1P3n2/P7/Q1PPP1PP/1RBBNNKR w HBhb - 0 9 ;D1 28 ;D2 977 ;D3 26955 ;D4 949925 ;D5 27802999 ;D6 992109168
qrb2bkr/1pp1pppp/2np1n2/pN6/3P4/4B3/PPP1PPPP/QR2NBKR w HBhb - 0 9 ;D1 27 ;D2 730 ;D3 20534 ;D4 585091 ;D5 17005916 ;D6 507008968
qrbnnkrb/pp2pp1p/8/2pp2p1/7P/P1P5/QP1PPPP1/1RBNNKRB w GBgb - 0 9 ;D1 24 ;D2 813 ;D3 21142 ;D4 707925 ;D5 19615756 ;D6 655850285
1brnb1kr/p1pppppp/1p6/8/4q2n/1P2P1P1/PNPP1P1P/QBR1BNKR w HChc - 3 9 ;D1 17 ;D2 734 ;D3 13462 ;D4 530809 ;D5 11032633 ;D6 416356876
1rnbbnkr/1pp1pppp/1q1p4/p7/4P3/5PN1/PPPP1BPP/QRNB2KR w HBhb - 1 9 ;D1 26 ;D2 809 ;D3 21764 ;D4 706677 ;D5 20292750 ;D6 675408811
qrnnbb1Q/ppp1pk1p/3p2p1/5p2/PP6/5P2/2PPP1PP/1RNNBBKR w HB - 0 9 ;D1 37 ;D2 751 ;D3 27902 ;D4 603931 ;D5 22443036 ;D6 515122176
qrnnbkrb/p3p1pp/3p1p2/1pp5/PP2P3/8/2PP1PPP/QRNNBRKB w gb - 0 9 ;D1 30 ;D2 906 ;D3 27955 ;D4 872526 ;D5 27658191 ;D6 890966633
qbrnnkbr/1p2pp1p/p1p3p1/3p4/6P1/P1N4P/1PPPPP2/QBR1NKBR w HChc - 0 9 ;D1 26 ;D2 701 ;D3 18930 ;D4 521377 ;D5 14733245 ;D6 416881799
qr1b1kbr/1p1ppppp/1n1n4/p1p5/4P3/5NPP/PPPP1P2/QRNB1KBR w HBhb - 1 9 ;D1 26 ;D2 649 ;D3 17235 ;D4 451997 ;D5 12367604 ;D6 342165821
qrnnkb1r/1pppppp1/7p/p4b2/4P3/5P1P/PPPP2PR/QRNNKBB1 w Bhb - 1 9 ;D1 34 ;D2 941 ;D3 31720 ;D4 901240 ;D5 30307554 ;D6 888709821
qr1nkrbb/p2ppppp/1pp5/8/3Pn3/1NP3P1/PP2PP1P/QR1NKRBB w FBfb - 1 9 ;D1 19 ;D2 505 ;D3 11107 ;D4 294251 ;D5 7046501 ;D6 190414579
bbrqn1kr/1pppp1pp/4n3/5p2/p5P1/3P4/PPP1PPKP/BBRQNN1R w hc - 0 9 ;D1 24 ;D2 573 ;D3 12963 ;D4 335845 ;D5 8191054 ;D6 227555387
brqb1nkr/pppppp1p/8/4N1pn/5P2/6P1/PPPPP2P/BRQB1NKR w HBhb - 0 9 ;D1 26 ;D2 550 ;D3 14338 ;D4 331666 ;D5 8903754 ;D6 223437427
brqnn1kr/pp3ppp/2pbp3/3p4/8/2NPP3/PPP1BPPP/BRQ1N1KR w HBhb - 0 9 ;D1 27 ;D2 780 ;D3 20760 ;D4 589328 ;D5 16243731 ;D6 463883447
brq1nkrb/ppp2ppp/8/n2pp2P/P7/4P3/1PPP1PP1/BRQNNKRB w GBgb - 1 9 ;D1 17 ;D2 426 ;D3 8295 ;D4 235162 ;D5 5048497 ;D6 153986034
rbbqn1kr/pp2p1pp/6n1/2pp1p2/2P4P/P7/BP1PPPP1/R1BQNNKR w HAha - 0 9 ;D1 27 ;D2 916 ;D3 25798 ;D4 890435 ;D5 26302461 ;D6 924181432
1qbbn1kr/1ppppppp/r3n3/8/p1P5/P7/1P1PPPPP/RQBBNNKR w HAh - 1 9 ;D1 29 ;D2 817 ;D3 24530 ;D4 720277 ;D5 22147642 ;D6 670707652
rqbnnbkr/ppp1ppp1/7p/3p4/PP6/7P/1NPPPPP1/RQB1NBKR w HAa - 1 9 ;D1 23 ;D2 572 ;D3 14509 ;D4 381474 ;D5 10416981 ;D6 288064942
r1bnnkrb/q1ppp1pp/p7/1p3pB1/2P1P3/3P4/PP3PPP/RQ1NNKRB w GAga - 2 9 ;D1 31 ;D2 925 ;D3 27776 ;D4 860969 ;D5 26316355 ;D6 843078864
rbqnb1kr/ppppp1pp/5p2/5N2/7P/1n3P2/PPPPP1P1/RBQNB1KR w HAha - 1 9 ;D1 32 ;D2 864 ;D3 27633 ;D4 766551 ;D5 24738875 ;D6 707188107
rqnbbn1r/ppppppp1/6k1/8/6Pp/2PN4/PP1PPPKP/RQ1BBN1R w - - 0 9 ;D1 27 ;D2 566 ;D3 15367 ;D4 347059 ;D5 9714509 ;D6 234622128
rqnnbbkr/p1p2pp1/1p1p3p/4p3/4NP2/6P1/PPPPP2P/RQN1BBKR w HAha - 0 9 ;D1 27 ;D2 631 ;D3 17923 ;D4 452734 ;D5 13307890 ;D6 356279813
1qnnbrkb/rppp1ppp/p3p3/8/4P3/2PP1P2/PP4PP/RQNNBKRB w GA - 1 9 ;D1 24 ;D2 479 ;D3 12135 ;D4 271469 ;D5 7204345 ;D6 175460841
rbqnn1br/p1pppk1p/1p4p1/5p2/8/P1P2P2/1PBPP1PP/R1QNNKBR w HA - 0 9 ;D1 31 ;D2 756 ;D3 23877 ;D4 625194 ;D5 20036784 ;D6 554292502
rqnbnkbr/1ppppp2/p5p1/8/1P4p1/4PP2/P1PP3P/RQNBNKBR w HAha - 0 9 ;D1 24 ;D2 715 ;D3 18536 ;D4 575589 ;D5 16013189 ;D6 515078271
rq1nkbbr/1p2pppp/p2n4/2pp4/1P4P1/P2N4/2PPPP1P/RQ1NKBBR w HAha - 1 9 ;D1 27 ;D2 694 ;D3 19840 ;D4 552904 ;D5 16685687 ;D6 494574415
r1nnkrbb/pp1pppp1/2p3q1/7p/8/1PPP3P/P3PPP1/RQNNKRBB w FAfa - 1 9 ;D1 18 ;D2 520 ;D3 10808 ;D4 329085 ;D5 7508201 ;D6 235103697
bbrnqk1r/pppp3p/6p1/4pp2/3P2P1/8/PPP1PP1P/BBRN1NKR w HC - 0 9 ;D1 22 ;D2 566 ;D3 12965 ;D4 362624 ;D5 8721079 ;D6 259069471
brnb1nkr/pppqpp2/3p2pp/8/3PP3/1P6/PBP2PPP/1RNBQNKR w HBhb - 0 9 ;D1 32 ;D2 859 ;D3 28517 ;D4 817464 ;D5 27734108 ;D6 829785474
brnq1b1r/ppp1ppkp/3p1np1/8/8/5P1P/PPPPPKPR/BRNQNB2 w - - 0 9 ;D1 21 ;D2 511 ;D3 10951 ;D4 273756 ;D5 6372681 ;D6 167139732
brnq1rkb/1pppppp1/3n3p/p7/8/P4NP1/1PPPPPRP/BRNQ1K1B w B - 0 9 ;D1 25 ;D2 548 ;D3 14049 ;D4 341208 ;D5 9015901 ;D6 235249649
rbb1qnkr/p1ppp1pp/1p3p2/6n1/8/1PN1P2P/P1PP1PP1/RBB1QNKR w HAha - 0 9 ;D1 25 ;D2 673 ;D3 16412 ;D4 467660 ;D5 12099119 ;D6 361714466
rnbb1nkr/1ppp1ppp/4p3/p5q1/6P1/1PP5/PB1PPP1P/RN1BQNKR w HAha - 1 9 ;D1 19 ;D2 663 ;D3 14149 ;D4 489653 ;D5 11491355 ;D6 399135495
rnbqnbkr/1pp1p2p/3p1p2/p5p1/5PP1/2P5/PPNPP2P/RNBQ1BKR w HAha - 0 9 ;D1 24 ;D2 647 ;D3 16679 ;D4 461931 ;D5 12649636 ;D6 361157611
rnb2krb/pppqppnp/8/3p2p1/1P4P1/7P/P1PPPPB1/RNBQNKR1 w GAga - 1 9 ;D1 24 ;D2 722 ;D3 18749 ;D4 605229 ;D5 16609220 ;D6 563558512
rbnqb1kr/pppn1pp1/3p3p/4p3/1P6/P7/R1PPPPPP/1BNQBNKR w Hha - 1 9 ;D1 20 ;D2 538 ;D3 12277 ;D4 345704 ;D5 8687621 ;D6 255304141
rnqb1nkr/p1pbp1pp/8/1pPp1p2/P2P4/8/1P2PPPP/RNQBBNKR w HAha - 1 9 ;D1 35 ;D2 764 ;D3 26952 ;D4 632796 ;D5 22592380 ;D6 564255328
rnq1bbkr/1p1ppp1p/4n3/p1p3p1/P1PP4/8/RP2PPPP/1NQNBBKR w Hha - 0 9 ;D1 29 ;D2 709 ;D3 21296 ;D4 570580 ;D5 17597398 ;D6 506140370
1nqnbkrb/1pppp2p/r7/p4pp1/3P4/8/PPPBPPPP/RNQNK1RB w g - 0 9 ;D1 27 ;D2 1028 ;D3 28534 ;D4 1050834 ;D5 30251988 ;D6 1096869832
rbnqnkbr/p1pp1p1p/8/1p2p3/3P2pP/2P5/PP2PPP1/RBNQNKBR w HAha - 0 9 ;D1 32 ;D2 832 ;D3 27120 ;D4 750336 ;D5 24945574 ;D6 724171581
rnq1nkbr/1p1p1ppp/2p1pb2/p7/7P/2P5/PPNPPPPB/RNQB1K1R w HAha - 2 9 ;D1 31 ;D2 779 ;D3 24010 ;D4 638640 ;D5 19919434 ;D6 551494771
rnqnk1br/p1ppp1bp/1p3p2/6p1/4N3/P5P1/1PPPPP1P/R1QNKBBR w HAha - 2 9 ;D1 25 ;D2 717 ;D3 19396 ;D4 576577 ;D5 16525239 ;D6 507175842
rnq1krbb/p1p1pppp/8/1p1p4/1n5B/2N2P2/PPPPP1PP/RNQ1KR1B w FAfa - 0 9 ;D1 28 ;D2 867 ;D3 24029 ;D4 735686 ;D5 21112751 ;D6 654808184
bbrnnqkr/1pp1pppp/3p4/p7/P3P3/7P/1PPP1PP1/BBRNNQKR w HChc - 0 9 ;D1 24 ;D2 405 ;D3 11025 ;D4 210557 ;D5 6196438 ;D6 131401224
brnbnqkr/p1ppp3/1p5p/5Pp1/5P2/3N4/PPPPP2P/BRNB1QKR w HBhb g6 0 9 ;D1 25 ;D2 785 ;D3 21402 ;D4 698331 ;D5 20687969 ;D6 695850727
br1nqbkr/1ppppp2/pn6/6pp/2PP4/1N4P1/PP2PP1P/BR1NQBKR w HBhb - 0 9 ;D1 25 ;D2 596 ;D3 16220 ;D4 421882 ;D5 12185361 ;D6 337805606
1rnnqkrb/p2ppp1p/1pp5/2N3p1/8/1P6/P1PPPPKP/BR1NQ1RB w gb - 0 9 ;D1 38 ;D2 960 ;D3 34831 ;D4 913665 ;D5 32490040 ;D6 880403591
rbbnnqkr/pp3pp1/2p1p3/3p3p/3P3P/1PP5/P3PPP1/RBBNNQKR w HAha - 0 9 ;D1 30 ;D2 785 ;D3 23079 ;D4 656618 ;D5 19885037 ;D6 599219582
rn1bnqkr/p1ppppp1/8/1p5p/P4P1P/3N4/1PPPP1b1/RNBB1QKR w HAha - 0 9 ;D1 27 ;D2 752 ;D3 21735 ;D4 613194 ;D5 18862234 ;D6 547415271
1nbnqbkr/1p1p1ppp/r3p3/p1p5/P3P3/3Q4/1PPP1PPP/RNBN1BKR w HAh - 2 9 ;D1 33 ;D2 721 ;D3 24278 ;D4 572535 ;D5 19648535 ;D6 496023732
rnbnqkrb/2pppppp/1p6/p7/1PP5/4N2P/P2PPPP1/RNB1QKRB w GAg - 0 9 ;D1 23 ;D2 570 ;D3 14225 ;D4 374196 ;D5 10022614 ;D6 279545007
rbnnbq1r/ppppppkp/6p1/N7/4P3/P7/1PPP1PPP/RB1NBQKR w HA - 5 9 ;D1 27 ;D2 620 ;D3 18371 ;D4 440594 ;D5 13909432 ;D6 349478320
r1nbbqkr/pppppp1p/8/8/1n3Pp1/3N1QP1/PPPPP2P/RN1BB1KR w HAha - 0 9 ;D1 31 ;D2 791 ;D3 25431 ;D4 682579 ;D5 22408813 ;D6 636779732
rnq1bbkr/pp1p1ppp/2pnp3/8/7P/1QP5/PP1PPPPR/RNN1BBK1 w Aha - 2 9 ;D1 28 ;D2 559 ;D3 16838 ;D4 390887 ;D5 12242780 ;D6 315431511
rnnqbrkb/2ppppp1/1p1N4/p6p/4P3/8/PPPP1PPP/R1NQBKRB w GA - 0 9 ;D1 32 ;D2 638 ;D3 20591 ;D4 438792 ;D5 14395828 ;D6 331782223
rbnnq1br/pppp1kp1/4pp2/7p/PP6/2PP4/4PPPP/RBNNQKBR w HA - 0 9 ;D1 21 ;D2 521 ;D3 12201 ;D4 320429 ;D5 8239159 ;D6 227346638
rnnbqkbr/p2ppp2/7p/1pp3p1/2P2N2/8/PP1PPPPP/RN1BQKBR w HAha - 0 9 ;D1 25 ;D2 528 ;D3 13896 ;D4 326094 ;D5 9079829 ;D6 232750602
rnn1kbbr/ppppqp2/6p1/2N1p2p/P7/2P5/1P1PPPPP/RN1QKBBR w HAha - 2 9 ;D1 27 ;D2 801 ;D3 22088 ;D4 707078 ;D5 20334071 ;D6 682580976
rnnqkrbb/p1p1p1pp/1p3p2/8/3p2Q1/P1P1P3/1P1P1PPP/RNN1KRBB w FAfa - 0 9 ;D1 37 ;D2 1014 ;D3 34735 ;D4 998999 ;D5 32921537 ;D6 988770109
bbrnk1qr/1pppppp1/p4n1p/8/P2P2N1/8/1PP1PPPP/BBR1NKQR w HC - 1 9 ;D1 21 ;D2 481 ;D3 11213 ;D4 279993 ;D5 7015419 ;D6 187564853
brnbnkqr/1pp1p1p1/p2p1p2/7p/1P4PP/8/PBPPPP2/1RNBNKQR w HBhb - 0 9 ;D1 31 ;D2 743 ;D3 24260 ;D4 660177 ;D5 22391185 ;D6 653721389
br2kbqr/ppppp1pp/3n1p2/3P4/3n3P/3N4/PPP1PPP1/BR1NKBQR w HBhb - 3 9 ;D1 25 ;D2 872 ;D3 22039 ;D4 748726 ;D5 20281962 ;D6 685749952
br1nkqrb/ppppppp1/8/7p/4P3/n1P2PP1/PP1P3P/BRNNKQRB w GBgb - 0 9 ;D1 28 ;D2 607 ;D3 16934 ;D4 396483 ;D5 11607818 ;D6 294181806
rbbn1kqr/pp1pp1p1/2pn3p/5p2/5P2/1P1N4/PNPPP1PP/RBB2KQR w HAha - 1 9 ;D1 27 ;D2 725 ;D3 21543 ;D4 616082 ;D5 19239812 ;D6 581716972
rnbbnk1r/pp1ppp1p/6q1/2p5/PP4p1/4P3/2PP1PPP/RNBBNKQR w HAha - 1 9 ;D1 25 ;D2 1072 ;D3 26898 ;D4 1088978 ;D5 28469879 ;D6 1122703887
rnbnkbqr/1pp3pp/3p4/p3pp2/3P2P1/2N1N3/PPP1PP1P/R1B1KBQR w HAha - 0 9 ;D1 31 ;D2 1028 ;D3 32907 ;D4 1095472 ;D5 36025223 ;D6 1211187800
r1bnkqrb/1ppppppp/p3n3/8/6P1/4N3/PPPPPPRP/RNB1KQ1B w Aga - 1 9 ;D1 23 ;D2 457 ;D3 11416 ;D4 250551 ;D5 6666787 ;D6 159759052
rbn1bkqr/p1pp1pp1/1pn5/4p2p/7P/1PBP4/P1P1PPP1/RBNN1KQR w HAha - 0 9 ;D1 23 ;D2 470 ;D3 11649 ;D4 264274 ;D5 6963287 ;D6 172833738
rnnbbkqr/3ppppp/p7/1pp5/P6P/6P1/1PPPPP2/RNNBBKQR w HAha - 0 9 ;D1 26 ;D2 569 ;D3 15733 ;D4 375556 ;D5 11008114 ;D6 284485303
r1nk1bqr/1pppp1pp/2n5/p4p1b/5P2/1N4B1/PPPPP1PP/RN1K1BQR w HAha - 2 9 ;D1 25 ;D2 824 ;D3 21983 ;D4 738366 ;D5 20904119 ;D6 716170771
r1nkbqrb/p2pppp1/npp4p/8/4PP2/2N4P/PPPP2P1/R1NKBQRB w GAga - 0 9 ;D1 31 ;D2 548 ;D3 17480 ;D4 349633 ;D5 11469548 ;D6 255067638
rbnnkqbr/ppppp2p/5p2/6p1/2P1B3/P6P/1P1PPPP1/R1NNKQBR w HAha - 1 9 ;D1 31 ;D2 809 ;D3 24956 ;D4 680747 ;D5 21247414 ;D6 606221516
1r1bkqbr/pppp1ppp/2nnp3/8/2P5/N4P2/PP1PP1PP/1RNBKQBR w Hh - 0 9 ;D1 28 ;D2 810 ;D3 22844 ;D4 694599 ;D5 20188622 ;D6 636748147
rn1kqbbr/p1pppp1p/1p4p1/1n6/1P2P3/4Q2P/P1PP1PP1/RNNK1BBR w HAha - 1 9 ;D1 39 ;D2 848 ;D3 30100 ;D4 724426 ;D5 25594662 ;D6 659615710
rn1kqrbb/pppppppp/8/8/2nP2P1/1P2P3/P1P2P1P/RNNKQRBB w FAfa - 1 9 ;D1 29 ;D2 766 ;D3 21701 ;D4 567971 ;D5 16944425 ;D6 456898648
b1rnnkrq/bpppppp1/7p/8/1p6/2B5/PNPPPPPP/1BR1NKRQ w GCgc - 2 9 ;D1 25 ;D2 667 ;D3 17253 ;D4 472678 ;D5 12865247 ;D6 365621294
brnb1krq/pppppppp/8/5P2/2P1n2P/8/PP1PP1P1/BRNBNKRQ w GBgb - 1 9 ;D1 23 ;D2 620 ;D3 14882 ;D4 402561 ;D5 10776855 ;D6 300125003
b1nnkbrq/pr1pppp1/1p5p/2p5/P2N1P2/8/1PPPP1PP/BR1NKBRQ w GBg - 0 9 ;D1 24 ;D2 472 ;D3 12181 ;D4 267398 ;D5 7370758 ;D6 178605165
br1nkrqb/p1p1p1pp/3n4/1p1p1p2/5N1P/4P3/PPPP1PP1/BR1NKRQB w FBfb - 0 9 ;D1 24 ;D2 775 ;D3 19398 ;D4 624309 ;D5 16429837 ;D6 539767605
rbbnnkrq/p2pp1pp/2p5/5p2/1pPP1B2/P7/1P2PPPP/RB1NNKRQ w GAga - 0 9 ;D1 34 ;D2 921 ;D3 30474 ;D4 849933 ;D5 28095833 ;D6 806446436
rnbbnkr1/1p1ppp1p/2p3p1/p7/2Pq4/1P1P4/P2BPPPP/RN1BNKRQ w GAga - 2 9 ;D1 26 ;D2 1139 ;D3 29847 ;D4 1204863 ;D5 32825932 ;D6 1281760240
1rbnkbrq/pppppp2/n5pp/2P5/P7/4N3/1P1PPPPP/RNB1KBRQ w GAg - 2 9 ;D1 23 ;D2 574 ;D3 14146 ;D4 391413 ;D5 10203438 ;D6 301874034
1nbnkr1b/rppppppq/p7/7p/1P5P/3P2P1/P1P1PP2/RNBNKRQB w FAf - 1 9 ;D1 33 ;D2 823 ;D3 26696 ;D4 724828 ;D5 23266182 ;D6 672294132
rbn1bkrq/ppppp3/4n2p/5pp1/1PN5/2P5/P2PPPPP/RBN1BKRQ w GAga - 0 9 ;D1 27 ;D2 859 ;D3 24090 ;D4 796482 ;D5 23075785 ;D6 789152120
r1nbbkrq/1ppp2pp/2n2p2/p3p3/5P2/1N4BP/PPPPP1P1/RN1B1KRQ w GAga - 0 9 ;D1 25 ;D2 774 ;D3 20141 ;D4 618805 ;D5 16718577 ;D6 515864053
rnnkbbrq/1pppp1p1/5p2/7p/p6P/3N1P2/PPPPP1PQ/RN1KBBR1 w GAga - 0 9 ;D1 29 ;D2 673 ;D3 20098 ;D4 504715 ;D5 15545590 ;D6 416359581
r1nkbrqb/pppp1p2/n3p1p1/7p/2P2P2/1P6/P2PPQPP/RNNKBR1B w FAfa - 0 9 ;D1 27 ;D2 722 ;D3 21397 ;D4 593762 ;D5 18742426 ;D6 537750982
rbnnkr1q/1ppp2pp/p4p2/P2bp3/4P2P/8/1PPP1PP1/RBNNKRBQ w FAfa - 1 9 ;D1 26 ;D2 848 ;D3 23387 ;D4 741674 ;D5 21591790 ;D6 675163653
rn1bkrb1/1ppppp1p/pn4p1/8/P2q3P/3P4/NPP1PPP1/RN1BKRBQ w FAfa - 1 9 ;D1 22 ;D2 803 ;D3 18322 ;D4 632920 ;D5 15847763 ;D6 536419559
rn1krbbq/pppp1npp/4pp2/8/4P2P/3P2P1/PPP2P2/RNNKRBBQ w EAea - 1 9 ;D1 29 ;D2 810 ;D3 23968 ;D4 670500 ;D5 20361517 ;D6 575069358
rnn1rqbb/ppkp1pp1/2p1p2p/2P5/8/3P1P2/PP2P1PP/RNNKRQBB w EA - 0 9 ;D1 22 ;D2 506 ;D3 11973 ;D4 292344 ;D5 7287368 ;D6 189865944
bbqr1knr/pppppp1p/8/4n1p1/2P1P3/6P1/PPQP1P1P/BB1RNKNR w HDhd - 0 9 ;D1 26 ;D2 650 ;D3 18253 ;D4 481200 ;D5 14301029 ;D6 394943978
bq1bnknr/pprppp1p/8/2p3p1/4PPP1/8/PPPP3P/BQRBNKNR w HCh - 0 9 ;D1 24 ;D2 548 ;D3 14021 ;D4 347611 ;D5 9374021 ;D6 250988458
bqrnkb1r/1p2pppp/p1pp3n/5Q2/2P4P/5N2/PP1PPPP1/B1RNKB1R w HChc - 0 9 ;D1 46 ;D2 823 ;D3 33347 ;D4 673905 ;D5 26130444 ;D6 582880996
bq1rknrb/pppppp1p/4n3/6p1/4P1P1/3P1P2/PPP4P/BQRNKNRB w GCg - 0 9 ;D1 23 ;D2 618 ;D3 14815 ;D4 419474 ;D5 10606831 ;D6 315124518
q1brnknr/pp1pp1p1/8/2p2p1p/5b2/P4N2/1PPPP1PP/QBBRK1NR w hd - 0 9 ;D1 22 ;D2 675 ;D3 15778 ;D4 473994 ;D5 12077228 ;D6 368479752
qrbbnknr/1p1ppp1p/p1p5/8/1P2P1p1/3P1B2/P1P2PPP/QRB1NKNR w HBhb - 0 9 ;D1 32 ;D2 722 ;D3 24049 ;D4 569905 ;D5 19584539 ;D6 484814878
qrb1kbnr/p3pppp/2n5/1ppp4/7P/3P1P2/PPP1P1PR/QRBNKBN1 w Bhb - 0 9 ;D1 26 ;D2 831 ;D3 22606 ;D4 724505 ;D5 20500804 ;D6 662608969
qrbnknrb/ppp1pp2/6p1/7p/PPNp4/8/2PPPPPP/QRB1KNRB w GBgb - 0 9 ;D1 31 ;D2 840 ;D3 26762 ;D4 742772 ;D5 24422614 ;D6 701363800
qbrnbknr/pp1pp1pp/8/2p2p2/3Q4/PP6/2PPPPPP/1BRNBKNR w HChc - 0 9 ;D1 38 ;D2 1121 ;D3 39472 ;D4 1198438 ;D5 41108769 ;D6 1285503872
qr1bbk1r/pppppp1p/1n6/5np1/4B3/1PP5/P2PPPPP/QRN1BKNR w HBhb - 0 9 ;D1 25 ;D2 694 ;D3 16938 ;D4 472950 ;D5 12164609 ;D6 345122090
qrnkbbnr/1p1pp2p/p7/2p1Npp1/6P1/7P/PPPPPP2/QR1KBBNR w HBhb - 0 9 ;D1 27 ;D2 586 ;D3 16348 ;D4 393391 ;D5 11409633 ;D6 298054792
qrnkbnrb/pp1p1p2/2p1p1pp/4N3/P4P2/8/1PPPP1PP/QR1KBNRB w GBgb - 0 9 ;D1 32 ;D2 645 ;D3 20737 ;D4 460319 ;D5 15037464 ;D6 358531599
qbrnknbr/1pppppp1/p6p/8/1P6/3PP3/PQP2PPP/1BRNKNBR w HChc - 3 9 ;D1 26 ;D2 595 ;D3 16755 ;D4 415022 ;D5 12214768 ;D6 323518628
qrnbk1br/1ppppp1p/p5p1/8/4Pn2/4K1P1/PPPP1P1P/QRNB1NBR w hb - 0 9 ;D1 24 ;D2 609 ;D3 13776 ;D4 359415 ;D5 8538539 ;D6 230364479
qrnk1bbr/1pnp1ppp/p1p1p3/8/3Q4/1P1N3P/P1PPPPP1/1RNK1BBR w HBhb - 0 9 ;D1 43 ;D2 1106 ;D3 42898 ;D4 1123080 ;D5 41695761 ;D6 1113836402
qrnknrb1/pppppp2/8/6pp/4P2P/3P1P2/PbP3P1/QRNKNRBB w FBfb - 0 9 ;D1 24 ;D2 658 ;D3 17965 ;D4 488373 ;D5 14457245 ;D6 400971226
bbrqnrk1/ppp2ppp/7n/3pp3/8/P4N1N/1PPPPPPP/BBRQ1RK1 w - - 1 9 ;D1 22 ;D2 503 ;D3 12078 ;D4 310760 ;D5 8080951 ;D6 224960353
brqbnk1r/1ppp1ppp/8/p3pn2/8/2PP1P2/PP2PKPP/BRQBN1NR w hb - 1 9 ;D1 25 ;D2 745 ;D3 19387 ;D4 570459 ;D5 15520298 ;D6 460840861
brqnkbnr/pp2pp1p/3p4/2p5/5p2/3P3P/PPP1PPP1/B1RNKBNR w Hhb - 0 9 ;D1 19 ;D2 516 ;D3 10755 ;D4 312996 ;D5 6995034 ;D6 214340699
brq1kn1b/1ppppprp/2n3p1/p7/P1N5/6P1/1PPPPP1P/BRQNK1RB w GBb - 2 9 ;D1 29 ;D2 557 ;D3 16739 ;D4 352277 ;D5 10840256 ;D6 249999654
rbbq1k1r/ppp1pppp/7n/1n1p4/5P2/P2P4/1PPBP1PP/RB1QNKNR w HAha - 1 9 ;D1 25 ;D2 769 ;D3 20110 ;D4 638340 ;D5 17438715 ;D6 570893953
r1bbnk1r/qpp1pppp/p6n/3p4/1P6/5N1P/P1PPPPP1/RQBBK1NR w ha - 0 9 ;D1 23 ;D2 728 ;D3 18209 ;D4 587364 ;D5 16053564 ;D6 529082811
rqbnkbnr/1pp2p1p/3p4/p3p1p1/8/2P2P2/PP1PPNPP/RQBNKB1R w HAha - 0 9 ;D1 26 ;D2 772 ;D3 21903 ;D4 653704 ;D5 19571559 ;D6 593915677
r1bnknrb/pqppp1p1/1p5p/5p2/7P/3P2N1/PPP1PPP1/RQBNK1RB w GAga - 2 9 ;D1 27 ;D2 748 ;D3 20291 ;D4 597105 ;D5 16324542 ;D6 506453626
rbqnbknr/pp1pppp1/8/2p5/3P3p/5N1P/PPP1PPPR/RBQNBK2 w Aha - 0 9 ;D1 30 ;D2 859 ;D3 26785 ;D4 819631 ;D5 26363334 ;D6 842796987
rqnbbrk1/ppppppp1/8/5n1p/3P3P/2B3P1/PPP1PP2/RQNB1KNR w HA - 0 9 ;D1 22 ;D2 505 ;D3 11452 ;D4 283464 ;D5 7055215 ;D6 186760784
rqnkbbnr/pp2p1p1/8/2pp1p1p/3PPP2/8/PPP1N1PP/RQNKBB1R w HAha - 0 9 ;D1 28 ;D2 832 ;D3 23142 ;D4 722857 ;D5 20429246 ;D6 663183060
rqnkbnr1/pppp2bp/6p1/4pp2/1P2P3/3NN3/P1PP1PPP/RQ1KB1RB w GAga - 0 9 ;D1 28 ;D2 641 ;D3 18835 ;D4 459993 ;D5 14038570 ;D6 364210162
rbq2kbr/pppppppp/2n5/P7/3P1n2/2P5/1P2PPPP/RBQNKNBR w HA - 1 9 ;D1 31 ;D2 889 ;D3 27028 ;D4 766181 ;D5 24299415 ;D6 692180754
rq1bkn1r/ppppp2p/3n4/5pp1/2b3P1/1N1P1P2/PPP1P2P/RQ1BKNBR w HAha - 1 9 ;D1 28 ;D2 810 ;D3 22667 ;D4 657520 ;D5 18719949 ;D6 556282676
r1nknbbr/p2ppp1p/1pp3p1/8/1P6/4P3/P1PPNPPq/R1QKNBBR w HAha - 0 9 ;D1 24 ;D2 797 ;D3 22144 ;D4 719069 ;D5 21862776 ;D6 716521139
rqnknrbb/ppp1p3/5ppp/2Np4/2P5/4P3/PP1P1PPP/RQNK1RBB w FAfa - 0 9 ;D1 34 ;D2 686 ;D3 23277 ;D4 515541 ;D5 17664543 ;D6 423574794
1brnqknr/2p1pppp/p2p4/1P6/6P1/4Nb2/PP1PPP1P/BBR1QKNR w HChc - 1 9 ;D1 34 ;D2 1019 ;D3 32982 ;D4 1003103 ;D5 33322477 ;D6 1043293394
brn1qknr/1p1pppp1/pb5p/Q1p5/3P3P/8/PPP1PPPR/BRNB1KN1 w Bhb - 2 9 ;D1 32 ;D2 642 ;D3 20952 ;D4 464895 ;D5 15454749 ;D6 371861782
brnqkbnr/pppppp2/8/6pp/6P1/P2P1P2/1PP1P2P/BRNQKBNR w HBhb - 0 9 ;D1 20 ;D2 441 ;D3 9782 ;D4 240220 ;D5 5770284 ;D6 153051835
2nqknrb/1rpppppp/5B2/pp6/1PP1b3/3P4/P3PPPP/1RNQKNRB w GBg - 1 9 ;D1 35 ;D2 1042 ;D3 36238 ;D4 1101159 ;D5 38505058 ;D6 1202668717
rb1nqknr/1pp1pppp/8/3p4/p2P4/6PN/PPPQPP1P/RBBN1K1R w HAha - 0 9 ;D1 29 ;D2 692 ;D3 21237 ;D4 555018 ;D5 17820605 ;D6 497251206
rnbbqknr/pppp4/5p2/4p1pp/P7/2N2PP1/1PPPP2P/R1BBQKNR w HAha - 0 9 ;D1 23 ;D2 595 ;D3 14651 ;D4 415772 ;D5 10881112 ;D6 329010121
rn1qkbnr/p1p1pp1p/bp4p1/3p4/1P6/4P3/P1PP1PPP/RNBQKBNR w HAha - 0 9 ;D1 30 ;D2 794 ;D3 24319 ;D4 690811 ;D5 21657601 ;D6 647745807
r1bqk1rb/pppnpppp/5n2/3p4/2P3PP/2N5/PP1PPP2/R1BQKNRB w GAga - 1 9 ;D1 32 ;D2 821 ;D3 27121 ;D4 733155 ;D5 24923473 ;D6 710765657
rbnqbknr/1p1ppp1p/6p1/p1p5/7P/3P4/PPP1PPP1/RBNQBKNR w HAha - 0 9 ;D1 24 ;D2 720 ;D3 18842 ;D4 575027 ;D5 15992882 ;D6 501093456
r1qbbk1r/pp1ppppp/n1p5/5n2/B1P3P1/8/PP1PPP1P/RNQ1BKNR w HAha - 0 9 ;D1 27 ;D2 831 ;D3 22293 ;D4 698986 ;D5 19948650 ;D6 637973209
rnqkbb1r/p1pppppp/8/8/1p4n1/PP4PP/2PPPP2/RNQKBBNR w HAha - 0 9 ;D1 18 ;D2 463 ;D3 9519 ;D4 256152 ;D5 6065231 ;D6 172734380
rnqk1nrb/pppbpp2/7p/3p2p1/4B3/2N1N1P1/PPPPPP1P/R1QKB1R1 w GAga - 0 9 ;D1 34 ;D2 1171 ;D3 38128 ;D4 1318217 ;D5 42109356 ;D6 1465473753
rbnqknbr/1pp1ppp1/3p4/7p/p2P2PP/2P5/PP2PP2/RBNQKNBR w HAha - 0 9 ;D1 32 ;D2 867 ;D3 28342 ;D4 798722 ;D5 26632459 ;D6 781067145
rn1bknbr/pq2pppp/1p6/2pp4/P7/1P1P4/2PNPPPP/RNQBK1BR w HAha - 0 9 ;D1 24 ;D2 627 ;D3 16652 ;D4 462942 ;D5 13200921 ;D6 385193532
r1qk1bbr/ppp1pp1p/2np1n2/6p1/2PP4/3BP3/PP3PPP/RNQKN1BR w HAha - 2 9 ;D1 31 ;D2 992 ;D3 30213 ;D4 986631 ;D5 30397368 ;D6 1011631987
r1qknrbb/pppp1p2/2n3p1/4p2p/8/QPP5/P1NPPPPP/RN1K1RBB w FAfa - 2 9 ;D1 30 ;D2 702 ;D3 21563 ;D4 532939 ;D5 16813114 ;D6 438096194
bbkr1qnr/2pppppp/2n5/pp6/8/PPN5/1BPPPPPP/1BR1KQNR w HC - 2 9 ;D1 25 ;D2 573 ;D3 15183 ;D4 380910 ;D5 10554668 ;D6 283975400
1rnbkqnr/1bpppppp/1p6/7P/p2P4/5P2/PPP1P1P1/BRNBKQNR w HBhb - 0 9 ;D1 21 ;D2 503 ;D3 11790 ;D4 301084 ;D5 7679979 ;D6 207799378
brnkqbnr/2p1pppp/1p6/3p4/1pP5/P6P/3PPPP1/BRNKQBNR w HBhb - 0 9 ;D1 28 ;D2 743 ;D3 21054 ;D4 587192 ;D5 17354516 ;D6 507176753
br1kqnrb/npp1pppp/8/3p4/p4N2/PP6/2PPPPPP/BR1KQNRB w GBgb - 0 9 ;D1 31 ;D2 808 ;D3 25585 ;D4 698475 ;D5 22376575 ;D6 640362920
rbbnkq1r/pppppp1p/7n/6p1/P5P1/2P2N2/1P1PPP1P/RBBNKQ1R w HAha - 1 9 ;D1 29 ;D2 580 ;D3 17585 ;D4 404831 ;D5 12730970 ;D6 325226128
rnbbk1nr/pp2qppp/2ppp3/8/3P4/P1N4N/1PP1PPPP/R1BBKQ1R w HAha - 0 9 ;D1 29 ;D2 838 ;D3 24197 ;D4 721884 ;D5 21100580 ;D6 646624429
rnbk1b1r/ppppn1pp/4pp2/7q/7P/P5PB/1PPPPP2/RNBKQ1NR w HAha - 3 9 ;D1 20 ;D2 729 ;D3 16633 ;D4 576199 ;D5 14507076 ;D6 498621813
r2kqnrb/pbppppp1/np5p/8/4Q1P1/3P4/PPP1PP1P/RNBK1NRB w GAga - 2 9 ;D1 47 ;D2 1219 ;D3 55009 ;D4 1486353 ;D5 65239153 ;D6 1834391369
rbnkbq1r/p1p2ppp/1p2pn2/3p4/P3P3/3P4/1PP1KPPP/RBN1BQNR w ha - 2 9 ;D1 29 ;D2 923 ;D3 27179 ;D4 883866 ;D5 26202752 ;D6 868565895
rk1bb1nr/ppppqppp/n7/1N2p3/6P1/7N/PPPPPP1P/R1KBBQ1R w HA - 6 9 ;D1 27 ;D2 703 ;D3 19478 ;D4 559525 ;D5 16049807 ;D6 492966455
rnkqbbnr/p1ppp2p/1p4p1/8/1B3p1P/2NP4/PPP1PPP1/R1KQ1BNR w HAha - 0 9 ;D1 29 ;D2 610 ;D3 18855 ;D4 438277 ;D5 14020041 ;D6 355083962
rnkqb1rb/pp1p1ppp/4p3/2P3n1/8/1PP5/P3PPPP/RNKQBNRB w GAga - 0 9 ;D1 29 ;D2 675 ;D3 20699 ;D4 535821 ;D5 17000613 ;D6 476598337
rb1kqnbr/pp1pp1p1/1np2p2/7p/P1P3PP/8/1P1PPP2/RBNKQNBR w HAha - 0 9 ;D1 31 ;D2 1077 ;D3 33661 ;D4 1183381 ;D5 37415304 ;D6 1328374620
rnkbq1br/ppp2ppp/3p4/Q3p1n1/5P2/3P2P1/PPP1P2P/RNKB1NBR w HAha - 0 9 ;D1 41 ;D2 1201 ;D3 46472 ;D4 1420367 ;D5 52991625 ;D6 1675608008
rn1qnbbr/pp2pppp/2ppk3/8/2PP4/3Q1N2/PP2PPPP/RNK2BBR w HA - 1 9 ;D1 34 ;D2 666 ;D3 22474 ;D4 472299 ;D5 15860369 ;D6 353831792
rnkqnr1b/ppppp1pp/5p2/8/Q1P2P2/8/PP1P2PP/RbK1NRBB w FAfa - 0 9 ;D1 36 ;D2 876 ;D3 31987 ;D4 788580 ;D5 29022529 ;D6 736717252
bbrn1nqr/ppp1k1pp/5p2/3pp3/7P/3PN3/PPP1PPP1/BBRK1NQR w - - 1 9 ;D1 24 ;D2 583 ;D3 15063 ;D4 383532 ;D5 10522064 ;D6 280707118
brnbkn1r/1pppp1p1/4q3/p4p1p/7P/1N3P2/PPPPP1PQ/BR1BKN1R w HBhb - 2 9 ;D1 27 ;D2 935 ;D3 26120 ;D4 885699 ;D5 26000648 ;D6 873063158
br1knbqr/pp2p1pp/1n6/2pp1p2/6P1/2P4B/PP1PPPQP/BRNKN2R w HBhb - 0 9 ;D1 27 ;D2 681 ;D3 19202 ;D4 510687 ;D5 14954779 ;D6 415624943
brnk1qrb/p1ppppp1/1p5p/8/P3n3/1N4P1/1PPPPPRP/BR1KNQ1B w Bgb - 0 9 ;D1 22 ;D2 638 ;D3 13991 ;D4 412346 ;D5 9760752 ;D6 293499724
rbbnknqr/pppp3p/5pp1/8/1P1pP3/7P/P1P2PP1/RBBNKNQR w HAha - 0 9 ;D1 29 ;D2 756 ;D3 21616 ;D4 614074 ;D5 17602252 ;D6 528140595
1nbbknqr/rpp1ppp1/1Q1p3p/p7/2P2PP1/8/PP1PP2P/RNBBKN1R w HAh - 2 9 ;D1 37 ;D2 977 ;D3 34977 ;D4 944867 ;D5 33695089 ;D6 940198007
rnb2bqr/ppkpppp1/3n3p/2p5/6PP/2N2P2/PPPPP3/R1BKNBQR w HA - 2 9 ;D1 30 ;D2 647 ;D3 20365 ;D4 467780 ;D5 15115531 ;D6 369257622
rn1k1qrb/p1pppppp/bp6/8/4n3/P4BPP/1PPPPP2/RNBKNQR1 w GAga - 2 9 ;D1 22 ;D2 670 ;D3 14998 ;D4 451517 ;D5 11199653 ;D6 339919682
rb2bnqr/nppkpppp/3p4/p7/1P6/P2N2P1/2PPPP1P/RB1KBNQR w HA - 3 9 ;D1 22 ;D2 479 ;D3 11475 ;D4 264739 ;D5 6831555 ;D6 167329117
r1kbb1qr/2pppppp/np2n3/p7/2P3P1/8/PP1PPPQP/RNKBBN1R w HAha - 1 9 ;D1 32 ;D2 723 ;D3 23953 ;D4 581832 ;D5 19472074 ;D6 504622114
rnknbb1r/p1ppp1pp/8/1p1P1p1q/8/P1P5/1P2PPPP/RNKNBBQR w HAha - 1 9 ;D1 19 ;D2 607 ;D3 12733 ;D4 417451 ;D5 9753617 ;D6 325177085
rnkn1qrb/pp1bp1pp/2p5/1N1p1p2/8/2P5/PPKPPPPP/R2NBQRB w ga - 2 9 ;D1 27 ;D2 533 ;D3 14549 ;D4 330747 ;D5 9206957 ;D6 232664675
r1nknqbr/pp2p1pp/2p2p2/3p4/6P1/PP1P4/2P1PP1b/RBNKNQBR w HAha - 0 9 ;D1 20 ;D2 582 ;D3 13777 ;D4 409166 ;D5 10708639 ;D6 326565393
rnkb1qbr/p1pp1p1p/1p2pn2/1Q4p1/4P3/N4P2/PPPP2PP/R1KBN1BR w HAha - 0 9 ;D1 40 ;D2 1038 ;D3 39356 ;D4 1051441 ;D5 39145902 ;D6 1079612614
rn2qbbr/1pkppp1p/p3n1p1/8/8/2P2P2/PP1PP1PP/RNKN1BBR w HA - 0 9 ;D1 24 ;D2 605 ;D3 14888 ;D4 385964 ;D5 9687507 ;D6 260874068
rn1nqrbb/p1kppp1p/8/1pp3p1/1P6/2N1P3/P1PP1PPP/RK1NQRBB w - - 0 9 ;D1 21 ;D2 540 ;D3 12489 ;D4 337997 ;D5 8436136 ;D6 237525904
bbrnknrq/1pp3pp/p2p1p2/4p3/P7/1P2N3/2PPPPPP/BBRN1RKQ w gc - 0 9 ;D1 24 ;D2 527 ;D3 13900 ;D4 326175 ;D5 9139962 ;D6 226253685
brnb1nrq/pppp1kpp/4p3/8/5p1P/P1P3P1/1P1PPP2/BRNBKNRQ w GB - 1 9 ;D1 29 ;D2 773 ;D3 23904 ;D4 638768 ;D5 20503775 ;D6 560338709
br1k1brq/ppppp2p/1n1n1pp1/8/P1P5/3P2P1/1P2PP1P/BRNKNBRQ w GBgb - 0 9 ;D1 28 ;D2 811 ;D3 23550 ;D4 664880 ;D5 19913758 ;D6 565143976
1r1knrqb/n1pppppp/p1b5/1p6/8/3N1P2/PPPPP1PP/BRNK1RQB w fb - 3 9 ;D1 29 ;D2 753 ;D3 23210 ;D4 620019 ;D5 20044474 ;D6 558383603
rbbnk1rq/pppppppp/8/3Pn3/8/4P1P1/PPP2P1P/RBBNKNRQ w GAga - 1 9 ;D1 22 ;D2 551 ;D3 12619 ;D4 324608 ;D5 8204171 ;D6 217689974
rnbbk1rq/2pppp1p/p3n1p1/1p6/P3N3/8/1PPPPPPP/RNBB1KRQ w ga - 0 9 ;D1 26 ;D2 742 ;D3 20061 ;D4 599527 ;D5 16787080 ;D6 525678162
rnbkn1rq/ppppppb1/6p1/7p/2B2P2/1P2P3/P1PP2PP/RNBKN1RQ w GAga - 1 9 ;D1 28 ;D2 799 ;D3 23210 ;D4 689436 ;D5 20755098 ;D6 639632905
rn1knrqb/p2pppp1/b1p5/1p5p/2P2P2/1P6/P2PP1PP/RNBKNRQB w FAfa - 1 9 ;D1 30 ;D2 579 ;D3 18481 ;D4 397545 ;D5 13257198 ;D6 311282465
rbnkbnrq/pp2p1Np/2p2p2/8/3p4/8/PPPPPPPP/RBNKBR1Q w Aga - 0 9 ;D1 23 ;D2 670 ;D3 16435 ;D4 501883 ;D5 13012378 ;D6 411860744
rk1bbnrq/ppp1pppp/n7/3p4/5P2/3P2NP/PPP1P1P1/RNKBB1RQ w GA - 0 9 ;D1 26 ;D2 597 ;D3 16238 ;D4 402506 ;D5 11269462 ;D6 296701249
r1knbbrq/pppp2p1/2n1p2p/5p2/4P3/P1PP4/1P3PPP/RNKNBBRQ w GAga - 1 9 ;D1 20 ;D2 596 ;D3 13091 ;D4 399069 ;D5 9416862 ;D6 293659781
rnknbrqb/p1p1pp1p/3p4/1p1N2p1/8/N7/PPPPPPPP/1RK1BRQB w Ffa - 0 9 ;D1 26 ;D2 724 ;D3 18942 ;D4 552040 ;D5 15257204 ;D6 461293885
rbnknrb1/1p1ppp1p/p1p3p1/8/1P3P2/1R6/PqPPP1PP/RBNKN1BQ w Afa - 0 9 ;D1 31 ;D2 1183 ;D3 34723 ;D4 1289502 ;D5 38722152 ;D6 1421492227
rnkbnrbq/2p1ppp1/p7/1p1p3p/3P4/1P4P1/P1P1PP1P/RNKBNRBQ w FAfa - 0 9 ;D1 24 ;D2 506 ;D3 12748 ;D4 301464 ;D5 8086100 ;D6 207129256
r1knrbbq/pp1ppppp/2p1n3/8/2P3P1/P7/1PKPPP1P/RN1NRBBQ w ea - 0 9 ;D1 28 ;D2 570 ;D3 16037 ;D4 352471 ;D5 10278695 ;D6 242592363
rnknrq1b/ppp1p1p1/4b3/3p1p1p/6P1/P4P2/1PPPPQ1P/RNKNR1BB w EAea - 2 9 ;D1 30 ;D2 739 ;D3 23124 ;D4 594962 ;D5 19252739 ;D6 521629794
bbqr1krn/pppp1p1p/5n2/4p1p1/3P4/P3QP2/1PP1P1PP/BB1RNKRN w GDgd - 0 9 ;D1 31 ;D2 799 ;D3 25627 ;D4 674913 ;D5 22172123 ;D6 609277274
bq1b1krn/pp1ppppp/3n4/2r5/3p3N/6N1/PPP1PPPP/BQRB1KR1 w GCg - 2 9 ;D1 21 ;D2 798 ;D3 18571 ;D4 688429 ;D5 17546069 ;D6 647165916
bqrnkbrn/2pp1pp1/p7/1p2p2p/1P6/4N3/P1PPPPPP/BQR1KBRN w GCgc - 0 9 ;D1 27 ;D2 783 ;D3 22327 ;D4 670798 ;D5 20059741 ;D6 624462073
bqr1krnb/1np1pppp/8/pp1p4/8/2P2N2/PP1PPPPP/BQRNKR1B w FCfc - 0 9 ;D1 28 ;D2 636 ;D3 18874 ;D4 461104 ;D5 14237097 ;D6 372181570
qbb1rkrn/1ppppppp/p7/7n/8/P2P4/1PP1PPPP/QBBRNKRN w Gg - 0 9 ;D1 25 ;D2 547 ;D3 13837 ;D4 332918 ;D5 8849383 ;D6 229112926
1rbbnkrn/p1p1pp1p/2q5/1p1p2p1/8/2P3P1/PP1PPP1P/QRBBNKRN w GBgb - 2 9 ;D1 24 ;D2 1010 ;D3 24370 ;D4 983770 ;D5 24328258 ;D6 961371180
qrb1kbrn/ppp1p2p/4npp1/3p4/8/1PP4P/PR1PPPP1/Q1BNKBRN w Ggb - 1 9 ;D1 18 ;D2 451 ;D3 9291 ;D4 247310 ;D5 5568106 ;D6 155744022
qr2krnb/p1p1pppp/b1np4/1p6/3NP3/7P/PPPP1PP1/QRBNKR1B w FBfb - 2 9 ;D1 25 ;D2 667 ;D3 17081 ;D4 476030 ;D5 12458875 ;D6 361495148
qbrnbkrn/ppp3pp/3p4/5p2/2P1pP2/6PP/PP1PP3/QBRNBKRN w GCgc - 0 9 ;D1 24 ;D2 650 ;D3 16835 ;D4 445263 ;D5 12187382 ;D6 326834539
qrnb1krn/ppp1p1pp/5p2/2Np4/b2P4/2P5/PP2PPPP/QR1BBKRN w GBgb - 0 9 ;D1 27 ;D2 641 ;D3 17490 ;D4 432041 ;D5 12103076 ;D6 310695797
qrnkbbrn/pp2pp2/8/2pp2pp/6PP/3P4/PPPKPP2/QRN1BBRN w gb - 0 9 ;D1 22 ;D2 554 ;D3 13116 ;D4 357404 ;D5 9014737 ;D6 258925091
qrnkbrnb/p1p1ppp1/1p6/3p4/3P3p/5N1P/PPP1PPP1/QRNKBR1B w FBfb - 0 9 ;D1 24 ;D2 529 ;D3 13205 ;D4 318722 ;D5 8295874 ;D6 213856651
qbr1krbn/1pppp1pp/p7/5pn1/2PP4/8/PPB1PPPP/Q1RNKRBN w FCfc - 0 9 ;D1 26 ;D2 831 ;D3 21651 ;D4 696830 ;D5 18961456 ;D6 621884383
1rnbkrbn/1qp1pppp/3p4/pp6/4P3/1NP4P/PP1P1PP1/QR1BKRBN w FBfb - 0 9 ;D1 24 ;D2 597 ;D3 15089 ;D4 404761 ;D5 10832084 ;D6 307793179
q1rkrbbn/ppp1pppp/8/3p4/1PnP4/P7/1RP1PPPP/Q1NKRBBN w Ee - 1 9 ;D1 20 ;D2 520 ;D3 10769 ;D4 278067 ;D5 6452205 ;D6 170268300
qrnkrn1b/ppppp1pp/4b3/7P/6p1/P7/1PPPPP2/QRNKRNBB w EBeb - 0 9 ;D1 26 ;D2 566 ;D3 15623 ;D4 381312 ;D5 10940750 ;D6 287987207
bbr1nkrn/ppp1pppp/3q4/3p4/8/P7/1PPPPPPP/BBRQNRKN w gc - 5 9 ;D1 19 ;D2 661 ;D3 13895 ;D4 460396 ;D5 10870247 ;D6 356399665
brqbnkrn/pp1pp2p/5pp1/2p5/4P3/P2P1N2/1PP2PPP/BRQB1KRN w GBgb - 0 9 ;D1 27 ;D2 679 ;D3 19916 ;D4 527306 ;D5 16391730 ;D6 455940859
2qnkbrn/p1pppppp/8/1r6/1p2bP2/7N/PPPPP1PP/BR1QKBRN w GBg - 4 9 ;D1 18 ;D2 774 ;D3 15713 ;D4 635461 ;D5 14371755 ;D6 559579332
r1qnkr1b/p1pppppp/7n/1p6/8/1P3b1N/PRPPPPPP/B1QNK1RB w f - 5 9 ;D1 21 ;D2 677 ;D3 15437 ;D4 501520 ;D5 12463801 ;D6 410795298
rbbqn1rn/pppp1pp1/3k4/4p2Q/2PPP3/8/PP3PPP/RBB1NKRN w GA - 1 9 ;D1 40 ;D2 742 ;D3 28757 ;D4 579833 ;D5 21852196 ;D6 471452088
rqbbnkrn/3pppp1/p1p4p/1p6/5P2/P2N4/1PPPP1PP/RQBBK1RN w ga - 0 9 ;D1 23 ;D2 665 ;D3 16400 ;D4 492544 ;D5 12794736 ;D6 396640086
r2nkbrn/pp2pppp/8/2ppqb2/2P3P1/5P2/PP1PPN1P/RQB1KBRN w GAga - 3 9 ;D1 28 ;D2 1108 ;D3 31164 ;D4 1194581 ;D5 34780853 ;D6 1292405738
rqbnk1nb/p1pppr1p/5p2/1p4p1/1PP1P3/8/P2P1PPP/RQBNKRNB w FAa - 1 9 ;D1 26 ;D2 650 ;D3 18208 ;D4 491403 ;D5 14565370 ;D6 416833400
rbqnb1rn/p1pp1kpp/1p2pp2/8/4P2P/P5P1/1PPP1P2/RBQNBKRN w GA - 0 9 ;D1 20 ;D2 437 ;D3 9423 ;D4 222154 ;D5 5282124 ;D6 132309824
rqnbbkrn/p1p1pppp/3p4/1p5B/8/1P1NP3/P1PP1PPP/RQ2BKRN w GAga - 0 9 ;D1 30 ;D2 606 ;D3 18382 ;D4 422491 ;D5 12989786 ;D6 326601372
rqnkbbr1/ppppp1pp/5p2/7n/8/2PNP2P/PP1P1PP1/RQ1KBBRN w GAga - 1 9 ;D1 23 ;D2 482 ;D3 12506 ;D4 297869 ;D5 8430874 ;D6 217797292
r1nkbrnb/2ppppp1/1q6/pp5p/1P6/P3P3/2PPKPPP/RQN1BRNB w fa - 2 9 ;D1 25 ;D2 827 ;D3 21518 ;D4 701071 ;D5 19290675 ;D6 632892337
rbqnkrbn/p1ppppp1/7p/1p6/7P/2N1P3/PPPP1PPB/RBQ1KR1N w FAfa - 1 9 ;D1 30 ;D2 627 ;D3 18566 ;D4 440217 ;D5 12976682 ;D6 337377291
r1nbkrbn/p1qp1ppp/8/1pp1p3/2P1P3/6P1/PP1PBP1P/RQN1KRBN w FAfa - 2 9 ;D1 22 ;D2 616 ;D3 14503 ;D4 431199 ;D5 10850952 ;D6 335943324
rqnkr1bn/ppp1ppb1/3p2pp/8/P7/2P2P2/1PKPP1PP/RQN1RBBN w ea - 1 9 ;D1 31 ;D2 679 ;D3 21365 ;D4 493500 ;D5 15661072 ;D6 379844460
r2krnbb/qppp1ppp/1n6/p3p3/PP6/4N3/N1PPPPPP/RQ1KR1BB w EAea - 4 9 ;D1 24 ;D2 645 ;D3 17054 ;D4 487028 ;D5 13837270 ;D6 416239106
bbr1qk1n/1ppppp1p/2n5/p7/P7/1P2P3/2PP1PrP/1BRNQKRN w GCc - 0 9 ;D1 18 ;D2 520 ;D3 10680 ;D4 304462 ;D5 7215306 ;D6 207612575
brnbq1rn/2ppppkp/p5p1/1p6/8/1BP3P1/PP1PPP1P/BRN1QRKN w - - 0 9 ;D1 21 ;D2 625 ;D3 13989 ;D4 419667 ;D5 9929336 ;D6 300902534
brn1kbrn/pp2p1pp/3p4/q1p2p2/2P4P/6P1/PP1PPP2/BRNQKBRN w GBgb - 1 9 ;D1 18 ;D2 477 ;D3 10205 ;D4 273925 ;D5 6720181 ;D6 187205941
brn1krnb/p3pppp/1qpp4/1p6/2P3P1/1P6/P2PPP1P/BRNQKRNB w FBfb - 1 9 ;D1 30 ;D2 835 ;D3 24761 ;D4 716151 ;D5 21806428 ;D6 654487872
r1b1qkrn/1p1ppppp/p1p1n3/8/4P3/1PN5/P1PPQPPb/RBB2KRN w GAga - 0 9 ;D1 28 ;D2 825 ;D3 24536 ;D4 716585 ;D5 22079005 ;D6 647939781
r1bbqk1n/p1pppprp/n7/1p4p1/5P2/2N3N1/PPPPP1PP/1RBBQKR1 w Ga - 4 9 ;D1 25 ;D2 545 ;D3 14657 ;D4 358854 ;D5 10271111 ;D6 273864588
rnbqkbrn/p1pp1pp1/4p3/7p/2p4P/2P5/PP1PPPP1/R1BQKBRN w GAga - 0 9 ;D1 17 ;D2 445 ;D3 9076 ;D4 255098 ;D5 5918310 ;D6 174733195
rnbqkrnb/1p1pp1p1/2p4p/p4p2/3P2P1/7N/PPPBPP1P/RN1QKR1B w FAfa - 0 9 ;D1 34 ;D2 746 ;D3 25319 ;D4 623133 ;D5 21285553 ;D6 569141201
rbnqbkr1/1ppppp2/p5n1/6pp/4P3/1N6/PPPP1PPP/RBQ1BRKN w ga - 2 9 ;D1 18 ;D2 466 ;D3 9683 ;D4 260864 ;D5 6051500 ;D6 170135726
rnqb1krn/ppppp1p1/7p/7b/P1P2pPP/8/1P1PPP2/RNQBBKRN w GAga - 0 9 ;D1 24 ;D2 575 ;D3 15400 ;D4 385825 ;D5 11039042 ;D6 291243811
rnqkbbr1/p1pp1ppp/4p3/1p6/P3P2n/5P2/1PPP1NPP/RNQKBBR1 w GAga - 2 9 ;D1 27 ;D2 803 ;D3 22883 ;D4 694449 ;D5 20666099 ;D6 638696065
rn1kbrnb/1qppp1pp/1p6/p4p2/1B1P4/1P5N/P1P1PPPP/RNQK1R1B w FAfa - 0 9 ;D1 37 ;D2 1209 ;D3 43015 ;D4 1425600 ;D5 49748034 ;D6 1671593862
rbnqkrbn/Bppp1p2/p5pp/4p3/5P2/6PP/PPPPP3/RBNQKR1N w FAfa - 0 9 ;D1 29 ;D2 720 ;D3 20434 ;D4 534148 ;D5 15384362 ;D6 421343249
rnqbkr1n/1p1ppbpp/3p1p2/p7/8/1P6/P1PPPPPP/R1QBKRBN w FAfa - 0 9 ;D1 20 ;D2 657 ;D3 14424 ;D4 492678 ;D5 11843134 ;D6 413965054
rnqkrb1n/ppppp3/6p1/5p1p/2b2P2/P1N5/1PPPP1PP/RQ1KRBBN w EAea - 1 9 ;D1 28 ;D2 749 ;D3 20684 ;D4 543151 ;D5 15379233 ;D6 417191461
rnqk1nbb/1pp2ppp/3pr3/p3p3/3P1P2/2N3N1/PPP1P1PP/R1QKR1BB w EAa - 1 9 ;D1 29 ;D2 883 ;D3 26412 ;D4 815098 ;D5 25144295 ;D6 789705382
bbr1kqrn/p1p1ppp1/1p2n2p/3p4/1P1P4/2N5/P1P1PPPP/BBR1KQRN w GCgc - 0 9 ;D1 22 ;D2 485 ;D3 11475 ;D4 271271 ;D5 6825123 ;D6 171793012
brnbkq1n/ppp1ppr1/7p/3p2p1/2P3PP/8/PPBPPP2/BRN1KQRN w GBb - 2 9 ;D1 30 ;D2 634 ;D3 19017 ;D4 442537 ;D5 13674310 ;D6 345386924
brnkqbr1/1pppp1pp/5p2/p7/P1P1P2n/8/1P1P1PP1/BRNKQBRN w GBgb - 0 9 ;D1 21 ;D2 504 ;D3 11672 ;D4 305184 ;D5 7778289 ;D6 217596497
b1rkqrnb/p1ppp1pp/1p1n4/5p2/5P2/PN5P/1PPPP1P1/BR1KQRNB w FBf - 0 9 ;D1 23 ;D2 688 ;D3 17259 ;D4 531592 ;D5 14228372 ;D6 451842354
1bbnkqrn/rppppp2/p5p1/7p/7P/P1P1P3/1P1P1PP1/RBBNKQRN w GAg - 1 9 ;D1 25 ;D2 450 ;D3 12391 ;D4 263946 ;D5 7752404 ;D6 185393913
rnbbkqr1/1pppppp1/7p/p3n3/PP5P/8/1BPPPPP1/RN1BKQRN w GAga - 0 9 ;D1 23 ;D2 543 ;D3 12224 ;D4 305812 ;D5 7549008 ;D6 199883770
r1bkqbrn/ppppp1pp/8/5p2/3nPP2/1P4N1/P1PP2PP/RNBKQBR1 w GAga - 1 9 ;D1 27 ;D2 751 ;D3 21158 ;D4 600417 ;D5 17989920 ;D6 527273615
rnbkqr1b/1p1pp1pp/p4p1n/2p5/1P5P/N4P2/P1PPP1P1/R1BKQRNB w FAfa - 0 9 ;D1 21 ;D2 498 ;D3 11738 ;D4 302278 ;D5 7808375 ;D6 216224115
rbnkbqrn/p1p3pp/1p1p4/B3pp2/3P2P1/6N1/PPP1PP1P/RBNK1QR1 w GAga - 0 9 ;D1 34 ;D2 977 ;D3 33464 ;D4 961128 ;D5 33318567 ;D6 978991050
r1kbbqrn/ppp3pp/2np1p2/1P2p3/3P1P2/8/P1P1P1PP/RNKBBQRN w GAga - 0 9 ;D1 32 ;D2 920 ;D3 28916 ;D4 844881 ;D5 26763259 ;D6 797524786
rk1qbbrn/p2npppp/1p6/2p4Q/8/4P3/PPPP1PPP/RNK1B1RN w GA - 2 9 ;D1 35 ;D2 657 ;D3 22359 ;D4 495406 ;D5 16662477 ;D6 419496845
rnk1brnb/pp1p1pp1/8/q1p1p2p/5P2/NP6/P1PPP1PP/R1KQBRNB w FAfa - 1 9 ;D1 26 ;D2 774 ;D3 20215 ;D4 610661 ;D5 16987110 ;D6 523437649
rb1kqrbn/npp1ppp1/p7/3P3p/2PP4/8/PP3PPP/RBNKQRBN w FAfa - 0 9 ;D1 35 ;D2 775 ;D3 27395 ;D4 661118 ;D5 23983464 ;D6 625669222
rnkb1rbn/pp1p2pp/8/2p1pp1q/P6P/1PN5/2PPPPP1/R1KBQRBN w FAfa - 1 9 ;D1 22 ;D2 899 ;D3 21188 ;D4 850597 ;D5 21518343 ;D6 857951339
rnkqrbbn/1pppp1p1/8/p2N1p1p/2P4P/8/PP1PPPP1/R1KQRBBN w EAea - 0 9 ;D1 29 ;D2 585 ;D3 17571 ;D4 393221 ;D5 12238776 ;D6 299752383
rnk1r1bb/pp1ppppp/1q4n1/2p5/5P1P/3PP3/PPP3P1/RNKQRNBB w EAea - 1 9 ;D1 27 ;D2 884 ;D3 24613 ;D4 811915 ;D5 23698701 ;D6 790239502
bbrnkrqn/1ppp1p2/6pp/p3p3/5PP1/2PB4/PP1PP2P/B1RNKRQN w FCfc - 0 9 ;D1 37 ;D2 693 ;D3 25425 ;D4 550527 ;D5 20138432 ;D6 481498664
b1rbkrqn/ppp2ppp/1n2p3/3p4/6P1/2PP4/PP2PP1P/BRNBKRQN w FBf - 1 9 ;D1 21 ;D2 463 ;D3 10610 ;D4 253204 ;D5 6307276 ;D6 159025909
brnkrb1n/1pp1p1pp/3p4/p1Nq1p2/2P5/8/PP1PPPPP/BRK1RBQN w eb - 2 9 ;D1 27 ;D2 725 ;D3 17842 ;D4 496072 ;D5 12604078 ;D6 362747791
brn1r1nb/ppppkppp/4p3/8/2PP1P2/8/PP1KP1PP/BRN1RQNB w - - 1 9 ;D1 25 ;D2 623 ;D3 16874 ;D4 426659 ;D5 12290985 ;D6 317097424
rbb1krqn/1pp1pp1p/p3n1p1/3pP3/8/1PN5/P1PP1PPP/RBB1KRQN w FAfa d6 0 9 ;D1 23 ;D2 529 ;D3 12641 ;D4 310277 ;D5 7861413 ;D6 202594556
r1bbkrqn/p1pppppp/8/4n3/1p5P/P2P2P1/1PP1PP2/RNBBKRQN w FAfa - 0 9 ;D1 23 ;D2 571 ;D3 13133 ;D4 346793 ;D5 8699448 ;D6 243460643
rnbkrbqn/p1pp1ppp/4p3/1p6/8/BPN3P1/P1PPPP1P/R2KRBQN w EAea - 2 9 ;D1 29 ;D2 692 ;D3 20014 ;D4 500375 ;D5 14904192 ;D6 386694739
rnbkrqn1/pppppp2/8/1Q2b1pp/P3P3/5P2/1PPP2PP/RNBKR1NB w EAea - 0 9 ;D1 37 ;D2 1001 ;D3 36440 ;D4 987842 ;D5 35626426 ;D6 993747544
rbnkbrqn/p1pppp2/7p/1p4pP/3P1P2/8/PPP1P1P1/RBNKBRQN w FAfa - 0 9 ;D1 30 ;D2 564 ;D3 17143 ;D4 381364 ;D5 11859538 ;D6 293703269
1nkbbrqn/3ppppp/r1p5/pp6/8/4PP2/PPPPN1PP/RNKBBRQ1 w FAf - 2 9 ;D1 26 ;D2 546 ;D3 14641 ;D4 344592 ;D5 9556962 ;D6 245137199
rnkrbbq1/pppppnp1/7p/8/1B1Q1p2/3P1P2/PPP1P1PP/RNKR1B1N w DAda - 2 9 ;D1 43 ;D2 887 ;D3 36240 ;D4 846858 ;D5 33185346 ;D6 851927292
1rkrbqnb/pppppp2/2n3p1/7p/3P3P/P4N2/1PP1PPP1/RNKRBQ1B w DAd - 0 9 ;D1 26 ;D2 622 ;D3 16049 ;D4 403921 ;D5 10786140 ;D6 285233838
rbnkr1bn/pp1pqp1p/2p1p3/6p1/3P4/7P/PPP1PPP1/RBNKRQBN w EAea - 0 9 ;D1 19 ;D2 566 ;D3 12257 ;D4 381197 ;D5 9107175 ;D6 293397389
r1kbrqb1/pppp2pp/2n1p1n1/5p1B/4PP2/P7/1PPP2PP/RNK1RQBN w EAea - 2 9 ;D1 39 ;D2 1359 ;D3 53626 ;D4 1876028 ;D5 73871486 ;D6 2633945690
rnkrqbbn/p1p3pp/1p1ppp2/8/1P6/3P2P1/PKP1PP1P/RN1RQBBN w da - 0 9 ;D1 26 ;D2 776 ;D3 20735 ;D4 611907 ;D5 16884013 ;D6 503561996
rnkrqnbb/ppp2p1p/3p4/4p1p1/3P3P/N1Q5/PPP1PPP1/R1KR1NBB w DAda - 0 9 ;D1 40 ;D2 1175 ;D3 45637 ;D4 1375884 ;D5 52620163 ;D6 1633655838
bbrnkrn1/p1pppp2/1p6/6pp/3q4/1P3QP1/P1PPPP1P/BBRNKRN1 w FCfc - 0 9 ;D1 34 ;D2 1398 ;D3 45749 ;D4 1712950 ;D5 57268492 ;D6 2059942014
br1bkrnq/1p2pppp/pnp5/3p4/P1P5/5P2/1P1PPKPP/BRNB1RNQ w fb - 2 9 ;D1 24 ;D2 501 ;D3 12237 ;D4 284936 ;D5 7049659 ;D6 177940764
brnkrbn1/pppppp1q/B6p/6p1/8/1P2PP2/P1PP2PP/BRNKR1NQ w EBeb - 0 9 ;D1 34 ;D2 815 ;D3 25868 ;D4 700970 ;D5 22006883 ;D6 639803952
br1krnqb/pppppp1p/1n4p1/8/8/P2NN3/2PPPPPP/BR1K1RQB w Beb - 2 9 ;D1 37 ;D2 1029 ;D3 36748 ;D4 1025712 ;D5 36214583 ;D6 1026195877
rbbnkr1q/p1p2ppp/1p1ppn2/8/1PP4P/8/P2PPPP1/RBBNKRNQ w FAfa - 0 9 ;D1 28 ;D2 755 ;D3 22623 ;D4 605106 ;D5 18972778 ;D6 513486101
r1b1krnq/pp2pppp/1bn5/2pp4/4N3/5P2/PPPPPRPP/R1BBK1NQ w Afa - 0 9 ;D1 24 ;D2 705 ;D3 17427 ;D4 532521 ;D5 13532966 ;D6 426443376
1nbkrbn1/rpppppqp/p7/6p1/4P3/3P2P1/PPP1KP1P/RNB1RBNQ w e - 1 9 ;D1 31 ;D2 800 ;D3 24748 ;D4 693366 ;D5 21193292 ;D6 625757852
r1bkrnqb/pp3ppp/n1ppp3/8/1P5P/P7/R1PPPPP1/1NBKRNQB w Eea - 0 9 ;D1 21 ;D2 482 ;D3 11417 ;D4 275339 ;D5 7112890 ;D6 180378139
rbnkbrnq/ppp1p2p/5p2/3p2p1/1B1P4/1N4P1/PPP1PP1P/RB1K1RNQ w FAfa - 0 9 ;D1 33 ;D2 780 ;D3 25532 ;D4 628945 ;D5 20756770 ;D6 535497008
rnk1brnq/pp1ppppp/2p5/b7/8/1P2P2P/P1PP1PPQ/RNKBBRN1 w FAfa - 3 9 ;D1 29 ;D2 648 ;D3 19043 ;D4 449637 ;D5 13722785 ;D6 341389148
rnkrbbnq/p1p3pp/5p2/1p1pp3/P7/1PN2P2/2PPP1PP/R1KRBBNQ w DAda - 0 9 ;D1 26 ;D2 827 ;D3 21865 ;D4 683167 ;D5 18916370 ;D6 589161126
r1krbnqb/p1pp1ppp/2n1p3/8/1p4P1/PPP5/3PPP1P/RNKRBNQB w DAda - 1 9 ;D1 25 ;D2 540 ;D3 14709 ;D4 331332 ;D5 9491817 ;D6 225389422
rbnkrnbq/ppp1pp2/3p2p1/2N5/P6p/2P5/1P1PPPPP/RB1KRNBQ w EAea - 0 9 ;D1 32 ;D2 790 ;D3 25107 ;D4 661207 ;D5 20906017 ;D6 578332225
rnkbrn1q/1ppppppb/8/p4N1p/8/P1N5/1PPPPPPP/R1KBR1BQ w EAea - 0 9 ;D1 31 ;D2 691 ;D3 20813 ;D4 510665 ;D5 15308408 ;D6 404129987
rnkrnbbq/p1p2ppp/3pp3/1p6/6P1/4PQ1B/PPPP1P1P/RNKRN1B1 w DAda - 0 9 ;D1 29 ;D2 558 ;D3 16800 ;D4 352887 ;D5 10825379 ;D6 246965507
rnkrnqbb/pp2p1p1/3p3p/2p2p2/5P2/1P1N4/P1PPPQPP/RNKR2BB w DAda - 0 9 ;D1 29 ;D2 762 ;D3 23210 ;D4 644936 ;D5 20522675 ;D6 596067005
bb1rknnr/ppqppppp/8/2p5/3P1N2/1P6/P1P1PPPP/BBQRKN1R w HDhd - 1 9 ;D1 33 ;D2 963 ;D3 32279 ;D4 1000890 ;D5 34552118 ;D6 1124738493
bqrbknnr/ppp1p2p/8/3p1p2/5p2/P3N2P/1PPPP1P1/BQRBK1NR w HChc - 0 9 ;D1 20 ;D2 398 ;D3 9009 ;D4 194859 ;D5 4834319 ;D6 113660536
b1rk1bnr/qpp1pppp/p4n2/3p4/3PPP2/7N/PPP3PP/BQRKNB1R w HChc - 1 9 ;D1 25 ;D2 648 ;D3 16587 ;D4 455720 ;D5 12200870 ;D6 351766307
bqkrnnrb/pppp2p1/4pp2/4P2p/6P1/7P/PPPP1P2/BQRKNNRB w GC - 1 9 ;D1 30 ;D2 493 ;D3 15118 ;D4 280726 ;D5 8786998 ;D6 181492621
q1brknnr/1p1ppppp/p7/2p5/8/1PPP4/P2RPPPP/QBB1KNNR w Hhd - 0 9 ;D1 25 ;D2 501 ;D3 13206 ;D4 290463 ;D5 7982978 ;D6 192717198
qrb1k1nr/ppppb1pp/6n1/4ppN1/3P4/4N3/PPP1PPPP/QRBBK2R w HBhb - 2 9 ;D1 31 ;D2 872 ;D3 26191 ;D4 739276 ;D5 22493014 ;D6 646855304
1rbknbnr/1ppp1pp1/q6p/p3p3/5P2/2PPB3/PP2P1PP/QR1KNBNR w HBhb - 0 9 ;D1 28 ;D2 1020 ;D3 28147 ;D4 984000 ;D5 27484692 ;D6 947786800
qrbk2rb/1ppp1ppp/5nn1/p3p3/1N6/P7/1PPPPPPP/QRB1KNRB w gb - 0 9 ;D1 23 ;D2 592 ;D3 14398 ;D4 395716 ;D5 10098215 ;D6 293988585
qbrk1nnr/1pp1pppp/2b5/p2p4/P2P2P1/8/1PP1PP1P/QBKRBNNR w hc - 1 9 ;D1 26 ;D2 654 ;D3 18103 ;D4 471653 ;D5 13740891 ;D6 373081138
qrkbbnnr/ppp2p1p/4p3/3p2p1/P7/2PP4/1P2PPPP/QRKBBNNR w HBhb - 0 9 ;D1 25 ;D2 626 ;D3 16616 ;D4 431634 ;D5 12079406 ;D6 324006164
qr1kbbnr/ppp1pp1p/4n1p1/2Pp4/6P1/4N3/PP1PPP1P/QRK1BBNR w HB d6 0 9 ;D1 26 ;D2 699 ;D3 18068 ;D4 497152 ;D5 13353359 ;D6 375702908
qrk1b1rb/p1pppppp/3nnQ2/1p6/1P3P2/3P4/P1P1P1PP/1RKNBNRB w GBgb - 3 9 ;D1 43 ;D2 1369 ;D3 55463 ;D4 1831200 ;D5 71514365 ;D6 2427477375
qbrk1nbr/pppp3p/5n2/4ppp1/3P1P2/4N3/PPP1P1PP/QBKRN1BR w hc - 0 9 ;D1 25 ;D2 752 ;D3 20165 ;D4 615263 ;D5 17493373 ;D6 543180234
qrkb1nbr/1pppppQp/3n4/p7/5p2/1P1N4/P1PPP1PP/1RKB1NBR w HBhb - 0 9 ;D1 45 ;D2 946 ;D3 40100 ;D4 966903 ;D5 39736157 ;D6 1051910977
qrk1nbbr/ppp1p1p1/4n2p/3p1p2/1P5P/3P2P1/P1P1PP2/QRKNNBBR w HBhb - 1 9 ;D1 32 ;D2 770 ;D3 25367 ;D4 646977 ;D5 21717615 ;D6 577979364
qrkn1rbb/pp2pppp/2p5/3p4/P2Qn1P1/1P6/2PPPP1P/1RKNNRBB w FBfb - 0 9 ;D1 38 ;D2 943 ;D3 35335 ;D4 868165 ;D5 31909835 ;D6 798405123
bbrqknnr/ppp4p/3pp3/5pp1/4PP2/5Q2/PPPP2PP/BBR1KNNR w HChc - 0 9 ;D1 36 ;D2 843 ;D3 29974 ;D4 758528 ;D5 26828059 ;D6 723306114
1rqbkn1r/p1p1pppp/1p5n/P2p4/3Pb1P1/8/1PP1PP1P/BRQBKNNR w HBhb - 0 9 ;D1 23 ;D2 778 ;D3 19482 ;D4 649789 ;D5 17337683 ;D6 579112676
br1knbnr/1qp1pppp/pp1p4/8/8/PP6/2PPPPPP/BRQKNBNR w HBhb - 2 9 ;D1 26 ;D2 697 ;D3 18835 ;D4 546622 ;D5 15280079 ;D6 473071890
brqk2rb/ppppp1pp/4np2/8/2n5/3P1Q2/PP2PPPP/BR1KNNRB w GBgb - 0 9 ;D1 32 ;D2 948 ;D3 30434 ;D4 885713 ;D5 29821322 ;D6 874251866
r1bqknnr/pp1pp1p1/5p1p/2p1b2N/2P5/8/PPQPPPPP/RBB1K1NR w HAha - 0 9 ;D1 31 ;D2 785 ;D3 25549 ;D4 659952 ;D5 22244193 ;D6 592797491
rqbbknnr/ppppp2p/5pp1/8/8/1P3PP1/PQPPP2P/R1BBKNNR w HAha - 0 9 ;D1 23 ;D2 391 ;D3 10163 ;D4 198450 ;D5 5576671 ;D6 121267576
rqbknbnr/1pp1p2p/p7/3p1pp1/7N/1PP5/P2PPPPP/RQBK1BNR w HAha - 0 9 ;D1 27 ;D2 676 ;D3 19606 ;D4 522428 ;D5 15955388 ;D6 448477218
rqb1nnrb/2ppkppp/1p2p3/p7/2PPP3/1P6/P4PPP/RQBKNNRB w GA - 1 9 ;D1 31 ;D2 727 ;D3 22895 ;D4 570647 ;D5 18361051 ;D6 483248153
rb1kbn1r/p1ppppp1/qp5n/7p/P7/RPP5/3PPPPP/1BQKBNNR w Hha - 2 9 ;D1 29 ;D2 837 ;D3 23815 ;D4 730083 ;D5 21279560 ;D6 682863811
rqkbb1nr/p1p2ppp/1p1p2n1/3Np3/4P3/5N2/PPPP1PPP/RQKBB2R w HAha - 0 9 ;D1 28 ;D2 717 ;D3 20663 ;D4 550987 ;D5 16347343 ;D6 453153783
rqknbbr1/p1pppp1p/1p3np1/8/4P3/2P2P1P/PP1P2P1/RQKNBBNR w HAa - 0 9 ;D1 27 ;D2 650 ;D3 18231 ;D4 475303 ;D5 13847463 ;D6 383256006
r1k1bnrb/1qpppppp/1p2n3/p7/1P5P/6P1/P1PPPP2/RQKNBNR1 w GAga - 1 9 ;D1 24 ;D2 806 ;D3 20693 ;D4 713220 ;D5 19382263 ;D6 686009788
rb1knnbr/1pp1ppp1/p2p3p/5q2/3B2P1/3P1P2/PPP1P2P/RBQKNN1R w HAha - 0 9 ;D1 34 ;D2 1360 ;D3 44096 ;D4 1605706 ;D5 51973672 ;D6 1837704407
rqkb1nbr/p1p1ppp1/1p3n1p/2Qp4/8/2P5/PP1PPPPP/R1KBNNBR w HAha - 2 9 ;D1 39 ;D2 983 ;D3 38218 ;D4 940989 ;D5 36347815 ;D6 918801645
rqknnbbr/2pppp2/pp5p/6p1/1P1P4/4PP2/P1P3PP/RQKNNBBR w HAha - 0 9 ;D1 26 ;D2 628 ;D3 17638 ;D4 464924 ;D5 13787303 ;D6 386125234
rqkn1rbb/1pp1pppp/p7/3p4/3Pn3/2P1PP2/PP4PP/RQKNNRBB w FAfa - 1 9 ;D1 20 ;D2 527 ;D3 12216 ;D4 321533 ;D5 8082183 ;D6 219311659
bbrkqn1r/1pppppp1/5n2/p7/1PP2P1p/7N/P2PP1PP/BBRKQN1R w HChc - 1 9 ;D1 36 ;D2 963 ;D3 35291 ;D4 973839 ;D5 35907489 ;D6 1034223364
brkbqn1r/p2ppppp/7n/1p6/P1p3PP/8/1PPPPP1N/BRKBQ1NR w HBhb - 0 9 ;D1 18 ;D2 583 ;D3 11790 ;D4 394603 ;D5 8858385 ;D6 304339862
brkq1bnr/pp1ppp1p/8/2p2np1/P7/8/1PPPPPPP/BRKQNBNR w HBhb - 0 9 ;D1 19 ;D2 552 ;D3 11811 ;D4 354260 ;D5 8432183 ;D6 262293169
brkqnnrb/1ppppppp/8/8/p3P3/5N2/PPPP1PPP/BRKQ1NRB w GBgb - 3 9 ;D1 21 ;D2 397 ;D3 9653 ;D4 204350 ;D5 5489836 ;D6 128389738
rbbkq1nr/1p2pppp/p1p3nB/3p4/1Q1P4/6N1/PPP1PPPP/RB1K2NR w HAha - 0 9 ;D1 40 ;D2 1132 ;D3 43404 ;D4 1260470 ;D5 47425783 ;D6 1415578783
rkbbq1nr/1pppp1p1/4np2/p6p/8/PP3P2/1KPPP1PP/R1BBQNNR w ha - 0 9 ;D1 24 ;D2 596 ;D3 15220 ;D4 402121 ;D5 10822049 ;D6 302056813
r1bqn1nr/pkpppp1p/1p4pb/8/PN6/R7/1PPPPPPP/1KBQ1BNR w H - 2 9 ;D1 33 ;D2 794 ;D3 25450 ;D4 649150 ;D5 20919309 ;D6 561073410
rkb1nnrb/1pppq1pp/p4p2/4p3/5P2/1P1PB3/P1P1P1PP/RK1QNNRB w GAga - 0 9 ;D1 26 ;D2 625 ;D3 17050 ;D4 442036 ;D5 12515042 ;D6 342967558
rbkqbn1r/pppp1p1p/2n1p1p1/8/8/1P1PP1N1/P1P2PPP/RBKQB1NR w HAha - 1 9 ;D1 30 ;D2 660 ;D3 20308 ;D4 492714 ;D5 15348335 ;D6 403323883
rkqbb1n1/pppppppr/8/6np/5P2/8/PPPPP1PP/RKQBBNNR w HAa - 6 9 ;D1 23 ;D2 500 ;D3 12154 ;D4 292936 ;D5 7519117 ;D6 196524441
rkqnbbnr/ppppppp1/8/7p/3N4/6PP/PPPPPP2/RKQNBB1R w HAa - 0 9 ;D1 24 ;D2 484 ;D3 12495 ;D4 284570 ;D5 7775173 ;D6 193947530
rkqnb1rb/p1p1pppp/1p1p4/2n5/3P4/2P1N1N1/PP2PPPP/RKQ1B1RB w GAga - 0 9 ;D1 28 ;D2 1020 ;D3 29124 ;D4 1027904 ;D5 30515456 ;D6 1073711823
rbk1nnbr/1ppq1ppp/p2p4/4p3/P3B2P/2P5/1P1PPPP1/R1KQNNBR w HAha - 2 9 ;D1 38 ;D2 998 ;D3 37265 ;D4 1047592 ;D5 38552638 ;D6 1139322479
r1qbn1br/k1pppppp/6n1/pp6/5P1P/P7/1PPPP1PB/RKQBNN1R w HA - 1 9 ;D1 22 ;D2 549 ;D3 12867 ;D4 348574 ;D5 8725809 ;D6 251613569
rkqnn1br/pppp3p/4p1pb/5p2/P2P4/7P/1PP1PPPB/RKQNNB1R w HAha - 1 9 ;D1 32 ;D2 659 ;D3 21249 ;D4 469701 ;D5 15434721 ;D6 365761521
rk1nnrbb/p1p1pppp/1p6/3p1q2/P3P3/2NN4/1PPP1PPP/RKQ2RBB w FAfa - 3 9 ;D1 29 ;D2 989 ;D3 29087 ;D4 980477 ;D5 29643404 ;D6 998848556
bbrk1q1r/ppppppp1/3n4/7p/3Pn3/6PN/PPP1PPNP/BBRK1Q1R w HChc - 2 9 ;D1 23 ;D2 712 ;D3 16551 ;D4 516177 ;D5 12995202 ;D6 411077508
brkbnq1r/p1ppp2p/5ppn/1p6/5P2/1P1P2P1/P1P1P2P/BRKBNQNR w HBhb - 0 9 ;D1 28 ;D2 856 ;D3 24984 ;D4 780503 ;D5 23529352 ;D6 754501112
br1k1bnr/ppppp1pp/4np2/1B2P2q/3P4/8/PPP2PPP/BRKNQ1NR w HB - 3 9 ;D1 36 ;D2 1214 ;D3 40615 ;D4 1328331 ;D5 45096834 ;D6 1470987023
brk1qnrb/pnppp1p1/1p6/5p1p/8/5PPP/PPPPP1R1/BRKNQN1B w Bgb - 0 9 ;D1 22 ;D2 551 ;D3 13111 ;D4 353317 ;D5 9040545 ;D6 259643605
rbbkn1nr/1ppp2pp/p3p3/2q2p2/3P4/6P1/PPPBPP1P/RB1KNQNR w HAha - 0 9 ;D1 31 ;D2 1060 ;D3 31332 ;D4 1015099 ;D5 30314172 ;D6 976268967
rkbbn1nr/ppppp1pp/8/6N1/5p2/1q6/P1PPPPPP/RKBBN1QR w HAha - 0 9 ;D1 3 ;D2 72 ;D3 1919 ;D4 50827 ;D5 1400832 ;D6 39654253
rkb2bnr/pp2pppp/2p1n3/3p4/q2P4/5NP1/PPP1PP1P/RKBNQBR1 w Aha - 0 9 ;D1 29 ;D2 861 ;D3 24504 ;D4 763454 ;D5 22763215 ;D6 731511256
rkbq1nrb/ppppppp1/7p/8/1P1n4/P4P1P/2PPP1P1/RKBNQNRB w GAga - 0 9 ;D1 25 ;D2 672 ;D3 17631 ;D4 473864 ;D5 12954224 ;D6 361237536
rbknb1nr/ppp1qp1p/6p1/3pp3/3P3P/2B1P3/PPP2PP1/RBKN1QNR w HAha - 1 9 ;D1 27 ;D2 857 ;D3 24688 ;D4 792538 ;D5 23790033 ;D6 768247869
rknbbq1r/p1pppppp/1p2N3/8/3n4/2P5/PP1PPPPP/RK1BBQNR w HAha - 4 9 ;D1 29 ;D2 763 ;D3 22138 ;D4 574054 ;D5 16926075 ;D6 447896703
r1nqbbnr/1pppp1pp/1k6/p4p2/8/4P3/PPPP1PPP/RKN1BBNR w HA - 0 9 ;D1 26 ;D2 658 ;D3 17302 ;D4 464039 ;D5 12380488 ;D6 349047256
rkn2qrb/ppp1pppp/6n1/1b1p4/1P6/4PPB1/P1PP2PP/RKNQ1NRB w GAga - 3 9 ;D1 23 ;D2 574 ;D3 14070 ;D4 370324 ;D5 9501401 ;D6 263870337
rbkn2br/ppppp1p1/4np1p/1P5q/8/2P1N3/P2PPPPP/RBK1QNBR w HAha - 1 9 ;D1 29 ;D2 992 ;D3 29506 ;D4 999564 ;D5 30148787 ;D6 1045942540
1knbqnbr/1ppppp1p/r5p1/p7/7P/2PN2P1/PP1PPP2/RK1BQNBR w HAh - 2 9 ;D1 26 ;D2 698 ;D3 19395 ;D4 512023 ;D5 14848229 ;D6 402599313
rk1qnbbr/pnpppp1p/6p1/1p6/3P4/1P6/P1P1PPPP/RKNQNBBR w HAha - 1 9 ;D1 20 ;D2 480 ;D3 11159 ;D4 287539 ;D5 7425917 ;D6 203194521
rknqnrbb/pp1p2p1/5p1p/2p1p3/2P1P3/P2P4/1P3PPP/RKNQNRBB w FAfa - 0 9 ;D1 26 ;D2 679 ;D3 18116 ;D4 494953 ;D5 13790137 ;D6 392629571
bbrk2qr/pp1p1ppp/3n2n1/2p1p3/3P1P2/6N1/PPP1P1PP/BBRKN1QR w HChc - 0 9 ;D1 26 ;D2 790 ;D3 21521 ;D4 673269 ;D5 19259490 ;D6 617563700
b1krnnqr/1p1ppppp/p1p5/b6B/P7/4P1N1/1PPP1PPP/BRK1N1QR w HB - 2 9 ;D1 26 ;D2 625 ;D3 16451 ;D4 415452 ;D5 11490615 ;D6 304805107
1rknnbqr/3ppppp/p7/1pp5/4b2P/P4P2/1PPPP1PR/BRKNNBQ1 w Bhb - 1 9 ;D1 24 ;D2 757 ;D3 19746 ;D4 618777 ;D5 17275100 ;D6 544309489
br1nn1rb/pppkpqpp/3p1p2/8/PP6/4N3/1KPPPPPP/BR2NQRB w - - 3 9 ;D1 24 ;D2 682 ;D3 17129 ;D4 482711 ;D5 13057308 ;D6 375033550
rbbkn1qr/pppp2p1/6np/4pp2/7N/7P/PPPPPPPR/RBBK1NQ1 w Aha - 0 9 ;D1 22 ;D2 586 ;D3 14158 ;D4 409891 ;D5 10607781 ;D6 324452612
rk1bn1qr/pppbpppp/4n3/4p3/4P3/5P2/PPPP2PP/RKBB1NQR w HAha - 1 9 ;D1 22 ;D2 530 ;D3 13440 ;D4 348004 ;D5 9514787 ;D6 259898748
rkbnnbqr/1ppp1ppp/p7/4p3/8/QP3P2/P1PPP1PP/RKBNNB1R w HAha - 0 9 ;D1 29 ;D2 705 ;D3 21511 ;D4 551042 ;D5 17524731 ;D6 472356665
1kbnnqrb/1pp1p1pp/r4p2/p2p4/N4P2/3P4/PPP1P1PP/RKB1NQRB w GAg - 2 9 ;D1 21 ;D2 623 ;D3 14979 ;D4 437554 ;D5 11601134 ;D6 343214006
rbknbn1r/pppp1p1p/4p1q1/8/P1P3Pp/8/1P1PPP2/RBKNBNQR w HAha - 0 9 ;D1 30 ;D2 813 ;D3 24959 ;D4 708454 ;D5 23379040 ;D6 692576573
rk1bb1qr/2pppppp/p2nn3/1p4P1/6QP/8/PPPPPP2/RKNBBN1R w HAha - 2 9 ;D1 36 ;D2 857 ;D3 30124 ;D4 757524 ;D5 26485812 ;D6 696999449
rkn1bbqr/p2ppppp/2p1n3/1p6/4PP2/6PP/PPPP4/RKNNBBQR w HAha - 0 9 ;D1 33 ;D2 687 ;D3 22744 ;D4 511018 ;D5 17101732 ;D6 412778368
rkn1bqrb/pnp1pppp/3p4/8/Pp6/1N2NP2/1PPPP1PP/RK2BQRB w GAga - 0 9 ;D1 28 ;D2 591 ;D3 17174 ;D4 406025 ;D5 12182448 ;D6 312575205
rbk1n1br/ppp1ppqp/2n5/2Np2p1/8/2P5/PPBPPPPP/R1KN1QBR w HAha - 4 9 ;D1 35 ;D2 930 ;D3 30663 ;D4 844433 ;D5 27160490 ;D6 780616047
rknbn1br/1ppp1ppp/p3p3/8/1q6/2P2N1P/P2PPPP1/RKNB1QBR w HAha - 0 9 ;D1 4 ;D2 157 ;D3 3697 ;D4 138102 ;D5 3454704 ;D6 125373395
rkn1qbbr/pp3ppp/4n3/2ppp3/4P1P1/P2P4/1PP2P1P/RKNNQBBR w HAha - 0 9 ;D1 28 ;D2 840 ;D3 24437 ;D4 771328 ;D5 23200961 ;D6 756489357
rkn1qrbb/pp1ppp2/2p1n1p1/7p/2P2P1P/6P1/PP1PP3/RKNNQRBB w FAfa - 1 9 ;D1 32 ;D2 867 ;D3 27595 ;D4 757836 ;D5 24485663 ;D6 688115847
b1rknnrq/bpppp1p1/p6p/5p1P/6P1/4N3/PPPPPP2/BBRKN1RQ w GCgc - 1 9 ;D1 33 ;D2 851 ;D3 28888 ;D4 763967 ;D5 26686205 ;D6 731944177
brkb1nr1/pppppp2/3n2pp/3B4/1P6/4P3/PqPP1PPP/BRK1NNRQ w GBgb - 2 9 ;D1 4 ;D2 98 ;D3 2965 ;D4 76143 ;D5 2352530 ;D6 64251468
brk1nbrq/1ppppn1p/6p1/p4p2/P5P1/5R2/1PPPPP1P/BRKNNB1Q w Bgb - 0 9 ;D1 29 ;D2 922 ;D3 27709 ;D4 879527 ;D5 27463717 ;D6 888881062
brkn1rqb/1p1ppppp/3n4/p1p5/1P3P2/8/PNPPP1PP/BR1KNRQB w fb - 1 9 ;D1 29 ;D2 633 ;D3 19399 ;D4 469818 ;D5 15076198 ;D6 396737074
rb1k1nrq/pbp1pppp/1p1p1n2/8/5P2/4NN1P/PPPPP1P1/RBBK2RQ w GAga - 2 9 ;D1 28 ;D2 841 ;D3 24056 ;D4 710751 ;D5 20772996 ;D6 613798447
rkbbnnrq/p1pp3p/4p1p1/1p3p2/P6P/1P6/1BPPPPP1/RK1BNNRQ w GAga - 0 9 ;D1 33 ;D2 957 ;D3 30668 ;D4 907217 ;D5 29735654 ;D6 903933626
rk2nbrq/p1ppppp1/bpn5/7p/6P1/2N2P2/PPPPP1QP/RKB1NBR1 w GAga - 2 9 ;D1 24 ;D2 687 ;D3 18206 ;D4 544627 ;D5 15518417 ;D6 484217179
rkbn1r1b/pp1pppnp/6q1/2p3p1/5P1P/4N3/PPPPP1P1/RKB1NRQB w FAfa - 1 9 ;D1 23 ;D2 831 ;D3 21254 ;D4 754622 ;D5 21126103 ;D6 744755212
rbknb1rq/ppp1p1p1/3pnp1p/8/6PP/2PP4/PP2PP2/RBKNBNRQ w GAga - 0 9 ;D1 31 ;D2 838 ;D3 26800 ;D4 736910 ;D5 24008129 ;D6 677776408
rknbb1rq/p1pn1ppp/4p3/1p1p4/2P5/1P2N1P1/P2PPP1P/RKNBB1RQ w GAga - 1 9 ;D1 29 ;D2 830 ;D3 24798 ;D4 721630 ;D5 22243832 ;D6 660040360
rk1nbbrq/pp1p1ppp/3n4/P3p3/2p4P/8/1PPPPPP1/RKNNBBRQ w GAga - 1 9 ;D1 24 ;D2 484 ;D3 12776 ;D4 297419 ;D5 8379748 ;D6 214004367
rknnbr1b/ppp2pqp/3p4/4p1p1/7P/3P1P2/PPP1P1P1/RKNNBRQB w FAfa - 0 9 ;D1 32 ;D2 838 ;D3 26408 ;D4 740701 ;D5 23472124 ;D6 699211365
rb1k1rbq/ppppN1pp/2nn4/5p2/7P/8/PPPPPPP1/RBK1NRBQ w FA - 1 9 ;D1 27 ;D2 800 ;D3 22785 ;D4 701742 ;D5 20804424 ;D6 660917073
r1nbnrbq/kppppp1p/6p1/8/p1PP1P2/4P3/PP4PP/RKNBNRBQ w FA - 1 9 ;D1 28 ;D2 757 ;D3 21198 ;D4 602699 ;D5 17180857 ;D6 507618340
rkn1rbbq/p1pppppp/2n5/1pP5/8/1N2P3/PP1P1PPP/RK1NRBBQ w EAea - 1 9 ;D1 22 ;D2 483 ;D3 11890 ;D4 283679 ;D5 7497674 ;D6 191130942
rknnrqbb/2pppppp/8/p7/Np3P2/3P4/PPP1P1PP/RKN1RQBB w EAea - 0 9 ;D1 25 ;D2 536 ;D3 14456 ;D4 339180 ;D5 9694947 ;D6 245669668
bb1rknrn/1qppppp1/1p4B1/p6N/8/2P5/PP1PPPPP/B1QRK1RN w GDgd - 1 9 ;D1 32 ;D2 715 ;D3 22421 ;D4 575008 ;D5 17860156 ;D6 502410909
b1rbknrn/qpp1ppp1/p6p/3p4/2P5/1P1P1P2/P3P1PP/BQRBKNRN w GCgc - 0 9 ;D1 30 ;D2 818 ;D3 24421 ;D4 688711 ;D5 20981488 ;D6 611986786
bqkrnbrn/1pp1pp1p/p7/1B1p2p1/4P3/7P/PPPP1PP1/BQKRN1RN w - - 0 9 ;D1 28 ;D2 676 ;D3 18366 ;D4 478054 ;D5 13126287 ;D6 363765666
bqrknrnb/1p2ppp1/p1pp3p/8/3P1P2/1PP5/P3P1PP/BQRKNRNB w FCfc - 0 9 ;D1 31 ;D2 646 ;D3 20686 ;D4 455607 ;D5 14984618 ;D6 349082278
qbbrkn1r/pppppp1p/8/6p1/2P1Pn1P/6N1/PP1P1PP1/QBBRKNR1 w GDd - 3 9 ;D1 20 ;D2 532 ;D3 11581 ;D4 303586 ;D5 7512432 ;D6 202967948
1rbbknr1/p1ppp1pp/1pq2pn1/8/3P4/P3P3/QPP2PPP/1RBBKNRN w GBgb - 3 9 ;D1 31 ;D2 1002 ;D3 30581 ;D4 999607 ;D5 30642468 ;D6 1009228283
qrbkn1rn/pppp1ppp/8/6b1/P1P1Pp2/8/1P1P2PP/QRBKNBRN w GBgb - 0 9 ;D1 22 ;D2 505 ;D3 12447 ;D4 304863 ;D5 8192621 ;D6 214730959
qrbk1rnb/p2ppp1p/5n2/1pp3p1/8/7P/PPPPPPPN/QRBKR1NB w Bfb - 0 9 ;D1 20 ;D2 619 ;D3 13448 ;D4 449630 ;D5 10571176 ;D6 369603424
qbrkb1r1/ppp2ppp/3pn1n1/P3p3/4P3/3P4/1PP2PPP/QBRKBNRN w GCgc - 1 9 ;D1 26 ;D2 755 ;D3 20596 ;D4 604483 ;D5 17164382 ;D6 510878835
qrkbb1r1/ppp1pnpp/3p2n1/5p2/1P3P2/2Q3N1/P1PPP1PP/1RKBB1RN w GBgb - 0 9 ;D1 35 ;D2 918 ;D3 32244 ;D4 870888 ;D5 30933394 ;D6 867833733
qrknbbrn/ppp1ppp1/8/7p/2Bp4/4PPP1/PPPP3P/QRKNB1RN w GBgb - 0 9 ;D1 27 ;D2 593 ;D3 16168 ;D4 376808 ;D5 10422676 ;D6 258348640
qrk1brnb/ppppp3/4n2p/5pp1/2PP4/2N4P/PP2PPP1/QRK1BRNB w FBfb - 2 9 ;D1 24 ;D2 672 ;D3 17447 ;D4 506189 ;D5 13765777 ;D6 414930519
qbrknrb1/p2ppppp/2p3n1/8/p4P2/6PP/1PPPP3/QBRKNRBN w FCfc - 0 9 ;D1 29 ;D2 759 ;D3 23235 ;D4 634493 ;D5 20416668 ;D6 584870558
1rkb1rbn/p1pp1ppp/3np3/1p6/4qP2/3NB3/PPPPPRPP/QRKB3N w Bfb - 0 9 ;D1 22 ;D2 923 ;D3 22585 ;D4 914106 ;D5 24049880 ;D6 957218571
1rknrbbn/p1pp1p1p/8/1p2p1p1/4qPP1/2P5/PP1PP1BP/QRKNR1BN w EBeb - 0 9 ;D1 28 ;D2 1309 ;D3 36355 ;D4 1568968 ;D5 44576409 ;D6 1846382333
qrk1rn1b/ppppp2p/4n3/3b1pp1/4P2P/5BP1/PPPP1P2/QRKNRNB1 w EBeb - 3 9 ;D1 26 ;D2 839 ;D3 22189 ;D4 726354 ;D5 19978260 ;D6 661207281
bbrqk1rn/pp1ppppp/8/2p5/2P1P3/5n1P/PPBP1PP1/B1RQKNRN w GCgc - 1 9 ;D1 3 ;D2 95 ;D3 2690 ;D4 85038 ;D5 2518864 ;D6 80775549
brqbk2n/pppppprp/8/6p1/1P3n2/5P2/P1PPP1PP/R1QBKNRN w Gb - 2 9 ;D1 22 ;D2 593 ;D3 13255 ;D4 362760 ;D5 8922397 ;D6 253271592
brqknbr1/pp3ppp/3p2n1/2p1p3/2P5/5P2/PPKPP1PP/BRQ1NBRN w gb - 0 9 ;D1 21 ;D2 590 ;D3 13190 ;D4 397355 ;D5 9581695 ;D6 304103516
1rqknrnb/2pp1ppp/p3p3/1p6/P2P4/5bP1/1PP1PP1P/BRQKNRNB w FBfb - 0 9 ;D1 24 ;D2 737 ;D3 20052 ;D4 598439 ;D5 17948681 ;D6 536330341
rbb1k1rn/p1pqpppp/6n1/1p1p4/5P2/3PP3/PPP1K1PP/RBBQ1NRN w ga - 3 9 ;D1 24 ;D2 694 ;D3 16773 ;D4 513782 ;D5 13094823 ;D6 419402704
rqbbknr1/1ppp2pp/p5n1/4pp2/P7/1PP5/1Q1PPPPP/R1BBKNRN w GAga - 0 9 ;D1 24 ;D2 600 ;D3 15347 ;D4 408207 ;D5 11029596 ;D6 308553169
rqbknbrn/2pppppp/6Q1/pp6/8/2P5/PP1PPPPP/R1BKNBRN w GAga - 2 9 ;D1 40 ;D2 949 ;D3 34100 ;D4 889887 ;D5 31296485 ;D6 881529007
rqbknr1b/pp1ppp2/2p2n1p/6p1/8/3P1PPP/PPP1P3/RQBKNRNB w FAfa - 0 9 ;D1 20 ;D2 560 ;D3 12275 ;D4 373921 ;D5 8687544 ;D6 277906201
rbqkbnrn/p3pppp/1p6/3p4/P1p3P1/1P6/1QPPPP1P/RB1KBNRN w GAga - 0 9 ;D1 30 ;D2 1155 ;D3 35865 ;D4 1351455 ;D5 43092716 ;D6 1614019629
rqkbb1rn/p1p1pppn/1p1p4/7p/4PP2/7P/PPPPB1P1/RQK1BNRN w GAga - 1 9 ;D1 30 ;D2 701 ;D3 20804 ;D4 515942 ;D5 15450970 ;D6 401499189
rqknbbrn/1p2pp1p/3p2p1/p1p5/P2P4/1P6/1KP1PPPP/RQ1NBBRN w ga - 0 9 ;D1 28 ;D2 756 ;D3 21655 ;D4 610320 ;D5 17989811 ;D6 525585996
rqknbrnb/1pp3pp/5p2/p2pp3/P7/3PPN2/1PP2PPP/RQKNBR1B w FAfa - 0 9 ;D1 26 ;D2 731 ;D3 19509 ;D4 550395 ;D5 15209404 ;D6 439767476
rbqkr1bn/p1pppp1p/1p1n4/6p1/7P/3P1PP1/PPP1P3/RBQKNRBN w FAa - 0 9 ;D1 27 ;D2 586 ;D3 16282 ;D4 381604 ;D5 10905865 ;D6 274364342
rqk1nrb1/ppbp1ppp/4p1n1/2p5/7P/1PP5/P2PPPP1/RQKBNRBN w FAfa - 1 9 ;D1 27 ;D2 749 ;D3 21480 ;D4 602318 ;D5 18084787 ;D6 520547029
rqknrbbn/pp1p1ppp/4p3/2p5/3P2P1/7P/PPP1PP2/RQKNRBBN w EAa - 0 9 ;D1 20 ;D2 533 ;D3 11829 ;D4 336248 ;D5 8230417 ;D6 245871540
rqknrnbb/pp1ppp1p/2p3p1/8/8/1P2P1NP/P1PP1PP1/RQKNR1BB w EAea - 0 9 ;D1 22 ;D2 633 ;D3 14480 ;D4 441877 ;D5 10827868 ;D6 343525739
1brkq1rn/2pppppp/1p2n3/p2bN3/8/7P/PPPPPPP1/BBRKQ1RN w GCgc - 2 9 ;D1 27 ;D2 748 ;D3 20134 ;D4 580054 ;D5 16010135 ;D6 475206624
brkbqnrn/2pp1ppp/8/1p2p3/Pp2N3/8/2PPPPPP/BRKBQNR1 w GBgb - 0 9 ;D1 30 ;D2 827 ;D3 25308 ;D4 757837 ;D5 23746165 ;D6 751690068
brk1nbrn/pp1ppppp/2p5/7P/5P2/q2P4/PPP1P1P1/BRKQNBRN w GBgb - 1 9 ;D1 15 ;D2 471 ;D3 8716 ;D4 276424 ;D5 5960901 ;D6 190316951
brkqnrnb/1p1pp1p1/p4p2/2p4p/8/P2PP3/1PP1QPPP/BRK1NRNB w FBfb - 0 9 ;D1 24 ;D2 479 ;D3 12584 ;D4 280081 ;D5 7830230 ;D6 190419716
rbbkqnrn/2ppp2p/pp3p2/6p1/P6P/8/RPPPPPP1/1BBKQNRN w Gga - 0 9 ;D1 21 ;D2 523 ;D3 12125 ;D4 328733 ;D5 8322614 ;D6 242240658
rkbbqr1n/1ppppppn/7p/p7/4P3/2P2P2/PP1PB1PP/RKB1QNRN w GAa - 3 9 ;D1 27 ;D2 563 ;D3 16026 ;D4 372148 ;D5 11105151 ;D6 283211800
rkbqnbrn/ppppp3/8/5ppp/2P3P1/7P/PPQPPP2/RKB1NBRN w GAga - 0 9 ;D1 28 ;D2 639 ;D3 19250 ;D4 469250 ;D5 14872172 ;D6 384663405
rkb1nrnb/pppp1pp1/5q1p/8/P3p3/4R1P1/1PPPPP1P/1KBQNRNB w Ffa - 0 9 ;D1 28 ;D2 873 ;D3 23690 ;D4 720814 ;D5 20209424 ;D6 625281937
rbkqb1rn/1p1ppppp/4n3/p1p5/8/3PBP2/PPP1P1PP/RBKQ1NRN w GAga - 0 9 ;D1 26 ;D2 798 ;D3 21416 ;D4 667496 ;D5 18475618 ;D6 591681956
rk1qbnrn/1p1ppppp/1b6/p1p5/P7/2P3NP/1P1PPPP1/RKQBB1RN w GAga - 0 9 ;D1 22 ;D2 506 ;D3 12313 ;D4 301029 ;D5 7891676 ;D6 205739580
rk1nbbrn/ppp1ppp1/8/3p3p/1P1P2q1/5PB1/P1P1P1PP/RKQN1BRN w GAga - 1 9 ;D1 31 ;D2 956 ;D3 29219 ;D4 903799 ;D5 27827461 ;D6 876341492
rkqnbr1b/pp1pppp1/7p/2p2n2/P2P4/7N/RPP1PPPP/1KQNBR1B w Ffa - 0 9 ;D1 31 ;D2 750 ;D3 24267 ;D4 646252 ;D5 21639104 ;D6 617064197
rbkq1rbn/2p1pppp/pp3n2/3p4/5P2/3N2N1/PPPPP1PP/RBKQR1B1 w Afa - 2 9 ;D1 26 ;D2 647 ;D3 18027 ;D4 465119 ;D5 13643783 ;D6 369702807
rkqbr1bn/p2ppppp/1pp2n2/8/5P2/3P1N2/PPP1PRPP/RKQB2BN w Aa - 3 9 ;D1 24 ;D2 574 ;D3 14593 ;D4 371597 ;D5 10066892 ;D6 271121237
rk1qrbbn/p1ppp1pp/1p2n3/5p2/1P6/K3N3/P1PPPPPP/R1Q1RBBN w ea - 0 9 ;D1 25 ;D2 548 ;D3 14069 ;D4 340734 ;D5 9043111 ;D6 235545764
rkqnrnbb/pp1pp3/2p5/5ppp/8/PP4NP/2PPPPP1/RKQNR1BB w EAea - 0 9 ;D1 23 ;D2 727 ;D3 18228 ;D4 566572 ;D5 15078056 ;D6 471296844
bbrknq1r/ppppppp1/8/7p/5n2/3P4/PPP1PNPP/BBKRNQR1 w c - 0 9 ;D1 21 ;D2 610 ;D3 13300 ;D4 394705 ;D5 9605845 ;D6 293532398
brkbnqr1/2pppnpp/pp3p2/8/4PPPP/8/PPPP4/BRKBNQRN w GBgb - 1 9 ;D1 30 ;D2 757 ;D3 23908 ;D4 621332 ;D5 20360394 ;D6 548380577
brk1qb1n/ppppppr1/2n3pp/8/2P3P1/2N5/PP1PPP1P/BR1KQBRN w b - 1 9 ;D1 26 ;D2 570 ;D3 15537 ;D4 352883 ;D5 10081351 ;D6 242864559
brknq1nb/pp2prpp/8/2pP1p2/6P1/2N5/PPPP1P1P/BRK1QRNB w FBb - 1 9 ;D1 33 ;D2 830 ;D3 27897 ;D4 764915 ;D5 26262884 ;D6 765831403
rbbk1qrn/ppp1p1pp/5p2/3p1n2/7N/P7/1PPPPPPP/RBB1KQRN w ga - 0 9 ;D1 21 ;D2 562 ;D3 13060 ;D4 378883 ;D5 9520963 ;D6 290579255
rk1b1qrn/ppp1pppp/5n2/3pN3/P6P/7b/1PPPPPP1/RKBB1QRN w GAga - 4 9 ;D1 28 ;D2 677 ;D3 19235 ;D4 488740 ;D5 14354779 ;D6 383207197
rkbnqbrn/pp1ppp1p/2p5/6p1/P7/4P3/KPPPQPPP/R1BN1BRN w - - 3 9 ;D1 28 ;D2 585 ;D3 17443 ;D4 401483 ;D5 12574541 ;D6 310495538
rk1nqrnb/pbpppp2/1p4p1/7p/P7/5NP1/1PPPPPBP/RKBNQR2 w FAfa - 2 9 ;D1 26 ;D2 774 ;D3 21626 ;D4 645200 ;D5 19093408 ;D6 576325868
rbknb1rn/p1pp2pp/1p6/4pp2/1q3P1B/2N5/PPPPPNPP/RBK2QR1 w GAga - 2 9 ;D1 31 ;D2 1206 ;D3 36940 ;D4 1374158 ;D5 42849564 ;D6 1555711209
rk1bbqrn/pp1pp1pp/3n4/5p2/3p4/1PP5/PK2PPPP/R1NBBQRN w ga - 0 9 ;D1 21 ;D2 629 ;D3 14059 ;D4 429667 ;D5 10587910 ;D6 332632033
rknqbbr1/p1pp1pp1/1p4n1/4p2p/4P1P1/6RB/PPPP1P1P/RKNQB2N w Aga - 0 9 ;D1 27 ;D2 753 ;D3 20918 ;D4 593155 ;D5 17318772 ;D6 507563675
rknqbr1b/pppp1ppp/4p2n/8/1P3P2/4P3/P1PPN1PP/RKNQBR1B w FAfa - 2 9 ;D1 26 ;D2 623 ;D3 17177 ;D4 460663 ;D5 13389799 ;D6 383508368
r2kqrbn/bppppppp/2n5/p4B2/5P2/2P5/PP1PP1PP/1RKNQRBN w F - 2 9 ;D1 39 ;D2 1026 ;D3 37800 ;D4 1011922 ;D5 35946987 ;D6 992756232
rk1bqrb1/ppppppp1/1n6/7p/2P2P1n/4P1Q1/PP1P2PP/RKNB1RBN w FAfa - 0 9 ;D1 35 ;D2 760 ;D3 25817 ;D4 610557 ;D5 21014787 ;D6 536852043
rkq1rb1n/ppppp1pp/1n6/5p2/PPb2P2/8/1KPPP1PP/R1NQRBBN w ea - 1 9 ;D1 27 ;D2 754 ;D3 21009 ;D4 568788 ;D5 16461795 ;D6 448313956
rknqr2b/pppnp1pp/3p4/3b1p2/8/1N1P2N1/PPP1PPPP/RKQ1R1BB w EAea - 1 9 ;D1 27 ;D2 803 ;D3 23708 ;D4 700453 ;D5 21875031 ;D6 654754840
bbrknrqn/ppppp1pB/8/2P2p1p/8/5N2/PP1PPPPP/B1RK1RQN w FCfc - 0 9 ;D1 30 ;D2 799 ;D3 23923 ;D4 671112 ;D5 20532790 ;D6 603059376
brkbnrq1/1pppp1p1/6np/p4p2/4P3/1PP5/P1KP1PPP/BR1BNRQN w fb - 1 9 ;D1 27 ;D2 726 ;D3 19329 ;D4 555622 ;D5 15156662 ;D6 457601127
brknrbq1/1p1p1ppp/p3p1n1/2p5/8/1P1BPP2/P1PP2PP/BRKNR1QN w EBeb - 0 9 ;D1 36 ;D2 786 ;D3 27868 ;D4 655019 ;D5 22852433 ;D6 577223409
brknrqnb/p2ppp1p/2p5/1p6/3P2p1/P1P1N3/1P2PPPP/BRK1RQNB w EBeb - 0 9 ;D1 23 ;D2 649 ;D3 15169 ;D4 440504 ;D5 10687843 ;D6 320881984
rbbk1rqn/1ppppppp/3n4/p7/2P5/3N4/PP1PPPPP/RBB1KRQN w fa - 1 9 ;D1 20 ;D2 478 ;D3 11094 ;D4 275250 ;D5 7094988 ;D6 185488058
rkbbnrqn/p2p1ppp/1p2p3/8/P1p1P3/1BP5/1P1P1PPP/RKB1NRQN w FAfa - 0 9 ;D1 22 ;D2 570 ;D3 13295 ;D4 346811 ;D5 8671852 ;D6 229898448
rkb1rb1n/ppppppqp/8/2n3p1/2P1P1P1/8/PP1P1P1P/RKBNRBQN w EAea - 1 9 ;D1 23 ;D2 663 ;D3 16212 ;D4 490748 ;D5 12900485 ;D6 404944553
rkb1rqnb/pppp3p/2n3p1/4pp2/P2P3P/2P5/1P2PPP1/RKBNRQNB w EAea - 0 9 ;D1 25 ;D2 845 ;D3 22188 ;D4 741972 ;D5 20276176 ;D6 683290790
rbk1brqn/ppp1pppp/8/3p4/7P/1P4P1/2PPPP2/RBKNBRQN w FAfa - 0 9 ;D1 24 ;D2 526 ;D3 13862 ;D4 322175 ;D5 9054028 ;D6 222704171
rknbbrqn/pp3pp1/4p3/2pp3p/2P5/8/PPBPPPPP/RKN1BRQN w FAfa - 0 9 ;D1 26 ;D2 756 ;D3 19280 ;D4 559186 ;D5 14697705 ;D6 433719427
1knrbbqn/rp1p1ppp/p3p3/2p5/8/5P1P/PPPPP1P1/RKNRBBQN w DAd - 0 9 ;D1 26 ;D2 539 ;D3 15194 ;D4 345070 ;D5 10223443 ;D6 248715580
rknr1qnb/ppp1p1pp/3p2b1/8/4p3/1P3P1P/P1PP2P1/RKNRBQNB w DAda - 0 9 ;D1 25 ;D2 701 ;D3 18969 ;D4 561369 ;D5 16047041 ;D6 496340789
rbk1r1bn/ppppp1pp/4n3/5p2/1P3P2/4N2P/PqPPP1P1/RBK1RQBN w EAea - 1 9 ;D1 2 ;D2 60 ;D3 1319 ;D4 41765 ;D5 1017864 ;D6 33183408
r1nbrqbn/k1ppp1pp/1p6/p4p2/2P5/6PQ/PP1PPP1P/RKNBR1BN w EA - 0 9 ;D1 27 ;D2 699 ;D3 20436 ;D4 561765 ;D5 17192121 ;D6 499247248
rknrqbbn/1pp1pp2/p5p1/3p3p/6P1/PN5P/1PPPPP2/RK1RQBBN w DAda - 0 9 ;D1 23 ;D2 611 ;D3 15515 ;D4 435927 ;D5 11917036 ;D6 352885930
rknrqn1b/p1pp1ppb/8/1p2p1Qp/3P4/3N4/PPP1PPPP/RK1R1NBB w DAda - 0 9 ;D1 45 ;D2 1170 ;D3 48283 ;D4 1320341 ;D5 52213677 ;D6 1500007485
bbkrnrnq/p2p1ppp/2p1p3/1p6/1P2Q3/6P1/P1PPPP1P/BBKRNRN1 w - - 0 9 ;D1 41 ;D2 1035 ;D3 39895 ;D4 1035610 ;D5 38555608 ;D6 1037686769
brkbnr2/1ppppp1p/7n/p5N1/P2q4/8/1PPPPPPP/BRKBNRQ1 w FBfb - 1 9 ;D1 22 ;D2 869 ;D3 19234 ;D4 679754 ;D5 16453359 ;D6 567287944
brknrbnq/p1ppppp1/1p6/7p/2PP4/5P2/PPK1P1PP/BR1NRBNQ w eb - 1 9 ;D1 23 ;D2 641 ;D3 14748 ;D4 422240 ;D5 10192718 ;D6 302864305
brk1r1qb/pp1ppnpp/2p2pn1/8/6N1/2N3P1/PPPPPP1P/BRK1R1QB w EBeb - 3 9 ;D1 32 ;D2 863 ;D3 28379 ;D4 773191 ;D5 25848794 ;D6 720443112
rbbk1rnq/pppp1pp1/4p2p/8/3P2n1/4BN1P/PPP1PPP1/RB1K1RNQ w FAfa - 3 9 ;D1 26 ;D2 628 ;D3 16151 ;D4 411995 ;D5 11237919 ;D6 300314373
rkbbnr1q/p1pppppp/5n2/1p5B/PP6/4P3/2PP1PPP/RKB1NRNQ w FAfa - 0 9 ;D1 30 ;D2 692 ;D3 21036 ;D4 519283 ;D5 16025428 ;D6 420887328
rkb1rbnq/1pppp1pp/5p2/p7/5n1P/1PN3P1/P1PPPP2/RKB1RBNQ w EAea - 0 9 ;D1 32 ;D2 825 ;D3 27130 ;D4 697251 ;D5 23593363 ;D6 622249676
rkbnrnqb/1ppp1p1p/p5p1/4p3/4P3/2N2P2/PPPP2PP/RKBR1NQB w Aea - 0 9 ;D1 24 ;D2 487 ;D3 13300 ;D4 301989 ;D5 8782713 ;D6 215787079
rbknbr1q/pppp2pp/4p3/5p1n/1P2P2N/8/P1PP1PPP/RBKNBR1Q w FAfa - 0 9 ;D1 23 ;D2 571 ;D3 13799 ;D4 365272 ;D5 9224232 ;D6 257288920
rknbb1nq/pppppr2/5pp1/7p/8/1N4P1/PPPPPP1P/RK1BBRNQ w FAa - 2 9 ;D1 26 ;D2 548 ;D3 15618 ;D4 350173 ;D5 10587626 ;D6 253006082
rknr1bnq/p2pp1pp/1p3p2/2p4b/6PP/2P2N2/PP1PPP2/RKNRBB1Q w DAda - 1 9 ;D1 25 ;D2 502 ;D3 13150 ;D4 279098 ;D5 7824941 ;D6 175766730
rknrb1qb/ppp1pppp/3p4/8/4P1nP/2P5/PPKP1PP1/R1NRBNQB w da - 1 9 ;D1 23 ;D2 643 ;D3 14849 ;D4 426616 ;D5 10507328 ;D6 312096061
rbk1rnbq/pppp1npp/4p3/5p2/4P1P1/7P/PPPP1P1N/RBKNR1BQ w EAea - 1 9 ;D1 24 ;D2 591 ;D3 15178 ;D4 376988 ;D5 10251465 ;D6 263574861
rknbrnb1/p1pppp1p/1p6/3N2p1/P3q1P1/8/1PPPPP1P/RKNBR1BQ w EAea - 1 9 ;D1 28 ;D2 948 ;D3 27343 ;D4 864588 ;D5 26241141 ;D6 812343987
rknrn1b1/ppppppqp/8/6p1/2P5/2P1BP2/PP2P1PP/RKNRNB1Q w DAda - 1 9 ;D1 31 ;D2 807 ;D3 24360 ;D4 672973 ;D5 20455205 ;D6 588518645
1k1rnqbb/npppppp1/r7/p2B3p/5P2/1N4P1/PPPPP2P/RK1RNQB1 w DAd - 0 9 ;D1 40 ;D2 1122 ;D3 44297 ;D4 1249989 ;D5 48711073 ;D6 1412437357
bbqr1rkn/pp1ppppp/8/2p5/1P2P1n1/7N/P1PP1P1P/BBQRKR1N w FD - 0 9 ;D1 26 ;D2 841 ;D3 22986 ;D4 746711 ;D5 21328001 ;D6 705170410
bqkr1rnn/1ppp1ppp/p4b2/4p3/P7/3PP2N/1PP2PPP/BQRBKR1N w FC - 3 9 ;D1 24 ;D2 500 ;D3 12802 ;D4 293824 ;D5 7928916 ;D6 197806842
bqrkrbnn/1pp1ppp1/8/p6p/3p4/P3P2P/QPPP1PP1/B1RKRBNN w ECec - 0 9 ;D1 31 ;D2 592 ;D3 18585 ;D4 396423 ;D5 12607528 ;D6 298629240
bqkrrnnb/2p1pppp/p7/1P1p4/8/2R3P1/PP1PPP1P/BQ1KRNNB w E - 0 9 ;D1 42 ;D2 1124 ;D3 45187 ;D4 1276664 ;D5 50052573 ;D6 1483524894
qbbrkrn1/p1pppn1p/8/1p3Pp1/2P5/8/PP1PPP1P/QBBRKRNN w FDfd - 0 9 ;D1 21 ;D2 577 ;D3 13244 ;D4 392131 ;D5 9683808 ;D6 300294295
qrbbkrnn/pp1p2pp/4p3/5p2/2p2P1P/2P5/PP1PP1P1/QRBBKRNN w FBfb - 0 9 ;D1 21 ;D2 571 ;D3 12736 ;D4 345681 ;D5 8239872 ;D6 228837930
qrbkrbn1/1pp1pppp/p2p4/8/5PPn/2P5/PP1PP3/QRBKRBNN w EBeb - 0 9 ;D1 18 ;D2 466 ;D3 9443 ;D4 257776 ;D5 5679073 ;D6 162883949
qrb1rnnb/pp1p1ppp/2pk4/4p3/1P2P3/1R6/P1PP1PPP/Q1BKRNNB w E - 4 9 ;D1 37 ;D2 760 ;D3 26863 ;D4 562201 ;D5 19486022 ;D6 421740856
qbrkbrn1/p1pppp1p/6n1/1p4p1/1P6/5P2/P1PPPBPP/QBRK1RNN w FCfc - 1 9 ;D1 33 ;D2 824 ;D3 27385 ;D4 750924 ;D5 25176664 ;D6 734656217
qrkbbr2/2pppppp/5nn1/pp1Q4/P7/3P4/1PP1PPPP/1RKBBRNN w FBfb - 0 9 ;D1 42 ;D2 1147 ;D3 44012 ;D4 1311247 ;D5 48216013 ;D6 1522548864
qrkrbbnn/pp2pp2/2pp2pp/1B6/P7/4P3/1PPP1PPP/QRKRB1NN w DBdb - 0 9 ;D1 26 ;D2 464 ;D3 12653 ;D4 242892 ;D5 6928220 ;D6 142507795
qrkrbnnb/p1pp1pp1/1p5p/4p3/1P6/6PN/PKPPPP1P/QR1RBN1B w db - 0 9 ;D1 29 ;D2 705 ;D3 20000 ;D4 529810 ;D5 15055365 ;D6 419552571
qbrkr1bn/p1p1pp1p/1p1p2n1/6p1/3P1P2/4P3/PPP3PP/QBKRRNBN w ec - 2 9 ;D1 23 ;D2 613 ;D3 14835 ;D4 426484 ;D5 10747407 ;D6 323905533
qrk1rnb1/p1pp1ppp/1p2Bbn1/8/4P3/6P1/PPPP1P1P/QRK1RNBN w EBeb - 1 9 ;D1 28 ;D2 927 ;D3 24887 ;D4 846839 ;D5 23063284 ;D6 807913585
1qkrnbbn/1rpppppp/pp6/5N2/P4P2/8/1PPPP1PP/QRKRNBB1 w DBd - 3 9 ;D1 30 ;D2 542 ;D3 16646 ;D4 345172 ;D5 10976745 ;D6 251694423
qrkr2bb/pppppppp/8/1n2n3/1N5P/1P6/P1PPPPP1/QRKR1NBB w DBdb - 1 9 ;D1 28 ;D2 719 ;D3 21048 ;D4 562015 ;D5 17351761 ;D6 479400272
bbrqkrnn/3ppppp/8/ppp5/6P1/4P2N/PPPPKP1P/BBRQ1R1N w fc - 0 9 ;D1 21 ;D2 704 ;D3 16119 ;D4 546215 ;D5 13676371 ;D6 470796854
brqbkrnn/1pp2p1p/3pp1p1/p5N1/8/1P6/P1PPPPPP/BRQBK1RN w Bfb - 0 9 ;D1 34 ;D2 688 ;D3 22827 ;D4 505618 ;D5 16639723 ;D6 402140795
br1krb1n/2qppppp/pp3n2/8/1P4P1/8/P1PPPP1P/1RQKRBNN w EBeb - 0 9 ;D1 24 ;D2 945 ;D3 23943 ;D4 926427 ;D5 25019636 ;D6 959651619
brqkr1nb/2ppp1pp/1p2np2/p7/2P1PN2/8/PP1P1PPP/BRQKRN1B w EBeb - 0 9 ;D1 28 ;D2 675 ;D3 19728 ;D4 504128 ;D5 15516491 ;D6 417396563
rbbqkrnn/3pppp1/p7/1pp4p/2P1P2P/8/PP1P1PP1/RBBQKRNN w FAfa - 0 9 ;D1 26 ;D2 671 ;D3 18164 ;D4 496806 ;D5 14072641 ;D6 404960259
rqbbkr1n/pp1p1p1p/4pn2/2p3p1/4P1P1/3P3P/PPP2P2/RQBBKRNN w FAfa - 0 9 ;D1 22 ;D2 633 ;D3 14629 ;D4 441809 ;D5 10776416 ;D6 335689685
rqbkrbnn/p1ppp3/1p3pp1/7p/3P4/P1P5/1PQ1PPPP/R1BKRBNN w EAea - 0 9 ;D1 32 ;D2 607 ;D3 20339 ;D4 454319 ;D5 15586203 ;D6 383515709
rqbkrnn1/pp2ppbp/3p4/2p3p1/2P5/1P3N1P/P2PPPP1/RQBKRN1B w EAea - 1 9 ;D1 29 ;D2 943 ;D3 28732 ;D4 908740 ;D5 28761841 ;D6 907579129
rbqkb1nn/1ppppr1p/p5p1/5p2/1P6/2P4P/P1KPPPP1/RBQ1BRNN w a - 1 9 ;D1 22 ;D2 441 ;D3 10403 ;D4 231273 ;D5 5784206 ;D6 140934555
rqkb1rnn/1pp1pp1p/p5p1/1b1p4/3P4/P5P1/RPP1PP1P/1QKBBRNN w Ffa - 1 9 ;D1 21 ;D2 505 ;D3 11592 ;D4 290897 ;D5 7147063 ;D6 188559137
rq1rbbnn/pkp1ppp1/3p3p/1p2N1P1/8/8/PPPPPP1P/RQKRBB1N w DA - 0 9 ;D1 27 ;D2 608 ;D3 16419 ;D4 387751 ;D5 10808908 ;D6 268393274
rqkrb2b/p2ppppp/2p3nn/1p6/5P2/PP1P4/2P1P1PP/RQKRBNNB w DAda - 1 9 ;D1 30 ;D2 749 ;D3 21563 ;D4 581531 ;D5 16916813 ;D6 485406712
rbqkr1bn/pp1ppp2/2p1n2p/6p1/8/4BPNP/PPPPP1P1/RBQKRN2 w EAea - 0 9 ;D1 23 ;D2 600 ;D3 15082 ;D4 410057 ;D5 11041820 ;D6 314327867
rqkbrnb1/2ppp1pp/pp3pn1/8/5P2/B2P4/PPP1P1PP/RQKBRN1N w EAea - 2 9 ;D1 22 ;D2 569 ;D3 13541 ;D4 371471 ;D5 9395816 ;D6 269460607
rqkrnbb1/p1p1pppp/1p4n1/3p4/7P/P3P3/1PPPBPP1/RQKRN1BN w DAda - 0 9 ;D1 27 ;D2 579 ;D3 15565 ;D4 373079 ;D5 10238486 ;D6 266047417
rqkrn1bb/p1ppp1pp/4n3/1p6/6p1/4N3/PPPPPPPP/RQKR2BB w DAda - 0 9 ;D1 20 ;D2 462 ;D3 10234 ;D4 274162 ;D5 6563859 ;D6 193376359
bbrkqr2/pppp1ppp/6nn/8/2P1p3/3PP2N/PP3PPP/BBRKQR1N w FCfc - 0 9 ;D1 28 ;D2 724 ;D3 21688 ;D4 619064 ;D5 19318355 ;D6 593204629
brk1qrnn/1pppbppp/4p3/8/1p6/P1P4P/3PPPP1/BRKBQRNN w FBfb - 1 9 ;D1 24 ;D2 662 ;D3 16920 ;D4 468215 ;D5 12610387 ;D6 355969349
1r1qrbnn/p1pkpppp/1p1p4/8/3P1PP1/P4b2/1PP1P2P/BRKQRBNN w EB - 1 9 ;D1 22 ;D2 696 ;D3 17021 ;D4 510247 ;D5 13697382 ;D6 401903030
1rkqrnnb/p1p1p1pp/1p1p4/3b1p1N/4P3/5N2/PPPP1PPP/BRKQR2B w EBeb - 1 9 ;D1 29 ;D2 887 ;D3 27035 ;D4 816176 ;D5 26051242 ;D6 791718847
rbbkq1rn/pppppppp/7n/8/P7/3P3P/1PPKPPP1/RBB1QRNN w a - 3 9 ;D1 22 ;D2 417 ;D3 9900 ;D4 216855 ;D5 5505063 ;D6 134818483
rkbbqr1n/1p1pppp1/2p2n2/p4NBp/8/3P4/PPP1PPPP/RK1BQRN1 w FAfa - 0 9 ;D1 37 ;D2 832 ;D3 30533 ;D4 728154 ;D5 26676373 ;D6 673756141
rkbqrb1n/3pBppp/ppp2n2/8/8/P2P4/1PP1PPPP/RK1QRBNN w EAea - 0 9 ;D1 28 ;D2 685 ;D3 19718 ;D4 543069 ;D5 16033316 ;D6 482288814
rkb1rn1b/ppppqppp/4p3/8/1P2n1P1/5Q2/P1PP1P1P/RKB1RNNB w EAea - 2 9 ;D1 37 ;D2 1158 ;D3 40114 ;D4 1234768 ;D5 44672979 ;D6 1389312729
r1kqbrnn/pp1pp1p1/7p/2P2p2/5b2/3P4/P1P1P1PP/RBKQBRNN w FAfa - 0 9 ;D1 5 ;D2 161 ;D3 4745 ;D4 154885 ;D5 4734999 ;D6 157499039
rkqbbr1n/ppp1ppp1/8/Q2p3p/4n3/3P1P2/PPP1P1PP/RK1BBRNN w FAfa - 2 9 ;D1 38 ;D2 1144 ;D3 40433 ;D4 1236877 ;D5 43832975 ;D6 1366087771
rkqrbbn1/p1ppppp1/Bp5p/8/P6n/2P1P3/1P1P1PPP/RKQRB1NN w DAda - 0 9 ;D1 28 ;D2 551 ;D3 15488 ;D4 350861 ;D5 9944107 ;D6 251179183
rkqrb1nb/1ppp1ppp/p7/4p3/5n2/3P2N1/PPPQPPPP/RK1RB1NB w DAda - 0 9 ;D1 26 ;D2 690 ;D3 19877 ;D4 513628 ;D5 15965907 ;D6 418191735
rbkqrnbn/pppp1p2/4p1p1/7p/7P/P2P4/BPP1PPP1/R1KQRNBN w EAea - 0 9 ;D1 27 ;D2 515 ;D3 13992 ;D4 309727 ;D5 8792550 ;D6 218658292
rkqbrnbn/pp1ppp2/8/2p3p1/P1P4p/5P2/1PKPP1PP/R1QBRNBN w ea - 0 9 ;D1 27 ;D2 627 ;D3 16843 ;D4 431101 ;D5 11978698 ;D6 328434174
rkqrnbbn/1p2pp1p/3p2p1/p1p5/P5PP/3N4/1PPPPP2/RKQR1BBN w DAda - 0 9 ;D1 23 ;D2 624 ;D3 15512 ;D4 451860 ;D5 11960861 ;D6 367311176
rk2rnbb/ppqppppp/2pn4/8/1P3P2/6P1/P1PPP1NP/RKQR1NBB w DAa - 1 9 ;D1 27 ;D2 727 ;D3 20206 ;D4 581003 ;D5 16633696 ;D6 505212747
b1krrqnn/pp1ppp1p/2p3p1/8/P3Pb1P/1P6/2PP1PP1/BBRKRQNN w EC - 0 9 ;D1 32 ;D2 943 ;D3 30759 ;D4 865229 ;D5 28672582 ;D6 800922511
1rkbrqnn/p1pp1ppp/1p6/8/P2Pp3/8/1PPKPPQP/BR1BR1NN w eb - 0 9 ;D1 28 ;D2 916 ;D3 24892 ;D4 817624 ;D5 22840279 ;D6 759318058
brkrqb1n/1pppp1pp/p7/3n1p2/P5P1/3PP3/1PP2P1P/BRKRQBNN w DBdb - 0 9 ;D1 27 ;D2 669 ;D3 18682 ;D4 484259 ;D5 13956472 ;D6 380267099
brkrqnnb/3pppp1/1p6/p1p4p/2P3P1/6N1/PP1PPP1P/BRKRQ1NB w DBdb - 0 9 ;D1 29 ;D2 699 ;D3 20042 ;D4 512639 ;D5 15093909 ;D6 406594531
r1bkrq1n/pp2pppp/3b1n2/2pp2B1/6P1/3P1P2/PPP1P2P/RB1KRQNN w EAea - 2 9 ;D1 27 ;D2 835 ;D3 22848 ;D4 713550 ;D5 19867800 ;D6 631209313
rk1brq1n/p1p1pppp/3p1n2/1p3b2/4P3/2NQ4/PPPP1PPP/RKBBR2N w EAea - 4 9 ;D1 36 ;D2 1004 ;D3 35774 ;D4 979608 ;D5 35143142 ;D6 966310885
rkbrqbnn/1p2ppp1/B1p5/p2p3p/4P2P/8/PPPP1PP1/RKBRQ1NN w DAda - 0 9 ;D1 27 ;D2 748 ;D3 21005 ;D4 597819 ;D5 17597073 ;D6 515304215
rkbrqn1b/pp1pp1pp/2p2p2/5n2/8/2P2P2/PP1PP1PP/RKBRQ1NB w DAda - 0 9 ;D1 20 ;D2 479 ;D3 10485 ;D4 266446 ;D5 6253775 ;D6 167767913
rbkrbnn1/ppppp1pp/5q2/5p2/5P2/P3P2N/1PPP2PP/RBKRBQ1N w DAda - 3 9 ;D1 28 ;D2 947 ;D3 26900 ;D4 876068 ;D5 26007841 ;D6 838704143
rkr1bqnn/1ppp1p1p/p5p1/4p3/3PP2b/2P2P2/PP4PP/RKRBBQNN w CAca - 0 9 ;D1 31 ;D2 1004 ;D3 32006 ;D4 1006830 ;D5 32688124 ;D6 1024529879
rkrqbbnn/pppp3p/8/4ppp1/1PP4P/8/P2PPPP1/RKRQBBNN w CAca - 0 9 ;D1 24 ;D2 717 ;D3 18834 ;D4 564137 ;D5 15844525 ;D6 484884485
rkrqbn1b/pppp2pp/8/4pp2/1P1P2n1/5N2/P1P1PP1P/RKRQBN1B w CAca - 0 9 ;D1 25 ;D2 718 ;D3 19654 ;D4 587666 ;D5 17257753 ;D6 537354146
rbkrqnbn/p1p1ppp1/1p1p4/8/3PP2p/2PB4/PP3PPP/R1KRQNBN w DAda - 0 9 ;D1 30 ;D2 754 ;D3 23298 ;D4 611322 ;D5 19338246 ;D6 532603566
1krbqnbn/1p2pppp/r1pp4/p7/8/1P1P2PP/P1P1PP2/RKRBQNBN w CAc - 0 9 ;D1 21 ;D2 566 ;D3 13519 ;D4 375128 ;D5 9700847 ;D6 279864836
rkrq1b2/pppppppb/3n2np/2N5/4P3/7P/PPPP1PP1/RKRQ1BBN w CAca - 1 9 ;D1 33 ;D2 654 ;D3 21708 ;D4 479678 ;D5 15990307 ;D6 382218272
rkr1nnbb/ppp2p1p/3p1qp1/4p3/P5P1/3PN3/1PP1PP1P/RKRQN1BB w CAca - 1 9 ;D1 28 ;D2 715 ;D3 20361 ;D4 555328 ;D5 16303092 ;D6 468666425
bbrkrnqn/1p1ppppp/8/8/p2pP3/PP6/2P2PPP/BBRKRNQN w ECec - 0 9 ;D1 24 ;D2 757 ;D3 19067 ;D4 603231 ;D5 15957628 ;D6 509307623
brkbrnqn/ppp2p2/4p3/P2p2pp/6P1/5P2/1PPPP2P/BRKBRNQN w EBeb - 0 9 ;D1 25 ;D2 548 ;D3 14563 ;D4 348259 ;D5 9688526 ;D6 247750144
brkr1bqn/1pppppp1/3n3p/1p6/P7/4P1P1/1PPP1P1P/BRKRN1QN w DBdb - 0 9 ;D1 19 ;D2 359 ;D3 7430 ;D4 157099 ;D5 3521652 ;D6 81787718
brkr1qnb/pppp2pp/2B1p3/5p2/2n5/6PP/PPPPPPN1/BRKR1QN1 w DBdb - 1 9 ;D1 27 ;D2 854 ;D3 23303 ;D4 741626 ;D5 20558538 ;D6 667089231
rbbkrnqn/p1p1p1pp/8/1p1p4/1P1Pp3/6N1/P1P2PPP/RBBKRNQ1 w EAea - 0 9 ;D1 28 ;D2 723 ;D3 19844 ;D4 514440 ;D5 14621108 ;D6 397454100
rkbbrn1n/pppppp2/5q1p/6p1/3P3P/4P3/PPP2PP1/RKBBRNQN w EAea - 1 9 ;D1 25 ;D2 741 ;D3 19224 ;D4 585198 ;D5 15605840 ;D6 485037906
rkbr1bq1/ppnppppp/6n1/2p5/2P1N2P/8/PP1PPPP1/RKBRNBQ1 w DAda - 3 9 ;D1 24 ;D2 547 ;D3 14359 ;D4 339497 ;D5 9410221 ;D6 234041078
1kbrnqnb/r1ppppp1/8/pp5p/8/1P1NP3/P1PP1PPP/RKB1RQNB w Ad - 2 9 ;D1 26 ;D2 618 ;D3 17305 ;D4 442643 ;D5 13112297 ;D6 357030697
rbkrb1qn/1pp1ppp1/3pn2p/pP6/8/4N1P1/P1PPPP1P/RBKRB1QN w DAda - 0 9 ;D1 21 ;D2 544 ;D3 12492 ;D4 338832 ;D5 8381483 ;D6 236013157
rkrbbnqn/ppppp3/5p2/6pp/5PBP/4P3/PPPP2P1/RKR1BNQN w CAca - 0 9 ;D1 30 ;D2 891 ;D3 25435 ;D4 764356 ;D5 21894752 ;D6 669256602
rkr1bb1n/ppppp1pp/5p2/4n3/3QP3/5P2/RPPP2PP/1KRNBB1N w Cca - 1 9 ;D1 45 ;D2 1172 ;D3 51766 ;D4 1332060 ;D5 57856784 ;D6 1501852662
rkr1bqnb/pp1ppppp/8/2pN4/1P6/5N2/P1PPnPPP/RKR1BQ1B w CAca - 0 9 ;D1 28 ;D2 730 ;D3 20511 ;D4 559167 ;D5 16323242 ;D6 463032124
rbkrnqb1/2ppppp1/p5np/1p6/8/3N4/PPPPPPPP/RBKRQNB1 w DAda - 2 9 ;D1 20 ;D2 417 ;D3 9159 ;D4 217390 ;D5 5180716 ;D6 133936564
rkrbnqb1/p1pppnpp/5p2/1p6/2P5/1P1P1N2/P3PPPP/RKRB1QBN w CAca - 0 9 ;D1 25 ;D2 546 ;D3 14039 ;D4 330316 ;D5 8813781 ;D6 222026485
rkr1qbbn/ppppppp1/4n3/7p/8/P7/KPPPPPPP/R1RNQBBN w ca - 0 9 ;D1 22 ;D2 484 ;D3 11458 ;D4 267495 ;D5 6633319 ;D6 163291279
rkrnqnb1/1ppppp2/p5p1/7p/8/P1bPP3/1PP1QPPP/RKRN1NBB w CAca - 0 9 ;D1 22 ;D2 636 ;D3 15526 ;D4 441001 ;D5 11614241 ;D6 331083405
b2krn1q/p1rppppp/1Q3n2/2p1b3/1P4P1/8/P1PPPP1P/BBRKRNN1 w ECe - 3 9 ;D1 36 ;D2 1192 ;D3 42945 ;D4 1406795 ;D5 50382104 ;D6 1650202838
brkbrnn1/pp1pppp1/7q/2p5/6Pp/4P1NP/PPPP1P2/BRKBR1NQ w EBeb - 2 9 ;D1 30 ;D2 978 ;D3 29593 ;D4 942398 ;D5 29205057 ;D6 936568065
brkrnb1q/pp1p1ppp/2p1p3/5n2/1P6/5N1N/P1PPPPPP/BRKR1B1Q w DBdb - 1 9 ;D1 31 ;D2 897 ;D3 27830 ;D4 810187 ;D5 25423729 ;D6 755334868
brkr1nqb/pp1p1pp1/2pn3p/P3p3/4P3/6P1/1PPP1P1P/BRKRNNQB w DBdb - 0 9 ;D1 19 ;D2 382 ;D3 8052 ;D4 182292 ;D5 4232274 ;D6 103537333
r1bkrn1q/ppbppppp/5n2/2p5/3P4/P6N/1PP1PPPP/RBBKRNQ1 w EAea - 3 9 ;D1 27 ;D2 822 ;D3 22551 ;D4 678880 ;D5 19115128 ;D6 578210135
rkbbrnnq/pp2pppp/8/2pp4/P1P5/1P3P2/3PP1PP/RKBBRNNQ w EAea - 1 9 ;D1 23 ;D2 643 ;D3 15410 ;D4 442070 ;D5 11170489 ;D6 329615708
rkbr1b1q/p1pppppp/1p1n4/7n/5QP1/3N4/PPPPPP1P/RKBR1BN1 w DAda - 4 9 ;D1 37 ;D2 943 ;D3 34382 ;D4 880474 ;D5 31568111 ;D6 842265141
rkbr1nqb/pppp2np/8/4ppp1/1P6/6N1/P1PPPPPP/RKBRN1QB w DAda - 1 9 ;D1 23 ;D2 574 ;D3 13260 ;D4 362306 ;D5 9020291 ;D6 261247606
rbkr1nnq/p1p1pp1p/1p4p1/3p4/b3P3/4N3/PPPPNPPP/RBKRB1Q1 w DAda - 0 9 ;D1 26 ;D2 900 ;D3 23414 ;D4 805006 ;D5 21653203 ;D6 745802405
rkrbb1nq/p2pppp1/1p4n1/2p4p/3N4/4P1P1/PPPP1P1P/RKRBBN1Q w CAca - 0 9 ;D1 32 ;D2 697 ;D3 22231 ;D4 531121 ;D5 17150175 ;D6 441578567
rkrnbb1q/pp2pp1p/6pn/2pp4/2B1P2P/8/PPPP1PP1/RKRNB1NQ w CAca - 0 9 ;D1 28 ;D2 854 ;D3 23853 ;D4 755990 ;D5 21823412 ;D6 712787248
rk2bnqb/pprpppp1/4n2p/2p5/P7/3P2NP/1PP1PPP1/RKRNB1QB w CAa - 1 9 ;D1 26 ;D2 596 ;D3 16251 ;D4 414862 ;D5 11758184 ;D6 323043654
r1krnnbq/pp1ppp1p/6p1/2p5/2P5/P3P3/Rb1P1PPP/1BKRNNBQ w Dda - 0 9 ;D1 2 ;D2 61 ;D3 1312 ;D4 40072 ;D5 937188 ;D6 28753562
1krbnnbq/1pp1p1pp/r7/p2p1p2/3PP3/2P3P1/PP3P1P/RKRBNNBQ w CAc - 0 9 ;D1 30 ;D2 953 ;D3 28033 ;D4 860530 ;D5 25531358 ;D6 787205262
rkr1nbbq/2ppp1pp/1pn5/p4p2/P6P/3P4/1PP1PPPB/RKRNNB1Q w CAca - 1 9 ;D1 24 ;D2 645 ;D3 15689 ;D4 446423 ;D5 11484012 ;D6 341262639
rkrnnqbb/p1ppp2p/Qp6/4Pp2/5p2/8/PPPP2PP/RKRNN1BB w CAca - 0 9 ;D1 35 ;D2 929 ;D3 32020 ;D4 896130 ;D5 31272517 ;D6 915268405
bbq1nr1r/pppppk1p/2n2p2/6p1/P4P2/4P1P1/1PPP3P/BBQNNRKR w HF - 1 9 ;D1 23 ;D2 589 ;D3 14744 ;D4 387556 ;D5 10316716 ;D6 280056112
+203
View File
@@ -0,0 +1,203 @@
# Training
## Value network (`value/`)
A `(768 -> 1024)x2 -> 1` SCReLU network trained with
[bullet](https://github.com/jw1912/bullet) on Lc0-derived data from linrock.
### Run
How `rigby-value-v2` was trained (the 12 S2 files, see Data):
```
powershell -ExecutionPolicy Bypass -File C:\Users\rektd\repos\Rigby\train\value\train.ps1 --hidden 1024 --superbatches 170 --id rigby-value-v2 --data <iter-1 file> ... --data <iter-12 file>
```
On the RTX 3070, 1024 hidden trains at 3-4M positions/s (bound by the GPU): about
33 s per superbatch of 100M positions. 512 hidden runs at ~6M/s, 1536 at ~2.6M/s.
Arguments are passed to the trainer:
| Argument | Default | Meaning |
| --- | --- | --- |
| `--superbatches N` | 40 | Training length; the learning rate decays to the end |
| `--hidden N` | 1024 | Hidden width; the engine's `nnue::HIDDEN` must match |
| `--id NAME` | `rigby-value` | Checkpoint name |
| `--data FILE` | the test80 Feb 2024 binpack | Repeatable; files are read one after the other, round and round. All `.bin.zst`, all `.bin` or all `.binpack` |
| `--batches N` | 6104 | Batches of 16384 per superbatch (smaller for speed tests) |
Output: `value/checkpoints/<id>-<superbatch>/quantised.bin` every 10 superbatches
and at the end. That file is what the engine loads.
### Network format
`quantised.bin` (1,579,072 bytes for 1024 hidden), little-endian `i16`:
| Part | Shape | Quantisation |
| --- | --- | --- |
| `l0w` | 768 x H, feature-major (`[feature][hidden]`) | QA = 255 |
| `l0b` | H | QA |
| `l1w` | 2 x H (side to move first, then the other side) | QB = 64 |
| `l1b` | 1 | QA * QB |
Inputs (bullet's `Chess768`): `64 * piece + square`, with pieces relative to the
accumulator's side (own pawn = 0 ... own king = 5, their pawn = 6 ... their king = 11)
and squares flipped vertically for black. The side to move's accumulator comes first.
Output: `((sum screlu(acc) * w) / QA + b) * 400 / (QA * QB)` in centipawns, side to
move. The engine maps it to Q with the same 400 scale:
`q = 2 * sigmoid(cp / 400) - 1 = tanh(cp / 800)` (`src/nnue.cpp`, `src/eval.cpp`).
The engine computes `screlu(v) * w` as `v * (v * w)` in 16 bits, so `|l1w|` must be
at most 128 (bullet's AdamW clips weights to ±1.98, i.e. 127); it refuses a net
that breaks this.
### Checking the engine's inference
```
cargo run --release -- --check checkpoints/<id>-<superbatch> --hidden <H>
```
prints bullet's own (float) evaluation of fixed positions; the engine's `evalfens`
command prints the same positions with the quantised network. Expect agreement
within a few centipawns (quantisation; v2 at superbatch 20: at most 13 cp); a
wrong feature mapping shows up as differences of hundreds.
### Networks
| File | Hidden | Data | Superbatches | Final loss |
| --- | --- | --- | --- | --- |
| `networks/rigby-value-v1.bin` | 128 | test80 2024-02 | 40 (10 min) | 0.0220 |
| `networks/rigby-value-v2.bin` | 1024 | linrock S2 (6.6B positions) | 170 (1h34m) | 0.01278 |
Losses are not comparable across data sets.
### Data
v2: the `S2` folder of
[linrock/bullet-training-data](https://huggingface.co/datasets/linrock/bullet-training-data),
12 files `test77nov-unfilt-test79-maraprmay-v6-dd.skip-see-ge0.wdl-pdist.iter-N.bullet.bin.zst`
(~9 GB each, 108 GB in all; ~547M positions each, 6.6B in all, different positions
in every file, each already filtered and shuffled). The trainer reads the `.zst`
files directly (`value/src/zstd_reader.rs`): unpacked they would take 210 GB, and
training only needs ~40 MB/s of compressed input, which an HDD gives easily. They
live in `D:\rigby-data\s2\s2-1.parts\` on this machine. Hugging Face caps one connection at ~20 MB/s, so
download several files at once.
v1: Lc0 self-play data converted to Stockfish binpacks by linrock
([huggingface.co/datasets/linrock](https://huggingface.co/datasets/linrock)),
`test80-2024-02-feb-2tb7p.min-v2.v6.binpack` (6.9 GB zstd, 8.3 GB unpacked), read
directly (`SfBinpackLoader`). The filter keeps positions from ply 16 on that are not
in check, with a quiet best move and |score| <= 10000.
Training target for both: `0.4 * result + 0.6 * sigmoid(score / 400)`.
Data other than S2 lives in `train/data/` and is not committed.
### Setup on a new machine
1. Rust via rustup (MSVC toolchain), Visual Studio C++ build tools.
2. CUDA Toolkit 13.3 with `cudart`, `nvrtc`, `cublas` (bullet compiles its kernels at
runtime with NVRTC, no nvcc needed).
3. `git clone https://github.com/jw1912/bullet` next to this repo.
4. linrock's data (see Data); `pip install zstandard` to unpack a `.binpack.zst`.
## Policy network (`policy/`)
`3072 -> HIDDEN -> CReLU -> pairwise product (HIDDEN / 2) -> one row per move`,
softmax over the legal moves, trained on Lc0's visit distributions. The trainer is
montytrain's policy trainer (the one Monty, Vine and Jackal use; it adds two CUDA
operations to a pinned bullet revision), with Rigby's inputs and outputs and an Lc0
converter.
### Data
```
powershell -ExecutionPolicy Bypass -File C:\Users\rektd\repos\Rigby\train\policy\fetch.ps1 -From 20261025 -To 20261115
```
Downloads the hourly tars of an Lc0 run from
[storage.lczero.org/files/training_data](https://storage.lczero.org/files/training_data/)
(default `test91`, the active run in November 2026; test80 stopped in August 2025),
one day at a time: each day is converted to `data/lc0/monty/<run>-<day>.binpack` and
its tars are deleted. Days already converted are skipped, so an interrupted run can
be restarted. Finally every day file is shuffled into `data/lc0/policy.binpack`.
One hourly tar (~73 MB) holds ~350k positions, which take ~12 MB converted; about
three weeks of test91 (~40 GB of tars, ~190M positions) is plenty for a
10-superbatch run. The server limits each connection to ~2.3 MB/s (what a browser
gets) but not their number, so fetch.ps1 downloads 32 tars at a time across days
(`-Parallel`): 72 MB/s measured, about 10 minutes for three weeks.
Tars downloaded by hand can be converted directly:
```
target\release\lc02monty.exe ..\data\lc0\monty\mine.binpack <tar or folder of tars>... [--delete]
target\release\interleave.exe ..\data\lc0\policy.binpack ..\data\lc0\monty
```
`lc02monty` (`src/lc0.rs`) reads V6 records (classical input format), rebuilds each
game from its first position and the played moves, and checks every record: the
pieces must match and the moves Lc0 gave a probability must be exactly the legal
moves. A game is cut at the first record that fails (`LC0_DEBUG=1` prints why); on
test91 data nothing fails. Lc0 writes castling as the king taking its rook; Chess960
games (about 4%) are kept, the castling rooks taken as the outermost on each side.
Stored per position: the played move, best Q and the visit fractions of every legal
move (montyformat scales them to 0..255).
### Run
```
powershell -ExecutionPolicy Bypass -File C:\Users\rektd\repos\Rigby\train\policy\train.ps1
```
Default: 1024 hidden, 10 superbatches of 100M positions, about 17 minutes on the
RTX 3070 (~1M positions/s; 2048 hidden runs at ~400k/s). AdamW, weights clipped to
±0.99, LR 1e-3 decaying exponentially to 1e-5. Arguments:
| Argument | Default | Meaning |
| --- | --- | --- |
| `--superbatches N` | 10 | Training length |
| `--hidden N` | 1024 | Hidden layer width (even) |
| `--id NAME` | `rigby-policy` | Checkpoint name |
| `--data FILE` | `../data/lc0/policy.binpack` | montyformat file |
| `--buffer-mb N` | 4096 | Shuffle buffer |
| `--batches N` | 6104 | Batches of 16384 per superbatch (smaller for test runs) |
Output: `policy/checkpoints/<id>-<superbatch>/quantised.bin` every 5 superbatches.
Try it in the engine with `setoption name PolicyFile value <path>`, or build it in
with `make POLICYFILE=<path>`.
### Network format
`quantised.bin`, `i8`, every weight times 128, no header (the engine works out
HIDDEN from the size: `3072 * H + H + (H / 2) * 3920 + 3920` bytes):
| Part | Shape |
| --- | --- |
| `l0w` | 3072 x H, feature-major |
| `l0b` | H |
| `l1w` | 3920 x H/2, move-major |
| `l1b` | 3920 |
Inputs, relative to the side to move (`src/inputs.rs`, `src/policy.cpp`): squares
flipped vertically for black and horizontally when its king is on files e-h;
`384 * theirs + 64 * piece + square`, plus 768 if the opponent attacks the square
and 1536 if the side to move defends it (attacks of sliders see through the other
side's king). Outputs: one row per (piece, from, to) reachable on an empty board,
then 4 x 22 promotions, 2 castling rows and 8 double pushes, in the same flipped
frame. Hidden: `clamp(acc[i], 0, 1) * clamp(acc[i + H/2], 0, 1)`.
### Checking the engine's inference
`train.ps1 --check checkpoints\<id>-<superbatch> --hidden <H>` prints the trainer's
(float) policy of fixed positions; the engine's `policyfens` command prints the
same with the quantised network. They agree to a few tenths of a percent, a few
percent on very sharp distributions (rigby-policy-v1, 1.e4 e5: 80.2% vs 75.3%).
### Networks
| File | Data | Hidden | Superbatches | Final loss |
| --- | --- | --- | --- | --- |
| `networks/rigby-policy-v1.bin` | test91 2026-10-25 .. 11-15 (171M positions) | 1024 | 10 (10 min) | 2.296 |
### Setup
As for the value trainer, plus: the pinned bullet revision's `cudarc` does not know
CUDA 13.3, so `env.ps1` sets `CUDARC_CUDA_VERSION=13000` (13.3 is compatible).
+556
View File
@@ -0,0 +1,556 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "acyclib"
version = "0.3.0"
source = "git+https://github.com/jw1912/bullet?rev=73618a4359ec44b48ae64ba63f49c247e7d200b9#73618a4359ec44b48ae64ba63f49c247e7d200b9"
dependencies = [
"parking_lot",
"rand",
"rand_distr",
]
[[package]]
name = "adler2"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
[[package]]
name = "autocfg"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "bitflags"
version = "2.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394"
[[package]]
name = "bullet_cuda_backend"
version = "0.1.0"
source = "git+https://github.com/jw1912/bullet?rev=73618a4359ec44b48ae64ba63f49c247e7d200b9#73618a4359ec44b48ae64ba63f49c247e7d200b9"
dependencies = [
"acyclib",
"cudarc",
"parking_lot",
]
[[package]]
name = "cfg-if"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
[[package]]
name = "crc32fast"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b929dd2a135771f40afabd1073f85eed59c800b7c61901e5c254270497dad64"
dependencies = [
"cfg-if",
]
[[package]]
name = "cudarc"
version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72ba848ae5c6f3cb36e71eab5f268763e3fabcabe3f7bc683e16f7fa3d46281e"
dependencies = [
"libloading",
]
[[package]]
name = "errno"
version = "0.3.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e35d6e78f4cebb90e51d543db8fe41528851d6deeef6ef21ebd4bfdc1e784776"
dependencies = [
"libc",
"windows-sys",
]
[[package]]
name = "filetime"
version = "0.2.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c287a33c7f0a620c38e641e7f60827713987b3c0f26e8ddc9462cc69cf75759"
dependencies = [
"cfg-if",
"libc",
]
[[package]]
name = "flate2"
version = "1.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4"
dependencies = [
"crc32fast",
"miniz_oxide",
"zlib-rs",
]
[[package]]
name = "getrandom"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasi",
]
[[package]]
name = "libc"
version = "0.2.175"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543"
[[package]]
name = "libloading"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667"
dependencies = [
"cfg-if",
"windows-targets 0.53.3",
]
[[package]]
name = "libm"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
[[package]]
name = "linux-raw-sys"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"
[[package]]
name = "lock_api"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "miniz_oxide"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c"
dependencies = [
"adler2",
"simd-adler32",
]
[[package]]
name = "montyformat"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4caf9c718f831a8568f030576e6a6e6aa487ed5f8732ddb0ba79e9a3ea0421ca"
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
"libm",
]
[[package]]
name = "parking_lot"
version = "0.12.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70d58bf43669b5795d1576d0641cfb6fbb2057bf629506267a92807158584a13"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-targets 0.52.6",
]
[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro2"
version = "1.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
name = "r-efi"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "rand"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
dependencies = [
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [
"getrandom",
]
[[package]]
name = "rand_distr"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a8615d50dcf34fa31f7ab52692afec947c4dd0ab803cc87cb3b0b4570ff7463"
dependencies = [
"num-traits",
"rand",
]
[[package]]
name = "redox_syscall"
version = "0.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77"
dependencies = [
"bitflags",
]
[[package]]
name = "rigby-policy"
version = "0.1.0"
dependencies = [
"acyclib",
"bullet_cuda_backend",
"flate2",
"montyformat",
"tar",
]
[[package]]
name = "rustix"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e"
dependencies = [
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "simd-adler32"
version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea"
[[package]]
name = "smallvec"
version = "1.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
[[package]]
name = "syn"
version = "2.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "tar"
version = "0.4.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f6221d9a6003c78398e3b239969f352578258df48c8eb051caadae0015bc840"
dependencies = [
"filetime",
"libc",
"xattr",
]
[[package]]
name = "unicode-ident"
version = "1.0.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
[[package]]
name = "wasi"
version = "0.14.7+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c"
dependencies = [
"wasip2",
]
[[package]]
name = "wasip2"
version = "1.0.1+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7"
dependencies = [
"wit-bindgen",
]
[[package]]
name = "windows-link"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link 0.2.1",
]
[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
dependencies = [
"windows_aarch64_gnullvm 0.52.6",
"windows_aarch64_msvc 0.52.6",
"windows_i686_gnu 0.52.6",
"windows_i686_gnullvm 0.52.6",
"windows_i686_msvc 0.52.6",
"windows_x86_64_gnu 0.52.6",
"windows_x86_64_gnullvm 0.52.6",
"windows_x86_64_msvc 0.52.6",
]
[[package]]
name = "windows-targets"
version = "0.53.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
dependencies = [
"windows-link 0.1.3",
"windows_aarch64_gnullvm 0.53.0",
"windows_aarch64_msvc 0.53.0",
"windows_i686_gnu 0.53.0",
"windows_i686_gnullvm 0.53.0",
"windows_i686_msvc 0.53.0",
"windows_x86_64_gnu 0.53.0",
"windows_x86_64_gnullvm 0.53.0",
"windows_x86_64_msvc 0.53.0",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
[[package]]
name = "windows_aarch64_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
[[package]]
name = "windows_i686_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
[[package]]
name = "windows_i686_gnu"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
[[package]]
name = "windows_i686_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
[[package]]
name = "windows_i686_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
[[package]]
name = "windows_i686_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
[[package]]
name = "windows_x86_64_gnu"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]]
name = "windows_x86_64_msvc"
version = "0.53.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
[[package]]
name = "wit-bindgen"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
[[package]]
name = "xattr"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156"
dependencies = [
"libc",
"rustix",
]
[[package]]
name = "zerocopy"
version = "0.8.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "zlib-rs"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112"
+22
View File
@@ -0,0 +1,22 @@
[package]
name = "rigby-policy"
version = "0.1.0"
edition = "2021"
publish = false
default-run = "rigby-policy"
# Trains Rigby's policy network on Lc0 self-play data.
# Based on montytrain's policy trainer (github.com/TomaszJaworski777/montytrain,
# the trainer Monty, Vine and Jackal use), which builds on a pinned bullet
# revision with two custom CUDA operations.
[dependencies]
acyclib = { package = "acyclib", git = 'https://github.com/jw1912/bullet', rev = "73618a4359ec44b48ae64ba63f49c247e7d200b9" }
bullet_cuda_backend = { package = "bullet_cuda_backend", git = 'https://github.com/jw1912/bullet', rev = "73618a4359ec44b48ae64ba63f49c247e7d200b9" }
montyformat = "0.9.2"
flate2 = "1"
tar = "0.4"
[profile.release]
lto = true
codegen-units = 1
panic = "abort"
+6
View File
@@ -0,0 +1,6 @@
# Shared by fetch.ps1 and train.ps1: CUDA and cargo on the PATH.
# The pinned bullet revision's cudarc only knows CUDA up to 13.0; 13.3 is
# ABI-compatible, so it is told to build for 13.0.
$env:CUDA_PATH = 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.3'
$env:CUDARC_CUDA_VERSION = '13000'
$env:PATH = "$env:USERPROFILE\.cargo\bin;$env:CUDA_PATH\bin\x64;$env:CUDA_PATH\bin;$env:PATH"
+98
View File
@@ -0,0 +1,98 @@
# Downloads Lc0 self-play data and converts it to montyformat for the policy trainer.
# powershell -ExecutionPolicy Bypass -File C:\Users\rektd\repos\Rigby\train\policy\fetch.ps1
# ... fetch.ps1 -From 20261025 -To 20261115 -Run test91 -Parallel 32
# Default: the last three weeks of test91 (about 40 GB of tars, 190M positions).
#
# The server limits each connection to about 2.3 MB/s but not their number
# (32 connections: ~72 MB/s), so tars are downloaded -Parallel at a time, in
# batches of whole days (about two tars per connection) into data\lc0\staging.
# Each day of a batch is then converted into data\lc0\monty\<run>-<day>.binpack
# and its tars deleted, so the disk only holds one batch of tars. Days already
# converted are skipped, so an interrupted run can simply be started again. At
# the end every day file is shuffled into data\lc0\policy.binpack, which is
# what train.ps1 reads.
param(
[string] $From = (Get-Date).AddDays(-21).ToString('yyyyMMdd'),
[string] $To = (Get-Date -Format 'yyyyMMdd'),
[string] $Run = 'test91',
[int] $Parallel = 32,
[switch] $NoInterleave
)
# Native tools report through exit codes; 'Stop' would turn cargo's progress
# output on stderr into errors under Windows PowerShell.
$ErrorActionPreference = 'Continue'
Set-Location $PSScriptRoot
. .\env.ps1
cargo build --release --bins
if ($LASTEXITCODE -ne 0) { throw 'build failed' }
$base = "https://storage.lczero.org/files/training_data/$Run/"
$data = (Resolve-Path '..\data').Path
$monty = Join-Path $data 'lc0\monty'
$staging = Join-Path $data 'lc0\staging'
New-Item -ItemType Directory -Force $monty, $staging | Out-Null
# The directory listing: name, date and size of every hourly tar. Empty tars
# (10240 bytes) are hours without games.
Write-Host "Listing $base ..."
$html = (Invoke-WebRequest -UseBasicParsing $base).Content
$tars = [regex]::Matches($html, '>(training-[^<]+-(\d{8})-\d{4}\.tar)</a>\s+\S+\s+\S+\s+(\d+)') |
ForEach-Object { [pscustomobject]@{ Name = $_.Groups[1].Value; Day = $_.Groups[2].Value; Size = [long]$_.Groups[3].Value } } |
Where-Object { $_.Day -ge $From -and $_.Day -le $To -and $_.Size -gt 10240 }
$days = $tars | Group-Object Day | Sort-Object Name
$totalGb = ($tars | Measure-Object Size -Sum).Sum / 1e9
Write-Host ("{0} tars over {1} days, {2:N1} GB to download" -f $tars.Count, $days.Count, $totalGb)
$pending = @($days | Where-Object { -not (Test-Path (Join-Path $monty "$Run-$($_.Name).binpack")) })
$done = $days.Count - $pending.Count
if ($done) { Write-Host "$done days already converted" }
while ($pending.Count) {
# Whole days until the batch has about two tars per connection.
$batch = @()
$count = 0
while ($pending.Count -and ($batch.Count -eq 0 -or $count -lt 2 * $Parallel)) {
$batch += $pending[0]
$count += $pending[0].Count
$pending = @($pending | Select-Object -Skip 1)
}
if (Test-Path $staging) { Remove-Item -Recurse -Force $staging }
New-Item -ItemType Directory -Force $staging | Out-Null
$config = Join-Path $staging 'curl.txt'
# Forward slashes: curl reads backslashes in a config file as escapes.
$lines = foreach ($day in $batch) {
$dir = Join-Path $staging $day.Name
New-Item -ItemType Directory -Force $dir | Out-Null
foreach ($tar in $day.Group) {
"url = `"$base$($tar.Name)`"`noutput = `"$((Join-Path $dir $tar.Name) -replace '\\', '/')`""
}
}
$lines | Set-Content -Encoding ascii $config
$gb = ($batch.Group | Measure-Object Size -Sum).Sum / 1e9
$start = Get-Date
Write-Host ("{0}..{1}: downloading {2} tars ({3:N2} GB)" -f $batch[0].Name, $batch[-1].Name, $count, $gb)
curl.exe -sSf --retry 5 -Z --parallel-max $Parallel -K $config
if ($LASTEXITCODE -ne 0) { throw "download failed for $($batch[0].Name)..$($batch[-1].Name)" }
$secs = ((Get-Date) - $start).TotalSeconds
Write-Host (" {0:N0} MB/s" -f ($gb * 1000 / [math]::Max($secs, 1)))
foreach ($day in $batch) {
$out = Join-Path $monty "$Run-$($day.Name).binpack"
& .\target\release\lc02monty.exe "$out.part" (Join-Path $staging $day.Name) --delete | Select-Object -Last 9
if ($LASTEXITCODE -ne 0) { throw "conversion failed for $($day.Name)" }
Move-Item -Force "$out.part" $out
}
}
if (Test-Path $staging) { Remove-Item -Recurse -Force $staging }
if (-not $NoInterleave) {
$policy = Join-Path $data 'lc0\policy.binpack'
Write-Host "Shuffling the day files into $policy ..."
& .\target\release\interleave.exe "$policy.part" $monty
if ($LASTEXITCODE -ne 0) { throw 'interleave failed' }
Move-Item -Force "$policy.part" $policy
Write-Host ("Done: {0:N1} GB in {1}" -f ((Get-Item $policy).Length / 1e9), $policy)
}
+3
View File
@@ -0,0 +1,3 @@
use_small_heuristics = "Max"
single_line_if_else_max_width = 100
max_width = 120
+111
View File
@@ -0,0 +1,111 @@
//! Shuffles montyformat files into one, game by game, picking each next game
//! from a file chosen in proportion to the bytes it has left.
//!
//! interleave <out.binpack> <file or directory of .binpack files>...
use std::{
fs::{self, File},
io::{BufReader, BufWriter, Write},
};
use montyformat::{FastDeserialise, MontyFormat};
fn main() -> std::io::Result<()> {
let mut args = std::env::args().skip(1);
let output = args.next().expect("usage: interleave <out> <file|dir>...");
let mut inputs: Vec<String> = Vec::new();
for arg in args {
let path = std::path::Path::new(&arg);
if path.is_dir() {
let mut files: Vec<String> = fs::read_dir(path)?
.filter_map(|e| e.ok().map(|e| e.path()))
.filter(|p| p.is_file() && p.extension().and_then(|e| e.to_str()) == Some("binpack"))
.map(|p| p.to_string_lossy().into_owned())
.collect();
files.sort();
inputs.extend(files);
} else {
inputs.push(arg);
}
}
assert!(!inputs.is_empty(), "no input files");
assert!(!inputs.contains(&output), "the output must not be one of the inputs");
println!("Writing to {output:#?}");
println!("Reading from:\n{inputs:#?}");
let mut streams = Vec::new();
let mut total = 0;
let target = File::create(&output)?;
let mut writer = BufWriter::new(target);
for path in &inputs {
let file = File::open(path)?;
let count = file.metadata()?.len();
if count > 0 {
streams.push((count, BufReader::new(file)));
total += count;
}
}
let mut remaining = total;
let mut rng = RandU64::default();
const INTERVAL: u64 = 1024 * 1024 * 256;
let mut prev = remaining / INTERVAL;
let mut buffer = Vec::new();
while remaining > 0 {
let mut spot = rng.rand() % remaining;
let mut idx = 0;
while streams[idx].0 < spot {
spot -= streams[idx].0;
idx += 1;
}
let (count, reader) = &mut streams[idx];
MontyFormat::deserialise_fast_into_buffer(reader, &mut buffer)?;
writer.write_all(&buffer)?;
let size = buffer.len() as u64;
remaining -= size;
*count -= size;
if *count == 0 {
streams.swap_remove(idx);
}
if remaining / INTERVAL < prev {
prev = remaining / INTERVAL;
let written = total - remaining;
print!("Written {written}/{total} Bytes ({:.2}%)\r", written as f64 / total as f64 * 100.0);
let _ = std::io::stdout().flush();
}
}
Ok(())
}
struct RandU64(u64);
impl Default for RandU64 {
fn default() -> Self {
Self(
(std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).expect("valid").as_nanos()
& 0xFFFF_FFFF_FFFF_FFFF) as u64,
)
}
}
impl RandU64 {
fn rand(&mut self) -> u64 {
self.0 ^= self.0 << 13;
self.0 ^= self.0 >> 7;
self.0 ^= self.0 << 17;
self.0
}
}
+132
View File
@@ -0,0 +1,132 @@
//! Converts Lc0 V6 training data tars into one montyformat file.
//!
//! lc02monty <out.binpack> <tar or directory of tars>... [--threads N] [--delete]
//!
//! Games are appended to the output, so a run can be repeated with new tars.
//! `--delete` removes each tar once its games are written (for streaming
//! large downloads through a small disk).
use std::{
fs::{File, OpenOptions},
io::{BufWriter, Read, Write},
path::PathBuf,
sync::{mpsc, Arc, Mutex},
};
use flate2::read::GzDecoder;
use rigby_policy::lc0::{convert_game, PolicyMap, Stats};
fn convert_tar(path: &PathBuf, map: &PolicyMap) -> std::io::Result<(Vec<u8>, Stats)> {
let mut stats = Stats::default();
let mut out = Vec::new();
let mut archive = tar::Archive::new(File::open(path)?);
let mut raw = Vec::new();
let mut buf = Vec::new();
for entry in archive.entries()? {
let mut entry = entry?;
if !entry.path()?.to_string_lossy().ends_with(".gz") {
continue;
}
raw.clear();
entry.read_to_end(&mut raw)?;
let mut data = Vec::new();
if GzDecoder::new(&raw[..]).read_to_end(&mut data).is_err() {
stats.bad_format += 1;
continue;
}
if let Some(game) = convert_game(&data, map, &mut stats) {
buf.clear();
game.serialise_into_buffer(&mut buf)?;
out.extend_from_slice(&buf);
}
}
Ok((out, stats))
}
fn main() {
let mut args = std::env::args().skip(1);
let out_path = args.next().expect("usage: lc02monty <out> <tar|dir>... [--threads N] [--delete]");
let mut inputs = Vec::new();
let mut threads = std::thread::available_parallelism().map(|n| n.get()).unwrap_or(4);
let mut delete = false;
while let Some(arg) = args.next() {
match arg.as_str() {
"--threads" => threads = args.next().expect("--threads needs a number").parse().expect("not a number"),
"--delete" => delete = true,
path => {
let p = PathBuf::from(path);
if p.is_dir() {
let mut tars: Vec<PathBuf> = std::fs::read_dir(&p)
.expect("cannot read directory")
.filter_map(|e| e.ok().map(|e| e.path()))
.filter(|p| p.extension().is_some_and(|e| e == "tar"))
.collect();
tars.sort();
inputs.extend(tars);
} else {
inputs.push(p);
}
}
}
}
assert!(!inputs.is_empty(), "no input tars");
let total_tars = inputs.len();
let queue = Arc::new(Mutex::new(inputs.into_iter()));
let map = Arc::new(PolicyMap::default());
let (sender, receiver) = mpsc::sync_channel::<(PathBuf, std::io::Result<(Vec<u8>, Stats)>)>(threads);
for _ in 0..threads {
let queue = queue.clone();
let map = map.clone();
let sender = sender.clone();
std::thread::spawn(move || loop {
let Some(path) = queue.lock().unwrap().next() else { break };
let result = convert_tar(&path, &map);
if sender.send((path, result)).is_err() {
break;
}
});
}
drop(sender);
let file = OpenOptions::new().create(true).append(true).open(&out_path).expect("cannot open output");
let mut writer = BufWriter::with_capacity(1 << 24, file);
let mut total = Stats::default();
let mut done = 0;
let mut bytes = 0u64;
for (path, result) in receiver {
done += 1;
match result {
Ok((data, stats)) => {
writer.write_all(&data).expect("write failed");
bytes += data.len() as u64;
total.add(&stats);
if delete {
writer.flush().expect("flush failed");
let _ = std::fs::remove_file(&path);
}
}
Err(e) => eprintln!("skipping {}: {e}", path.display()),
}
println!(
"[{done}/{total_tars}] {} games, {} positions, {:.1} MB written",
total.games,
total.positions,
bytes as f64 / 1e6
);
}
writer.flush().expect("flush failed");
let kept = total.positions as f64;
let dropped = total.dropped_records as f64;
println!("games kept : {}", total.games);
println!("positions kept : {}", total.positions);
println!("records dropped : {} ({:.3}%)", total.dropped_records, 100.0 * dropped / (kept + dropped).max(1.0));
println!(" bad format : {} games", total.bad_format);
println!(" bad start : {} games", total.bad_start);
println!(" board mismatch : {} cuts", total.cut_board);
println!(" move mismatch : {} cuts", total.cut_moves);
println!(" played not found: {} cuts", total.cut_played);
}
+4
View File
@@ -0,0 +1,4 @@
pub mod loader;
pub mod reader;
pub use loader::MontyDataLoader;
+126
View File
@@ -0,0 +1,126 @@
use acyclib::{
device::tensor::Shape,
trainer::{
dataloader::{DataLoader, HostDenseMatrix, HostMatrix, HostSparseMatrix, PreparedBatchHost},
DataLoadingError,
},
};
use montyformat::chess::Move;
use super::reader::{DataReader, DecompressedData};
use crate::inputs::{self, INPUT_SIZE, MAX_ACTIVE_BASE, MAX_MOVES, NUM_MOVES_INDICES};
#[derive(Clone)]
pub struct MontyDataLoader {
reader: DataReader,
threads: usize,
}
impl MontyDataLoader {
pub fn new(path: &str, buffer_size_mb: usize, reader_threads: usize, loader_threads: usize) -> Self {
Self { reader: DataReader::new(path, buffer_size_mb, reader_threads), threads: loader_threads }
}
}
impl DataLoader for MontyDataLoader {
type Error = DataLoadingError;
fn map_batches<F: FnMut(PreparedBatchHost) -> bool>(self, batch_size: usize, mut f: F) -> Result<(), Self::Error> {
self.reader.map_batches(batch_size, |batch| f(prepare(batch, self.threads)));
Ok(())
}
}
pub fn prepare(data: &[DecompressedData], threads: usize) -> PreparedBatchHost {
let batch_size = data.len();
let chunk_size = batch_size.div_ceil(threads);
let mut inputs = vec![0; MAX_ACTIVE_BASE * batch_size];
let mut moves = vec![0; MAX_MOVES * batch_size];
let mut dist = vec![0.0; MAX_MOVES * batch_size];
std::thread::scope(|s| {
for (((data_chunk, input_chunk), moves_chunk), dist_chunk) in data
.chunks(chunk_size)
.zip(inputs.chunks_mut(MAX_ACTIVE_BASE * chunk_size))
.zip(moves.chunks_mut(MAX_MOVES * chunk_size))
.zip(dist.chunks_mut(MAX_MOVES * chunk_size))
{
s.spawn(move || {
for (i, point) in data_chunk.iter().enumerate() {
let input_offset = MAX_ACTIVE_BASE * i;
let moves_offset = MAX_MOVES * i;
let mut j = 0;
inputs::map_base_inputs(&point.pos, |feat| {
assert!(feat < INPUT_SIZE);
input_chunk[input_offset + j] = feat as i32;
j += 1;
});
for k in j..MAX_ACTIVE_BASE {
input_chunk[input_offset + k] = -1;
}
assert!(j <= MAX_ACTIVE_BASE, "More inputs provided than the specified maximum!");
let mut total = 0;
let mut distinct = 0;
let pos = &point.pos;
for &(mov, visits) in &point.moves[..point.num] {
total += visits;
let mov = Move::from(mov);
moves_chunk[moves_offset + distinct] = inputs::map_move_to_index(pos, mov) as i32;
dist_chunk[moves_offset + distinct] = f32::from(visits);
distinct += 1;
}
for k in distinct..MAX_MOVES {
moves_chunk[moves_offset + k] = -1;
}
let total = f32::from(total);
for idx in 0..distinct {
dist_chunk[moves_offset + idx] /= total;
}
}
});
}
});
let mut prep = PreparedBatchHost { batch_size, inputs: Default::default() };
unsafe {
prep.inputs.insert(
"inputs".to_string(),
HostMatrix::Sparse(HostSparseMatrix::new(
inputs,
Some(batch_size),
Shape::new(INPUT_SIZE, 1),
MAX_ACTIVE_BASE,
)),
);
prep.inputs.insert(
"moves".to_string(),
HostMatrix::Sparse(HostSparseMatrix::new(
moves,
Some(batch_size),
Shape::new(NUM_MOVES_INDICES, 1),
MAX_MOVES,
)),
);
}
prep.inputs.insert(
"targets".to_string(),
HostMatrix::Dense(HostDenseMatrix::new(dist, Some(batch_size), Shape::new(MAX_MOVES, 1))),
);
prep
}
+266
View File
@@ -0,0 +1,266 @@
use std::{
fs::File,
io::{BufReader, Cursor, Read},
sync::mpsc,
time::{SystemTime, UNIX_EPOCH},
};
use montyformat::{
chess::{Castling, Move, Position},
FastDeserialise, MontyFormat,
};
use crate::inputs::MAX_MOVES;
#[derive(Clone, Copy)]
pub struct DecompressedData {
pub pos: Position,
pub castling: Castling,
pub moves: [(u16, u16); MAX_MOVES],
pub num: usize,
}
#[derive(Clone)]
pub struct DataReader {
file_path: String,
buffer_size: usize,
threads: usize,
}
impl DataReader {
pub fn new(path: &str, buffer_size_mb: usize, threads: usize) -> Self {
Self {
file_path: path.to_string(),
buffer_size: buffer_size_mb * 1024 * 1024 / std::mem::size_of::<DecompressedData>() / 2,
threads,
}
}
}
impl DataReader {
pub fn map_batches<F: FnMut(&[DecompressedData]) -> bool>(&self, batch_size: usize, mut f: F) {
let file_path = self.file_path.clone();
let buffer_size = self.buffer_size;
let threads = self.threads;
let games_per_thread = 2048;
let (game_sender, game_receiver) = mpsc::sync_channel::<Vec<u8>>(32);
std::thread::spawn(move || {
let mut buffer = Vec::new();
'dataloading: loop {
let mut reader = BufReader::new(File::open(file_path.as_str()).unwrap());
while let Ok(()) = MontyFormat::deserialise_fast_into_buffer(&mut reader, &mut buffer) {
if game_sender.send(buffer.clone()).is_err() {
break 'dataloading;
}
}
}
});
let (mini_sender, mini_receiver) = mpsc::sync_channel::<Vec<DecompressedData>>(threads);
std::thread::spawn(move || {
let mut buffer = Vec::new();
while let Ok(game_bytes) = game_receiver.recv() {
buffer.push(game_bytes);
if buffer.len() == games_per_thread * threads {
if std::thread::scope(|s| {
let mut handles = Vec::with_capacity(threads);
for chunk in buffer.chunks(games_per_thread) {
let this_sender = mini_sender.clone();
let handle = s.spawn(move || {
let mut buf = Vec::with_capacity(160 * games_per_thread);
for game_bytes in chunk {
parse_into_buffer(game_bytes, &mut buf);
}
this_sender.send(buf).is_err()
});
handles.push(handle);
}
handles.into_iter().any(|x| x.join().unwrap())
}) {
break;
}
buffer.clear();
}
}
});
let (buffer_sender, buffer_receiver) = mpsc::sync_channel::<Vec<DecompressedData>>(0);
std::thread::spawn(move || {
let mut shuffle_buffer = Vec::new();
shuffle_buffer.reserve_exact(buffer_size);
while let Ok(buffer) = mini_receiver.recv() {
if shuffle_buffer.len() + buffer.len() < shuffle_buffer.capacity() {
shuffle_buffer.extend_from_slice(&buffer);
} else {
let diff = shuffle_buffer.capacity() - shuffle_buffer.len();
shuffle_buffer.extend_from_slice(&buffer[..diff]);
if buffer_sender.send(shuffle_buffer).is_err() {
break;
}
shuffle_buffer = Vec::new();
shuffle_buffer.reserve_exact(buffer_size);
}
}
});
let (shuffled_sender, shuffled_receiver) = mpsc::sync_channel::<Vec<DecompressedData>>(0);
std::thread::spawn(move || {
while let Ok(mut inputs) = buffer_receiver.recv() {
shuffle(&mut inputs);
if shuffled_sender.send(inputs).is_err() {
break;
}
}
});
'dataloading: while let Ok(inputs) = shuffled_receiver.recv() {
for batch in inputs.chunks(batch_size) {
if f(batch) {
break 'dataloading;
}
}
}
drop(shuffled_receiver);
}
}
fn shuffle(data: &mut [DecompressedData]) {
let mut rng = Rand::with_seed();
for i in (0..data.len()).rev() {
let idx = rng.rng() as usize % (i + 1);
data.swap(idx, i);
}
}
macro_rules! read_into_primitive {
($reader:expr, $t:ty) => {{
let mut buf = [0u8; std::mem::size_of::<$t>()];
$reader.read_exact(&mut buf).unwrap();
<$t>::from_le_bytes(buf)
}};
}
fn parse_into_buffer(game: &[u8], buffer: &mut Vec<DecompressedData>) {
let mut reader = Cursor::new(game);
let mut qbbs = [0u64; 4];
for bb in &mut qbbs {
*bb = read_into_primitive!(reader, u64);
}
let stm = read_into_primitive!(reader, u8);
let enp_sq = read_into_primitive!(reader, u8);
let rights = read_into_primitive!(reader, u8);
let halfm = read_into_primitive!(reader, u8);
let fullm = read_into_primitive!(reader, u16);
let mut bbs = [0; 8];
let blc = qbbs[0];
let rqk = qbbs[1];
let nbk = qbbs[2];
let pbq = qbbs[3];
let occ = rqk | nbk | pbq;
let pnb = occ ^ qbbs[1];
let prq = occ ^ qbbs[2];
let nrk = occ ^ qbbs[3];
bbs[0] = occ ^ blc;
bbs[1] = blc;
bbs[2] = pnb & prq;
bbs[3] = pnb & nrk;
bbs[4] = pnb & nbk & pbq;
bbs[5] = prq & nrk;
bbs[6] = pbq & prq & rqk;
bbs[7] = nbk & rqk;
let mut pos = Position::from_raw(bbs, stm > 0, enp_sq, rights, halfm, fullm);
let mut rook_files = [[0; 2]; 2];
for side in &mut rook_files {
for rook in side {
*rook = read_into_primitive!(reader, u8);
}
}
let castling = Castling::from_raw(&pos, rook_files);
let _result = read_into_primitive!(reader, u8) as f32 / 2.0;
loop {
let best_move = Move::from(read_into_primitive!(reader, u16));
if best_move == Move::NULL {
break;
}
let _score = f32::from(read_into_primitive!(reader, u16)) / f32::from(u16::MAX);
let num_moves = usize::from(read_into_primitive!(reader, u8));
if num_moves > 1 && num_moves <= MAX_MOVES {
let mut policy_data = DecompressedData { pos, castling, moves: [(0, 0); MAX_MOVES], num: num_moves };
let mut count = 0;
pos.map_legal_moves(&castling, |mov| {
policy_data.moves[count].0 = mov.into();
count += 1;
});
assert_eq!(count, num_moves);
policy_data.moves[..num_moves].sort_by_key(|x| x.0);
for entry in &mut policy_data.moves[..num_moves] {
entry.1 = u16::from(read_into_primitive!(reader, u8));
}
buffer.push(policy_data);
} else {
for _ in 0..num_moves {
let _ = read_into_primitive!(reader, u8);
}
}
pos.make(best_move, &castling);
}
}
pub struct Rand(u64);
impl Rand {
pub fn with_seed() -> Self {
let seed = SystemTime::now().duration_since(UNIX_EPOCH).expect("Guaranteed increasing.").as_micros() as u64
& 0xFFFF_FFFF;
Self(seed)
}
pub fn rng(&mut self) -> u64 {
self.0 ^= self.0 << 13;
self.0 ^= self.0 >> 7;
self.0 ^= self.0 << 17;
self.0
}
}
+198
View File
@@ -0,0 +1,198 @@
//! Policy network inputs and outputs. Rigby's C++ inference (src/policy.cpp)
//! must map positions and moves exactly the same way.
//!
//! Inputs (3072): 768 piece-square features relative to the side to move
//! (own pieces 0..384, theirs 384..768, `64 * piece + square`), offset by 768
//! when the square is attacked by the opponent and by 1536 when it is defended
//! by the side to move. Squares are flipped vertically for black and
//! horizontally when the side to move's king is on files e-h.
//!
//! Outputs (NUM_MOVES_INDICES): one row per (piece, from, to) a piece could
//! ever move along, plus promotions, castling and double pawn pushes, in the
//! same oriented frame. Unlike Monty there is no SEE split.
use montyformat::chess::{Flag, Move, Piece, Position, Side};
pub const MAX_MOVES: usize = 64;
pub const INPUT_SIZE: usize = 768 * 4;
pub const MAX_ACTIVE_BASE: usize = 32;
pub const NUM_MOVES_INDICES: usize = FROM_TO;
const FROM_TO: usize = OFFSETS[5][64] + PROMOS + 2 + 8;
pub fn map_move_to_index(pos: &Position, mov: Move) -> usize {
let hm = if pos.king_index() % 8 > 3 { 7 } else { 0 };
let flip = hm ^ if pos.stm() == Side::BLACK { 56 } else { 0 };
let src = usize::from(mov.src() ^ flip);
let dst = usize::from(mov.to() ^ flip);
if mov.is_promo() {
let ffile = src % 8;
let tfile = dst % 8;
let promo_id = 2 * ffile + tfile;
OFFSETS[5][64] + (PROMOS / 4) * (mov.promo_pc() - Piece::KNIGHT) + promo_id
} else if mov.flag() == Flag::QS || mov.flag() == Flag::KS {
let is_ks = usize::from(mov.flag() == Flag::KS);
let is_hm = usize::from(hm == 0);
OFFSETS[5][64] + PROMOS + (is_ks ^ is_hm)
} else if mov.flag() == Flag::DBL {
OFFSETS[5][64] + PROMOS + 2 + (src % 8)
} else {
let pc = pos.get_pc(1 << mov.src()) - 2;
let below = DESTINATIONS[src][pc] & ((1 << dst) - 1);
OFFSETS[pc][src] + below.count_ones() as usize
}
}
pub fn map_base_inputs<F: FnMut(usize)>(pos: &Position, mut f: F) {
let vert = if pos.stm() == Side::BLACK { 56 } else { 0 };
let hori = if pos.king_index() % 8 > 3 { 7 } else { 0 };
let flip = vert ^ hori;
let threats = pos.threats_by(pos.stm() ^ 1);
let defences = pos.threats_by(pos.stm());
for piece in Piece::PAWN..=Piece::KING {
let pc = 64 * (piece - 2);
let mut our_bb = pos.piece(piece) & pos.piece(pos.stm());
let mut opp_bb = pos.piece(piece) & pos.piece(pos.stm() ^ 1);
while our_bb > 0 {
let sq = our_bb.trailing_zeros() as usize;
let mut feat = pc + (sq ^ flip);
let bit = 1 << sq;
if threats & bit > 0 {
feat += 768;
}
if defences & bit > 0 {
feat += 768 * 2;
}
f(feat);
our_bb &= our_bb - 1;
}
while opp_bb > 0 {
let sq = opp_bb.trailing_zeros() as usize;
let mut feat = 384 + pc + (sq ^ flip);
let bit = 1 << sq;
if threats & bit > 0 {
feat += 768;
}
if defences & bit > 0 {
feat += 768 * 2;
}
f(feat);
opp_bb &= opp_bb - 1;
}
}
}
pub const PROMOS: usize = 4 * 22;
macro_rules! init {
(|$sq:ident, $size:literal | $($rest:tt)+) => {{
let mut $sq = 0;
let mut res = [{$($rest)+}; $size];
while $sq < $size {
res[$sq] = {$($rest)+};
$sq += 1;
}
res
}};
}
const OFFSETS: [[usize; 65]; 6] = {
let mut offsets = [[0; 65]; 6];
let mut curr = 0;
let mut pc = 0;
while pc < 6 {
let mut sq = 0;
while sq < 64 {
offsets[pc][sq] = curr;
curr += DESTINATIONS[sq][pc].count_ones() as usize;
sq += 1;
}
offsets[pc][64] = curr;
pc += 1;
}
offsets
};
const DESTINATIONS: [[u64; 6]; 64] = init!(|sq, 64| [PAWN[sq], KNIGHT[sq], bishop(sq), rook(sq), queen(sq), KING[sq]]);
const A: u64 = 0x0101_0101_0101_0101;
const H: u64 = A << 7;
const DIAGS: [u64; 15] = [
0x0100_0000_0000_0000,
0x0201_0000_0000_0000,
0x0402_0100_0000_0000,
0x0804_0201_0000_0000,
0x1008_0402_0100_0000,
0x2010_0804_0201_0000,
0x4020_1008_0402_0100,
0x8040_2010_0804_0201,
0x0080_4020_1008_0402,
0x0000_8040_2010_0804,
0x0000_0080_4020_1008,
0x0000_0000_8040_2010,
0x0000_0000_0080_4020,
0x0000_0000_0000_8040,
0x0000_0000_0000_0080,
];
const PAWN: [u64; 64] = init!(|sq, 64| {
let bit = 1 << sq;
((bit & !A) << 7) | (bit << 8) | ((bit & !H) << 9)
});
const KNIGHT: [u64; 64] = init!(|sq, 64| {
let n = 1 << sq;
let h1 = ((n >> 1) & 0x7f7f_7f7f_7f7f_7f7f) | ((n << 1) & 0xfefe_fefe_fefe_fefe);
let h2 = ((n >> 2) & 0x3f3f_3f3f_3f3f_3f3f) | ((n << 2) & 0xfcfc_fcfc_fcfc_fcfc);
(h1 << 16) | (h1 >> 16) | (h2 << 8) | (h2 >> 8)
});
const fn bishop(sq: usize) -> u64 {
let rank = sq / 8;
let file = sq % 8;
DIAGS[file + rank].swap_bytes() ^ DIAGS[7 + file - rank]
}
const fn rook(sq: usize) -> u64 {
let rank = sq / 8;
let file = sq % 8;
(0xFF << (rank * 8)) ^ (A << file)
}
const fn queen(sq: usize) -> u64 {
bishop(sq) | rook(sq)
}
const KING: [u64; 64] = init!(|sq, 64| {
let mut k = 1 << sq;
k |= (k << 8) | (k >> 8);
k |= ((k & !A) >> 1) | ((k & !H) << 1);
k ^ (1 << sq)
});
+323
View File
@@ -0,0 +1,323 @@
//! Lc0 V6 training data (one gzipped file of 8356-byte records per game,
//! packed in hourly tar files) converted to montyformat games.
//!
//! Each record holds the position as input planes, the search's visit
//! fractions over Lc0's 1858 policy outputs (-1 for illegal moves) and the
//! move that was played. A game is rebuilt from its first record and the
//! played moves, and every record is checked against the rebuilt position:
//! the pieces must match and the moves Lc0 gave a probability must be exactly
//! the legal moves. A game is cut at the first record that fails; with the
//! LC0_DEBUG environment variable set, the reason is printed to stderr.
use montyformat::{
chess::{Castling, Flag, Move, Piece, Position, Right, Side},
MontyFormat, SearchData,
};
use crate::lc0_policy::POLICY_INDEX;
pub const RECORD_SIZE: usize = 8356;
const OFF_PROBS: usize = 8;
const OFF_PLANES: usize = 7440;
const OFF_CASTLING: usize = 8272;
const OFF_STM: usize = 8276;
const OFF_RULE50: usize = 8277;
const OFF_BEST_Q: usize = 8284;
const OFF_RESULT_Q: usize = 8308;
const OFF_PLAYED_IDX: usize = 8344;
/// Why records were dropped, and how much was kept.
#[derive(Default, Clone, Copy, Debug)]
pub struct Stats {
pub games: u64,
pub positions: u64,
pub bad_format: u64,
pub bad_start: u64,
pub cut_board: u64,
pub cut_moves: u64,
pub cut_played: u64,
pub dropped_records: u64,
}
impl Stats {
pub fn add(&mut self, o: &Stats) {
self.games += o.games;
self.positions += o.positions;
self.bad_format += o.bad_format;
self.bad_start += o.bad_start;
self.cut_board += o.cut_board;
self.cut_moves += o.cut_moves;
self.cut_played += o.cut_played;
self.dropped_records += o.dropped_records;
}
}
/// (from, to, promotion piece or 0) -> Lc0 policy index, in the side to
/// move's frame. Knight promotions are the plain move.
pub struct PolicyMap {
index: Vec<i16>,
}
fn key(from: usize, to: usize, promo: usize) -> usize {
(from * 64 + to) * 8 + promo
}
impl Default for PolicyMap {
fn default() -> Self {
let mut index = vec![-1i16; 64 * 64 * 8];
for (i, uci) in POLICY_INDEX.iter().enumerate() {
let b = uci.as_bytes();
let sq = |f: u8, r: u8| usize::from(r - b'1') * 8 + usize::from(f - b'a');
let from = sq(b[0], b[1]);
let to = sq(b[2], b[3]);
let promo = match b.get(4) {
None => 0,
Some(b'q') => Piece::QUEEN,
Some(b'r') => Piece::ROOK,
Some(b'b') => Piece::BISHOP,
Some(_) => unreachable!(),
};
index[key(from, to, promo)] = i as i16;
}
Self { index }
}
}
impl PolicyMap {
/// Lc0 index of a montyformat move. Lc0 encodes castling as the king
/// taking its own rook (e1h1 / e1a1, or wherever the rook is in Chess960).
pub fn index(&self, pos: &Position, castling: &Castling, mov: Move) -> Option<usize> {
let flip = if pos.stm() == Side::BLACK { 56 } else { 0 };
let from = usize::from(mov.src()) ^ flip;
let to = match mov.flag() {
Flag::KS => usize::from(castling.rook_file(pos.stm(), 1)),
Flag::QS => usize::from(castling.rook_file(pos.stm(), 0)),
_ => usize::from(mov.to()) ^ flip,
};
let promo = if mov.is_promo() && mov.promo_pc() != Piece::KNIGHT { mov.promo_pc() } else { 0 };
let idx = self.index[key(from, to, promo)];
(idx >= 0).then_some(idx as usize)
}
}
fn f32_at(r: &[u8], off: usize) -> f32 {
f32::from_le_bytes(r[off..off + 4].try_into().unwrap())
}
fn u16_at(r: &[u8], off: usize) -> u16 {
u16::from_le_bytes(r[off..off + 2].try_into().unwrap())
}
fn u32_at(r: &[u8], off: usize) -> u32 {
u32::from_le_bytes(r[off..off + 4].try_into().unwrap())
}
/// Bit i of the result is square i (a1 = 0) on the real board.
fn plane(r: &[u8], idx: usize, black: bool) -> u64 {
let off = OFF_PLANES + 8 * idx;
let stored = u64::from_le_bytes(r[off..off + 8].try_into().unwrap());
// Lc0 stores each plane with the bits of every byte reversed (a file
// mirror), and from the side to move's point of view.
let mut bytes = stored.to_le_bytes();
for b in &mut bytes {
*b = b.reverse_bits();
}
let oriented = u64::from_le_bytes(bytes);
if black {
oriented.swap_bytes()
} else {
oriented
}
}
/// The current position's pieces: [white, black, pawn, knight, bishop, rook, queen, king].
fn board(r: &[u8]) -> ([u64; 8], bool) {
let black = r[OFF_STM] != 0;
let (us, them) = if black { (Side::BLACK, Side::WHITE) } else { (Side::WHITE, Side::BLACK) };
let mut bbs = [0u64; 8];
for pc in 0..6 {
let ours = plane(r, pc, black);
let theirs = plane(r, 6 + pc, black);
bbs[us] |= ours;
bbs[them] |= theirs;
bbs[Piece::PAWN + pc] = ours | theirs;
}
(bbs, black)
}
fn rights(r: &[u8], black: bool) -> u8 {
let c = &r[OFF_CASTLING..OFF_CASTLING + 4]; // us_ooo, us_oo, them_ooo, them_oo
let (us_q, us_k, them_q, them_k) = if black {
(Right::BQS, Right::BKS, Right::WQS, Right::WKS)
} else {
(Right::WQS, Right::WKS, Right::BQS, Right::BKS)
};
let mut rights = 0;
for (flag, right) in c.iter().zip([us_q, us_k, them_q, them_k]) {
if *flag != 0 {
rights |= right;
}
}
rights
}
/// Castling rook files ([side][queenside, kingside]) for the given rights.
/// Lc0's classical input format only stores which rights exist, so each one
/// takes the outermost rook on its side of the king, as X-FEN does; the move
/// check catches a wrong guess. None when a right has no king or rook for it.
fn rook_files(bbs: &[u64; 8], rights: u8) -> Option<[[u8; 2]; 2]> {
let mut files = [[0, 7]; 2];
for (side, rank, qs, ks) in [(Side::WHITE, 0, Right::WQS, Right::WKS), (Side::BLACK, 7, Right::BQS, Right::BKS)] {
if rights & (qs | ks) == 0 {
continue;
}
let back = |piece: usize| ((bbs[side] & bbs[piece]) >> (8 * rank)) as u8;
let king = back(Piece::KING);
if king == 0 {
return None;
}
let kfile = king.trailing_zeros() as u8;
let rooks = back(Piece::ROOK);
let below = rooks & ((1u8 << kfile) - 1);
let above = rooks & !((2u16 << kfile) - 1) as u8;
if rights & qs != 0 {
if below == 0 {
return None;
}
files[side][0] = below.trailing_zeros() as u8;
}
if rights & ks != 0 {
if above == 0 {
return None;
}
files[side][1] = 7 - above.leading_zeros() as u8;
}
}
Some(files)
}
/// Legal moves paired with their Lc0 probability, or None when the set of
/// legal moves differs from the moves Lc0 gave a probability.
fn match_moves(pos: &Position, castling: &Castling, r: &[u8], map: &PolicyMap) -> Option<Vec<(Move, f32)>> {
let mut legal = Vec::with_capacity(64);
let mut ok = true;
pos.map_legal_moves(castling, |mov| match map.index(pos, castling, mov) {
Some(idx) => legal.push((mov, f32_at(r, OFF_PROBS + 4 * idx))),
None => ok = false,
});
if !ok || legal.iter().any(|&(_, p)| p < 0.0) {
if std::env::var("LC0_DEBUG").is_ok() {
let bad: Vec<String> =
legal.iter().filter(|&&(_, p)| p < 0.0).map(|&(m, _)| m.to_uci(castling)).collect();
eprintln!("{} ok={ok} negative: {:?}", pos.as_fen(), bad);
}
return None;
}
let with_prob = (0..1858).filter(|&i| f32_at(r, OFF_PROBS + 4 * i) >= 0.0).count();
if with_prob != legal.len() && std::env::var("LC0_DEBUG").is_ok() {
let ours: Vec<usize> = legal.iter().filter_map(|&(m, _)| map.index(pos, castling, m)).collect();
let extra: Vec<&str> = (0..1858)
.filter(|&i| f32_at(r, OFF_PROBS + 4 * i) >= 0.0 && !ours.contains(&i))
.map(|i| POLICY_INDEX[i])
.collect();
eprintln!("{} lc0-only: {:?}", pos.as_fen(), extra);
}
(with_prob == legal.len()).then_some(legal)
}
/// The game's first position. En passant is not stored, so each possible en
/// passant square is tried and the one whose legal moves match Lc0's is kept.
fn start_position(r: &[u8], map: &PolicyMap) -> Option<(Position, Castling)> {
let (bbs, black) = board(r);
let rights = rights(r, black);
let files = rook_files(&bbs, rights)?;
let halfm = r[OFF_RULE50];
let mut candidates = vec![0u8];
// A pawn of the side not to move that may just have made a double push.
let (them, rank_from, rank_to) = if black { (Side::WHITE, 1, 3) } else { (Side::BLACK, 6, 4) };
let occ = bbs[0] | bbs[1];
let mut pawns = bbs[them] & bbs[Piece::PAWN] & (0xFFu64 << (8 * rank_to));
while pawns != 0 {
let sq = pawns.trailing_zeros() as u8;
pawns &= pawns - 1;
let file = sq % 8;
let mid = (rank_from + rank_to) / 2 * 8 + file;
let from = rank_from * 8 + file;
if occ & ((1u64 << mid) | (1u64 << from)) == 0 {
candidates.push(mid);
}
}
for enp in candidates {
#[allow(deprecated)]
let pos = Position::from_raw(bbs, black, enp, rights, halfm, 1);
let castling = Castling::from_raw(&pos, files);
if match_moves(&pos, &castling, r, map).is_some() {
return Some((pos, castling));
}
}
None
}
/// Converts one game (the decompressed contents of one .gz file).
pub fn convert_game(data: &[u8], map: &PolicyMap, stats: &mut Stats) -> Option<MontyFormat> {
if data.len() < RECORD_SIZE || data.len() % RECORD_SIZE != 0 {
stats.bad_format += 1;
return None;
}
let records: Vec<&[u8]> = data.chunks_exact(RECORD_SIZE).collect();
if records.iter().any(|r| u32_at(r, 0) != 6 || u32_at(r, 4) != 1) {
stats.bad_format += 1;
stats.dropped_records += records.len() as u64;
return None;
}
let Some((startpos, castling)) = start_position(records[0], map) else {
stats.bad_start += 1;
stats.dropped_records += records.len() as u64;
return None;
};
let mut game = MontyFormat::new(startpos, castling);
// Lc0's result is from the side to move's point of view; montyformat's
// from white's.
let result_q = f32_at(records[0], OFF_RESULT_Q).clamp(-1.0, 1.0);
let white_q = if startpos.stm() == Side::BLACK { -result_q } else { result_q };
game.result = (white_q + 1.0) / 2.0;
let mut pos = startpos;
for (i, r) in records.iter().enumerate() {
let (bbs, black) = board(r);
if bbs != pos.bbs() || black != (pos.stm() == Side::BLACK) {
stats.cut_board += 1;
stats.dropped_records += (records.len() - i) as u64;
break;
}
let Some(moves) = match_moves(&pos, &castling, r, map) else {
stats.cut_moves += 1;
stats.dropped_records += (records.len() - i) as u64;
break;
};
let played_idx = usize::from(u16_at(r, OFF_PLAYED_IDX));
let Some(played) = moves.iter().map(|&(m, _)| m).find(|&m| map.index(&pos, &castling, m) == Some(played_idx)) else {
stats.cut_played += 1;
stats.dropped_records += (records.len() - i) as u64;
break;
};
let dist: Vec<(Move, u32)> = moves.iter().map(|&(m, p)| (m, (p * 1_000_000.0).round() as u32)).collect();
let score = ((f32_at(r, OFF_BEST_Q).clamp(-1.0, 1.0) + 1.0) / 2.0).clamp(0.0, 1.0);
game.push(SearchData::new(played, score, Some(dist)));
stats.positions += 1;
pos.make(played, &castling);
}
if game.moves.is_empty() {
return None;
}
stats.games += 1;
Some(game)
}
+192
View File
@@ -0,0 +1,192 @@
//! Lc0's 1858 policy outputs (lczero-training tf/policy_index.py), as UCI
//! moves from the side to move's point of view (black's moves flipped
//! vertically). A promotion without a suffix is a knight promotion.
pub const POLICY_INDEX: [&str; 1858] = [
"a1b1", "a1c1", "a1d1", "a1e1", "a1f1", "a1g1", "a1h1", "a1a2", "a1b2", "a1c2",
"a1a3", "a1b3", "a1c3", "a1a4", "a1d4", "a1a5", "a1e5", "a1a6", "a1f6", "a1a7",
"a1g7", "a1a8", "a1h8", "b1a1", "b1c1", "b1d1", "b1e1", "b1f1", "b1g1", "b1h1",
"b1a2", "b1b2", "b1c2", "b1d2", "b1a3", "b1b3", "b1c3", "b1d3", "b1b4", "b1e4",
"b1b5", "b1f5", "b1b6", "b1g6", "b1b7", "b1h7", "b1b8", "c1a1", "c1b1", "c1d1",
"c1e1", "c1f1", "c1g1", "c1h1", "c1a2", "c1b2", "c1c2", "c1d2", "c1e2", "c1a3",
"c1b3", "c1c3", "c1d3", "c1e3", "c1c4", "c1f4", "c1c5", "c1g5", "c1c6", "c1h6",
"c1c7", "c1c8", "d1a1", "d1b1", "d1c1", "d1e1", "d1f1", "d1g1", "d1h1", "d1b2",
"d1c2", "d1d2", "d1e2", "d1f2", "d1b3", "d1c3", "d1d3", "d1e3", "d1f3", "d1a4",
"d1d4", "d1g4", "d1d5", "d1h5", "d1d6", "d1d7", "d1d8", "e1a1", "e1b1", "e1c1",
"e1d1", "e1f1", "e1g1", "e1h1", "e1c2", "e1d2", "e1e2", "e1f2", "e1g2", "e1c3",
"e1d3", "e1e3", "e1f3", "e1g3", "e1b4", "e1e4", "e1h4", "e1a5", "e1e5", "e1e6",
"e1e7", "e1e8", "f1a1", "f1b1", "f1c1", "f1d1", "f1e1", "f1g1", "f1h1", "f1d2",
"f1e2", "f1f2", "f1g2", "f1h2", "f1d3", "f1e3", "f1f3", "f1g3", "f1h3", "f1c4",
"f1f4", "f1b5", "f1f5", "f1a6", "f1f6", "f1f7", "f1f8", "g1a1", "g1b1", "g1c1",
"g1d1", "g1e1", "g1f1", "g1h1", "g1e2", "g1f2", "g1g2", "g1h2", "g1e3", "g1f3",
"g1g3", "g1h3", "g1d4", "g1g4", "g1c5", "g1g5", "g1b6", "g1g6", "g1a7", "g1g7",
"g1g8", "h1a1", "h1b1", "h1c1", "h1d1", "h1e1", "h1f1", "h1g1", "h1f2", "h1g2",
"h1h2", "h1f3", "h1g3", "h1h3", "h1e4", "h1h4", "h1d5", "h1h5", "h1c6", "h1h6",
"h1b7", "h1h7", "h1a8", "h1h8", "a2a1", "a2b1", "a2c1", "a2b2", "a2c2", "a2d2",
"a2e2", "a2f2", "a2g2", "a2h2", "a2a3", "a2b3", "a2c3", "a2a4", "a2b4", "a2c4",
"a2a5", "a2d5", "a2a6", "a2e6", "a2a7", "a2f7", "a2a8", "a2g8", "b2a1", "b2b1",
"b2c1", "b2d1", "b2a2", "b2c2", "b2d2", "b2e2", "b2f2", "b2g2", "b2h2", "b2a3",
"b2b3", "b2c3", "b2d3", "b2a4", "b2b4", "b2c4", "b2d4", "b2b5", "b2e5", "b2b6",
"b2f6", "b2b7", "b2g7", "b2b8", "b2h8", "c2a1", "c2b1", "c2c1", "c2d1", "c2e1",
"c2a2", "c2b2", "c2d2", "c2e2", "c2f2", "c2g2", "c2h2", "c2a3", "c2b3", "c2c3",
"c2d3", "c2e3", "c2a4", "c2b4", "c2c4", "c2d4", "c2e4", "c2c5", "c2f5", "c2c6",
"c2g6", "c2c7", "c2h7", "c2c8", "d2b1", "d2c1", "d2d1", "d2e1", "d2f1", "d2a2",
"d2b2", "d2c2", "d2e2", "d2f2", "d2g2", "d2h2", "d2b3", "d2c3", "d2d3", "d2e3",
"d2f3", "d2b4", "d2c4", "d2d4", "d2e4", "d2f4", "d2a5", "d2d5", "d2g5", "d2d6",
"d2h6", "d2d7", "d2d8", "e2c1", "e2d1", "e2e1", "e2f1", "e2g1", "e2a2", "e2b2",
"e2c2", "e2d2", "e2f2", "e2g2", "e2h2", "e2c3", "e2d3", "e2e3", "e2f3", "e2g3",
"e2c4", "e2d4", "e2e4", "e2f4", "e2g4", "e2b5", "e2e5", "e2h5", "e2a6", "e2e6",
"e2e7", "e2e8", "f2d1", "f2e1", "f2f1", "f2g1", "f2h1", "f2a2", "f2b2", "f2c2",
"f2d2", "f2e2", "f2g2", "f2h2", "f2d3", "f2e3", "f2f3", "f2g3", "f2h3", "f2d4",
"f2e4", "f2f4", "f2g4", "f2h4", "f2c5", "f2f5", "f2b6", "f2f6", "f2a7", "f2f7",
"f2f8", "g2e1", "g2f1", "g2g1", "g2h1", "g2a2", "g2b2", "g2c2", "g2d2", "g2e2",
"g2f2", "g2h2", "g2e3", "g2f3", "g2g3", "g2h3", "g2e4", "g2f4", "g2g4", "g2h4",
"g2d5", "g2g5", "g2c6", "g2g6", "g2b7", "g2g7", "g2a8", "g2g8", "h2f1", "h2g1",
"h2h1", "h2a2", "h2b2", "h2c2", "h2d2", "h2e2", "h2f2", "h2g2", "h2f3", "h2g3",
"h2h3", "h2f4", "h2g4", "h2h4", "h2e5", "h2h5", "h2d6", "h2h6", "h2c7", "h2h7",
"h2b8", "h2h8", "a3a1", "a3b1", "a3c1", "a3a2", "a3b2", "a3c2", "a3b3", "a3c3",
"a3d3", "a3e3", "a3f3", "a3g3", "a3h3", "a3a4", "a3b4", "a3c4", "a3a5", "a3b5",
"a3c5", "a3a6", "a3d6", "a3a7", "a3e7", "a3a8", "a3f8", "b3a1", "b3b1", "b3c1",
"b3d1", "b3a2", "b3b2", "b3c2", "b3d2", "b3a3", "b3c3", "b3d3", "b3e3", "b3f3",
"b3g3", "b3h3", "b3a4", "b3b4", "b3c4", "b3d4", "b3a5", "b3b5", "b3c5", "b3d5",
"b3b6", "b3e6", "b3b7", "b3f7", "b3b8", "b3g8", "c3a1", "c3b1", "c3c1", "c3d1",
"c3e1", "c3a2", "c3b2", "c3c2", "c3d2", "c3e2", "c3a3", "c3b3", "c3d3", "c3e3",
"c3f3", "c3g3", "c3h3", "c3a4", "c3b4", "c3c4", "c3d4", "c3e4", "c3a5", "c3b5",
"c3c5", "c3d5", "c3e5", "c3c6", "c3f6", "c3c7", "c3g7", "c3c8", "c3h8", "d3b1",
"d3c1", "d3d1", "d3e1", "d3f1", "d3b2", "d3c2", "d3d2", "d3e2", "d3f2", "d3a3",
"d3b3", "d3c3", "d3e3", "d3f3", "d3g3", "d3h3", "d3b4", "d3c4", "d3d4", "d3e4",
"d3f4", "d3b5", "d3c5", "d3d5", "d3e5", "d3f5", "d3a6", "d3d6", "d3g6", "d3d7",
"d3h7", "d3d8", "e3c1", "e3d1", "e3e1", "e3f1", "e3g1", "e3c2", "e3d2", "e3e2",
"e3f2", "e3g2", "e3a3", "e3b3", "e3c3", "e3d3", "e3f3", "e3g3", "e3h3", "e3c4",
"e3d4", "e3e4", "e3f4", "e3g4", "e3c5", "e3d5", "e3e5", "e3f5", "e3g5", "e3b6",
"e3e6", "e3h6", "e3a7", "e3e7", "e3e8", "f3d1", "f3e1", "f3f1", "f3g1", "f3h1",
"f3d2", "f3e2", "f3f2", "f3g2", "f3h2", "f3a3", "f3b3", "f3c3", "f3d3", "f3e3",
"f3g3", "f3h3", "f3d4", "f3e4", "f3f4", "f3g4", "f3h4", "f3d5", "f3e5", "f3f5",
"f3g5", "f3h5", "f3c6", "f3f6", "f3b7", "f3f7", "f3a8", "f3f8", "g3e1", "g3f1",
"g3g1", "g3h1", "g3e2", "g3f2", "g3g2", "g3h2", "g3a3", "g3b3", "g3c3", "g3d3",
"g3e3", "g3f3", "g3h3", "g3e4", "g3f4", "g3g4", "g3h4", "g3e5", "g3f5", "g3g5",
"g3h5", "g3d6", "g3g6", "g3c7", "g3g7", "g3b8", "g3g8", "h3f1", "h3g1", "h3h1",
"h3f2", "h3g2", "h3h2", "h3a3", "h3b3", "h3c3", "h3d3", "h3e3", "h3f3", "h3g3",
"h3f4", "h3g4", "h3h4", "h3f5", "h3g5", "h3h5", "h3e6", "h3h6", "h3d7", "h3h7",
"h3c8", "h3h8", "a4a1", "a4d1", "a4a2", "a4b2", "a4c2", "a4a3", "a4b3", "a4c3",
"a4b4", "a4c4", "a4d4", "a4e4", "a4f4", "a4g4", "a4h4", "a4a5", "a4b5", "a4c5",
"a4a6", "a4b6", "a4c6", "a4a7", "a4d7", "a4a8", "a4e8", "b4b1", "b4e1", "b4a2",
"b4b2", "b4c2", "b4d2", "b4a3", "b4b3", "b4c3", "b4d3", "b4a4", "b4c4", "b4d4",
"b4e4", "b4f4", "b4g4", "b4h4", "b4a5", "b4b5", "b4c5", "b4d5", "b4a6", "b4b6",
"b4c6", "b4d6", "b4b7", "b4e7", "b4b8", "b4f8", "c4c1", "c4f1", "c4a2", "c4b2",
"c4c2", "c4d2", "c4e2", "c4a3", "c4b3", "c4c3", "c4d3", "c4e3", "c4a4", "c4b4",
"c4d4", "c4e4", "c4f4", "c4g4", "c4h4", "c4a5", "c4b5", "c4c5", "c4d5", "c4e5",
"c4a6", "c4b6", "c4c6", "c4d6", "c4e6", "c4c7", "c4f7", "c4c8", "c4g8", "d4a1",
"d4d1", "d4g1", "d4b2", "d4c2", "d4d2", "d4e2", "d4f2", "d4b3", "d4c3", "d4d3",
"d4e3", "d4f3", "d4a4", "d4b4", "d4c4", "d4e4", "d4f4", "d4g4", "d4h4", "d4b5",
"d4c5", "d4d5", "d4e5", "d4f5", "d4b6", "d4c6", "d4d6", "d4e6", "d4f6", "d4a7",
"d4d7", "d4g7", "d4d8", "d4h8", "e4b1", "e4e1", "e4h1", "e4c2", "e4d2", "e4e2",
"e4f2", "e4g2", "e4c3", "e4d3", "e4e3", "e4f3", "e4g3", "e4a4", "e4b4", "e4c4",
"e4d4", "e4f4", "e4g4", "e4h4", "e4c5", "e4d5", "e4e5", "e4f5", "e4g5", "e4c6",
"e4d6", "e4e6", "e4f6", "e4g6", "e4b7", "e4e7", "e4h7", "e4a8", "e4e8", "f4c1",
"f4f1", "f4d2", "f4e2", "f4f2", "f4g2", "f4h2", "f4d3", "f4e3", "f4f3", "f4g3",
"f4h3", "f4a4", "f4b4", "f4c4", "f4d4", "f4e4", "f4g4", "f4h4", "f4d5", "f4e5",
"f4f5", "f4g5", "f4h5", "f4d6", "f4e6", "f4f6", "f4g6", "f4h6", "f4c7", "f4f7",
"f4b8", "f4f8", "g4d1", "g4g1", "g4e2", "g4f2", "g4g2", "g4h2", "g4e3", "g4f3",
"g4g3", "g4h3", "g4a4", "g4b4", "g4c4", "g4d4", "g4e4", "g4f4", "g4h4", "g4e5",
"g4f5", "g4g5", "g4h5", "g4e6", "g4f6", "g4g6", "g4h6", "g4d7", "g4g7", "g4c8",
"g4g8", "h4e1", "h4h1", "h4f2", "h4g2", "h4h2", "h4f3", "h4g3", "h4h3", "h4a4",
"h4b4", "h4c4", "h4d4", "h4e4", "h4f4", "h4g4", "h4f5", "h4g5", "h4h5", "h4f6",
"h4g6", "h4h6", "h4e7", "h4h7", "h4d8", "h4h8", "a5a1", "a5e1", "a5a2", "a5d2",
"a5a3", "a5b3", "a5c3", "a5a4", "a5b4", "a5c4", "a5b5", "a5c5", "a5d5", "a5e5",
"a5f5", "a5g5", "a5h5", "a5a6", "a5b6", "a5c6", "a5a7", "a5b7", "a5c7", "a5a8",
"a5d8", "b5b1", "b5f1", "b5b2", "b5e2", "b5a3", "b5b3", "b5c3", "b5d3", "b5a4",
"b5b4", "b5c4", "b5d4", "b5a5", "b5c5", "b5d5", "b5e5", "b5f5", "b5g5", "b5h5",
"b5a6", "b5b6", "b5c6", "b5d6", "b5a7", "b5b7", "b5c7", "b5d7", "b5b8", "b5e8",
"c5c1", "c5g1", "c5c2", "c5f2", "c5a3", "c5b3", "c5c3", "c5d3", "c5e3", "c5a4",
"c5b4", "c5c4", "c5d4", "c5e4", "c5a5", "c5b5", "c5d5", "c5e5", "c5f5", "c5g5",
"c5h5", "c5a6", "c5b6", "c5c6", "c5d6", "c5e6", "c5a7", "c5b7", "c5c7", "c5d7",
"c5e7", "c5c8", "c5f8", "d5d1", "d5h1", "d5a2", "d5d2", "d5g2", "d5b3", "d5c3",
"d5d3", "d5e3", "d5f3", "d5b4", "d5c4", "d5d4", "d5e4", "d5f4", "d5a5", "d5b5",
"d5c5", "d5e5", "d5f5", "d5g5", "d5h5", "d5b6", "d5c6", "d5d6", "d5e6", "d5f6",
"d5b7", "d5c7", "d5d7", "d5e7", "d5f7", "d5a8", "d5d8", "d5g8", "e5a1", "e5e1",
"e5b2", "e5e2", "e5h2", "e5c3", "e5d3", "e5e3", "e5f3", "e5g3", "e5c4", "e5d4",
"e5e4", "e5f4", "e5g4", "e5a5", "e5b5", "e5c5", "e5d5", "e5f5", "e5g5", "e5h5",
"e5c6", "e5d6", "e5e6", "e5f6", "e5g6", "e5c7", "e5d7", "e5e7", "e5f7", "e5g7",
"e5b8", "e5e8", "e5h8", "f5b1", "f5f1", "f5c2", "f5f2", "f5d3", "f5e3", "f5f3",
"f5g3", "f5h3", "f5d4", "f5e4", "f5f4", "f5g4", "f5h4", "f5a5", "f5b5", "f5c5",
"f5d5", "f5e5", "f5g5", "f5h5", "f5d6", "f5e6", "f5f6", "f5g6", "f5h6", "f5d7",
"f5e7", "f5f7", "f5g7", "f5h7", "f5c8", "f5f8", "g5c1", "g5g1", "g5d2", "g5g2",
"g5e3", "g5f3", "g5g3", "g5h3", "g5e4", "g5f4", "g5g4", "g5h4", "g5a5", "g5b5",
"g5c5", "g5d5", "g5e5", "g5f5", "g5h5", "g5e6", "g5f6", "g5g6", "g5h6", "g5e7",
"g5f7", "g5g7", "g5h7", "g5d8", "g5g8", "h5d1", "h5h1", "h5e2", "h5h2", "h5f3",
"h5g3", "h5h3", "h5f4", "h5g4", "h5h4", "h5a5", "h5b5", "h5c5", "h5d5", "h5e5",
"h5f5", "h5g5", "h5f6", "h5g6", "h5h6", "h5f7", "h5g7", "h5h7", "h5e8", "h5h8",
"a6a1", "a6f1", "a6a2", "a6e2", "a6a3", "a6d3", "a6a4", "a6b4", "a6c4", "a6a5",
"a6b5", "a6c5", "a6b6", "a6c6", "a6d6", "a6e6", "a6f6", "a6g6", "a6h6", "a6a7",
"a6b7", "a6c7", "a6a8", "a6b8", "a6c8", "b6b1", "b6g1", "b6b2", "b6f2", "b6b3",
"b6e3", "b6a4", "b6b4", "b6c4", "b6d4", "b6a5", "b6b5", "b6c5", "b6d5", "b6a6",
"b6c6", "b6d6", "b6e6", "b6f6", "b6g6", "b6h6", "b6a7", "b6b7", "b6c7", "b6d7",
"b6a8", "b6b8", "b6c8", "b6d8", "c6c1", "c6h1", "c6c2", "c6g2", "c6c3", "c6f3",
"c6a4", "c6b4", "c6c4", "c6d4", "c6e4", "c6a5", "c6b5", "c6c5", "c6d5", "c6e5",
"c6a6", "c6b6", "c6d6", "c6e6", "c6f6", "c6g6", "c6h6", "c6a7", "c6b7", "c6c7",
"c6d7", "c6e7", "c6a8", "c6b8", "c6c8", "c6d8", "c6e8", "d6d1", "d6d2", "d6h2",
"d6a3", "d6d3", "d6g3", "d6b4", "d6c4", "d6d4", "d6e4", "d6f4", "d6b5", "d6c5",
"d6d5", "d6e5", "d6f5", "d6a6", "d6b6", "d6c6", "d6e6", "d6f6", "d6g6", "d6h6",
"d6b7", "d6c7", "d6d7", "d6e7", "d6f7", "d6b8", "d6c8", "d6d8", "d6e8", "d6f8",
"e6e1", "e6a2", "e6e2", "e6b3", "e6e3", "e6h3", "e6c4", "e6d4", "e6e4", "e6f4",
"e6g4", "e6c5", "e6d5", "e6e5", "e6f5", "e6g5", "e6a6", "e6b6", "e6c6", "e6d6",
"e6f6", "e6g6", "e6h6", "e6c7", "e6d7", "e6e7", "e6f7", "e6g7", "e6c8", "e6d8",
"e6e8", "e6f8", "e6g8", "f6a1", "f6f1", "f6b2", "f6f2", "f6c3", "f6f3", "f6d4",
"f6e4", "f6f4", "f6g4", "f6h4", "f6d5", "f6e5", "f6f5", "f6g5", "f6h5", "f6a6",
"f6b6", "f6c6", "f6d6", "f6e6", "f6g6", "f6h6", "f6d7", "f6e7", "f6f7", "f6g7",
"f6h7", "f6d8", "f6e8", "f6f8", "f6g8", "f6h8", "g6b1", "g6g1", "g6c2", "g6g2",
"g6d3", "g6g3", "g6e4", "g6f4", "g6g4", "g6h4", "g6e5", "g6f5", "g6g5", "g6h5",
"g6a6", "g6b6", "g6c6", "g6d6", "g6e6", "g6f6", "g6h6", "g6e7", "g6f7", "g6g7",
"g6h7", "g6e8", "g6f8", "g6g8", "g6h8", "h6c1", "h6h1", "h6d2", "h6h2", "h6e3",
"h6h3", "h6f4", "h6g4", "h6h4", "h6f5", "h6g5", "h6h5", "h6a6", "h6b6", "h6c6",
"h6d6", "h6e6", "h6f6", "h6g6", "h6f7", "h6g7", "h6h7", "h6f8", "h6g8", "h6h8",
"a7a1", "a7g1", "a7a2", "a7f2", "a7a3", "a7e3", "a7a4", "a7d4", "a7a5", "a7b5",
"a7c5", "a7a6", "a7b6", "a7c6", "a7b7", "a7c7", "a7d7", "a7e7", "a7f7", "a7g7",
"a7h7", "a7a8", "a7b8", "a7c8", "b7b1", "b7h1", "b7b2", "b7g2", "b7b3", "b7f3",
"b7b4", "b7e4", "b7a5", "b7b5", "b7c5", "b7d5", "b7a6", "b7b6", "b7c6", "b7d6",
"b7a7", "b7c7", "b7d7", "b7e7", "b7f7", "b7g7", "b7h7", "b7a8", "b7b8", "b7c8",
"b7d8", "c7c1", "c7c2", "c7h2", "c7c3", "c7g3", "c7c4", "c7f4", "c7a5", "c7b5",
"c7c5", "c7d5", "c7e5", "c7a6", "c7b6", "c7c6", "c7d6", "c7e6", "c7a7", "c7b7",
"c7d7", "c7e7", "c7f7", "c7g7", "c7h7", "c7a8", "c7b8", "c7c8", "c7d8", "c7e8",
"d7d1", "d7d2", "d7d3", "d7h3", "d7a4", "d7d4", "d7g4", "d7b5", "d7c5", "d7d5",
"d7e5", "d7f5", "d7b6", "d7c6", "d7d6", "d7e6", "d7f6", "d7a7", "d7b7", "d7c7",
"d7e7", "d7f7", "d7g7", "d7h7", "d7b8", "d7c8", "d7d8", "d7e8", "d7f8", "e7e1",
"e7e2", "e7a3", "e7e3", "e7b4", "e7e4", "e7h4", "e7c5", "e7d5", "e7e5", "e7f5",
"e7g5", "e7c6", "e7d6", "e7e6", "e7f6", "e7g6", "e7a7", "e7b7", "e7c7", "e7d7",
"e7f7", "e7g7", "e7h7", "e7c8", "e7d8", "e7e8", "e7f8", "e7g8", "f7f1", "f7a2",
"f7f2", "f7b3", "f7f3", "f7c4", "f7f4", "f7d5", "f7e5", "f7f5", "f7g5", "f7h5",
"f7d6", "f7e6", "f7f6", "f7g6", "f7h6", "f7a7", "f7b7", "f7c7", "f7d7", "f7e7",
"f7g7", "f7h7", "f7d8", "f7e8", "f7f8", "f7g8", "f7h8", "g7a1", "g7g1", "g7b2",
"g7g2", "g7c3", "g7g3", "g7d4", "g7g4", "g7e5", "g7f5", "g7g5", "g7h5", "g7e6",
"g7f6", "g7g6", "g7h6", "g7a7", "g7b7", "g7c7", "g7d7", "g7e7", "g7f7", "g7h7",
"g7e8", "g7f8", "g7g8", "g7h8", "h7b1", "h7h1", "h7c2", "h7h2", "h7d3", "h7h3",
"h7e4", "h7h4", "h7f5", "h7g5", "h7h5", "h7f6", "h7g6", "h7h6", "h7a7", "h7b7",
"h7c7", "h7d7", "h7e7", "h7f7", "h7g7", "h7f8", "h7g8", "h7h8", "a8a1", "a8h1",
"a8a2", "a8g2", "a8a3", "a8f3", "a8a4", "a8e4", "a8a5", "a8d5", "a8a6", "a8b6",
"a8c6", "a8a7", "a8b7", "a8c7", "a8b8", "a8c8", "a8d8", "a8e8", "a8f8", "a8g8",
"a8h8", "b8b1", "b8b2", "b8h2", "b8b3", "b8g3", "b8b4", "b8f4", "b8b5", "b8e5",
"b8a6", "b8b6", "b8c6", "b8d6", "b8a7", "b8b7", "b8c7", "b8d7", "b8a8", "b8c8",
"b8d8", "b8e8", "b8f8", "b8g8", "b8h8", "c8c1", "c8c2", "c8c3", "c8h3", "c8c4",
"c8g4", "c8c5", "c8f5", "c8a6", "c8b6", "c8c6", "c8d6", "c8e6", "c8a7", "c8b7",
"c8c7", "c8d7", "c8e7", "c8a8", "c8b8", "c8d8", "c8e8", "c8f8", "c8g8", "c8h8",
"d8d1", "d8d2", "d8d3", "d8d4", "d8h4", "d8a5", "d8d5", "d8g5", "d8b6", "d8c6",
"d8d6", "d8e6", "d8f6", "d8b7", "d8c7", "d8d7", "d8e7", "d8f7", "d8a8", "d8b8",
"d8c8", "d8e8", "d8f8", "d8g8", "d8h8", "e8e1", "e8e2", "e8e3", "e8a4", "e8e4",
"e8b5", "e8e5", "e8h5", "e8c6", "e8d6", "e8e6", "e8f6", "e8g6", "e8c7", "e8d7",
"e8e7", "e8f7", "e8g7", "e8a8", "e8b8", "e8c8", "e8d8", "e8f8", "e8g8", "e8h8",
"f8f1", "f8f2", "f8a3", "f8f3", "f8b4", "f8f4", "f8c5", "f8f5", "f8d6", "f8e6",
"f8f6", "f8g6", "f8h6", "f8d7", "f8e7", "f8f7", "f8g7", "f8h7", "f8a8", "f8b8",
"f8c8", "f8d8", "f8e8", "f8g8", "f8h8", "g8g1", "g8a2", "g8g2", "g8b3", "g8g3",
"g8c4", "g8g4", "g8d5", "g8g5", "g8e6", "g8f6", "g8g6", "g8h6", "g8e7", "g8f7",
"g8g7", "g8h7", "g8a8", "g8b8", "g8c8", "g8d8", "g8e8", "g8f8", "g8h8", "h8a1",
"h8h1", "h8b2", "h8h2", "h8c3", "h8h3", "h8d4", "h8h4", "h8e5", "h8h5", "h8f6",
"h8g6", "h8h6", "h8f7", "h8g7", "h8h7", "h8a8", "h8b8", "h8c8", "h8d8", "h8e8",
"h8f8", "h8g8", "a7a8q", "a7a8r", "a7a8b", "a7b8q", "a7b8r", "a7b8b", "b7a8q", "b7a8r",
"b7a8b", "b7b8q", "b7b8r", "b7b8b", "b7c8q", "b7c8r", "b7c8b", "c7b8q", "c7b8r", "c7b8b",
"c7c8q", "c7c8r", "c7c8b", "c7d8q", "c7d8r", "c7d8b", "d7c8q", "d7c8r", "d7c8b", "d7d8q",
"d7d8r", "d7d8b", "d7e8q", "d7e8r", "d7e8b", "e7d8q", "e7d8r", "e7d8b", "e7e8q", "e7e8r",
"e7e8b", "e7f8q", "e7f8r", "e7f8b", "f7e8q", "f7e8r", "f7e8b", "f7f8q", "f7f8r", "f7f8b",
"f7g8q", "f7g8r", "f7g8b", "g7f8q", "g7f8r", "g7f8b", "g7g8q", "g7g8r", "g7g8b", "g7h8q",
"g7h8r", "g7h8b", "h7g8q", "h7g8r", "h7g8b", "h7h8q", "h7h8r", "h7h8b",
];
+5
View File
@@ -0,0 +1,5 @@
pub mod data;
pub mod inputs;
pub mod lc0;
pub mod lc0_policy;
pub mod model;
+155
View File
@@ -0,0 +1,155 @@
//! Rigby policy network trainer.
//!
//! Architecture: 3072 threat inputs -> HIDDEN -> CReLU -> pairwise multiply
//! (HIDDEN / 2) -> one output row per legal move, softmax over the legal moves.
//! Data: Lc0 self-play converted to montyformat by `lc02monty`, shuffled across
//! files by `interleave`. Target: Lc0's visit distribution.
//!
//! Usage:
//! rigby-policy [--data FILE] [--superbatches N] [--hidden N] [--id NAME] [--buffer-mb N] [--batches N]
//!
//! A superbatch is `--batches` batches of 16384 positions (default 6104, about
//! 100M positions); fewer batches make quick test runs.
//! rigby-policy --check checkpoints/<id>-<superbatch> [--hidden N]
//!
//! `--check` loads a checkpoint and prints the policy of a few fixed positions,
//! as a reference for the engine's inference (Rigby's `policyfens` command
//! prints the same list).
//!
//! checkpoints/<id>-<superbatch>/quantised.bin is written every SAVE_RATE
//! superbatches and at the end; README.md describes its layout.
use acyclib::{
device::Device,
trainer::{
optimiser::{
adam::{AdamW, AdamWParams},
Optimiser,
},
schedule::{TrainingSchedule, TrainingSteps},
Trainer,
},
};
use bullet_cuda_backend::CudaDevice;
use rigby_policy::{data::MontyDataLoader, model};
const DEFAULT_DATA: &str = "../data/lc0/policy.binpack";
const DEFAULT_SUPERBATCHES: usize = 10;
const DEFAULT_HIDDEN: usize = 1024;
const DEFAULT_BUFFER_MB: usize = 4096;
const SAVE_RATE: usize = 5;
const BATCH_SIZE: usize = 16_384;
const BATCHES_PER_SUPERBATCH: usize = 6104;
const INITIAL_LR: f32 = 0.001;
const FINAL_LR: f32 = 0.00001;
/// Positions for `--check`; keep in sync with Rigby's `policyfens` command.
pub const CHECK_FENS: [&str; 6] = [
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq - 0 1",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R b KQkq - 0 1",
"6k1/5pp1/1p2p2p/1Pq1Pn2/2P2P2/6P1/4Q1BP/6K1 w - - 1 30",
"8/2P2k2/8/8/8/8/5K2/8 w - - 0 1",
];
struct Args {
data: String,
superbatches: usize,
hidden: usize,
id: String,
buffer_mb: usize,
batches: usize,
check: Option<String>,
}
fn parse_args() -> Args {
let mut args = Args {
data: DEFAULT_DATA.to_string(),
superbatches: DEFAULT_SUPERBATCHES,
hidden: DEFAULT_HIDDEN,
id: "rigby-policy".to_string(),
buffer_mb: DEFAULT_BUFFER_MB,
batches: BATCHES_PER_SUPERBATCH,
check: None,
};
let mut it = std::env::args().skip(1);
let number = |v: Option<String>, name: &str| -> usize {
v.unwrap_or_else(|| panic!("{name} needs a number")).parse().expect("not a number")
};
while let Some(arg) = it.next() {
match arg.as_str() {
"--data" => args.data = it.next().expect("--data needs a path"),
"--superbatches" => args.superbatches = number(it.next(), "--superbatches"),
"--hidden" => args.hidden = number(it.next(), "--hidden"),
"--buffer-mb" => args.buffer_mb = number(it.next(), "--buffer-mb"),
"--batches" => args.batches = number(it.next(), "--batches"),
"--id" => args.id = it.next().expect("--id needs a name"),
"--check" => args.check = Some(it.next().expect("--check needs a checkpoint directory")),
other => panic!("unknown argument: {other}"),
}
}
assert!(args.hidden % 2 == 0, "--hidden must be even");
if args.check.is_none() {
assert!(std::path::Path::new(&args.data).exists(), "data file not found: {}", args.data);
}
args
}
fn main() {
let args = parse_args();
let device = CudaDevice::new(0).unwrap();
let (graph, node) = model::make(device, args.hidden);
let params = AdamWParams { decay: 0.01, beta1: 0.9, beta2: 0.999, min_weight: -0.99, max_weight: 0.99 };
let optimiser = Optimiser::<_, _, AdamW<_>>::new(graph, params).unwrap();
let mut trainer = Trainer { optimiser, state: () };
if let Some(checkpoint) = &args.check {
trainer.optimiser.load_from_checkpoint(&format!("{checkpoint}/optimiser_state")).unwrap();
for fen in CHECK_FENS {
model::eval(&mut trainer.optimiser.graph, node, fen);
}
return;
}
let dataloader = MontyDataLoader::new(&args.data, args.buffer_mb, 4, 8);
let end_superbatch = args.superbatches;
let steps =
TrainingSteps { batch_size: BATCH_SIZE, batches_per_superbatch: args.batches, start_superbatch: 1, end_superbatch };
let schedule = TrainingSchedule {
steps,
log_rate: 64,
lr_schedule: Box::new(move |_, sb| {
if sb >= end_superbatch {
return FINAL_LR;
}
let lambda = sb as f32 / end_superbatch as f32;
INITIAL_LR * (FINAL_LR / INITIAL_LR).powf(lambda)
}),
};
let id = args.id.clone();
trainer
.train_custom(
schedule,
dataloader,
|_, _, _, _| {},
|trainer, superbatch| {
if superbatch % SAVE_RATE == 0 || superbatch == end_superbatch {
let dir = format!("checkpoints/{id}-{superbatch}");
println!("Saving checkpoint {dir}");
std::fs::create_dir_all(format!("{dir}/optimiser_state")).unwrap();
trainer.optimiser.write_to_checkpoint(&format!("{dir}/optimiser_state")).unwrap();
model::save_quantised(&trainer.optimiser.graph, &format!("{dir}/quantised.bin")).unwrap();
}
},
)
.unwrap();
model::eval(&mut trainer.optimiser.graph, node, CHECK_FENS[0]);
}
+92
View File
@@ -0,0 +1,92 @@
mod loss;
mod select_affine;
use acyclib::{
device::tensor::Shape,
graph::{builder::GraphBuilder, Graph, GraphNodeId, GraphNodeIdTy},
trainer::dataloader::PreparedBatchDevice,
};
use bullet_cuda_backend::CudaDevice;
use montyformat::chess::{Castling, Move, Position};
use crate::{
data::{loader::prepare, reader::DecompressedData},
inputs::{INPUT_SIZE, MAX_ACTIVE_BASE, MAX_MOVES, NUM_MOVES_INDICES},
};
pub fn make(device: CudaDevice, hl: usize) -> (Graph<CudaDevice>, GraphNodeId) {
let builder = GraphBuilder::default();
let inputs = builder.new_sparse_input("inputs", Shape::new(INPUT_SIZE, 1), MAX_ACTIVE_BASE);
let targets = builder.new_dense_input("targets", Shape::new(MAX_MOVES, 1));
let moves = builder.new_sparse_input("moves", Shape::new(NUM_MOVES_INDICES, 1), MAX_MOVES);
let l0 = builder.new_affine("l0", INPUT_SIZE, hl);
let l1 = builder.new_affine("l1", hl / 2, NUM_MOVES_INDICES);
let hl = l0.forward(inputs).crelu().pairwise_mul();
let logits = builder.apply(select_affine::SelectAffine::new(l1, hl, moves));
let ones = builder.new_constant(Shape::new(1, MAX_MOVES), &[1.0; MAX_MOVES]);
let loss = builder.apply(loss::OptimisedSoftmaxCrossEntropy::new(logits, targets));
let _ = ones.matmul(loss);
let node = GraphNodeId::new(loss.annotated_node().idx, GraphNodeIdTy::Ancillary(0));
(builder.build(device), node)
}
pub fn eval(graph: &mut Graph<CudaDevice>, node: GraphNodeId, fen: &str) {
let mut castling = Castling::default();
let pos = Position::parse_fen(fen, &mut castling);
let mut moves = [(0, 0); 64];
let mut num = 0;
pos.map_legal_moves(&castling, |mov| {
moves[num] = (u16::from(mov), 1);
num += 1;
});
let point = DecompressedData { pos, castling, moves, num };
let data = prepare(&[point], 1);
let mut on_device = PreparedBatchDevice::new(vec![graph.device()], &data).unwrap();
on_device.load_into_graph(graph).unwrap();
let _ = graph.forward().unwrap();
let dist = graph.get(node).unwrap().get_dense_vals().unwrap();
let mut out: Vec<(String, f32)> =
(0..num).map(|i| (Move::from(moves[i].0).to_uci(&castling), dist[i] * 100.0)).collect();
out.sort_by(|a, b| b.1.total_cmp(&a.1).then_with(|| a.0.cmp(&b.0)));
println!();
println!("{fen}");
for (uci, pct) in out {
println!(" {uci:<6} {pct:6.2}%");
}
}
pub fn save_quantised(graph: &Graph<CudaDevice>, path: &str) -> std::io::Result<()> {
use std::io::Write;
let mut file = std::fs::File::create(path).unwrap();
let mut quant = Vec::new();
for id in ["l0w", "l0b", "l1w", "l1b"] {
let vals = graph.get_weights(id).get_dense_vals().unwrap();
for x in vals {
let q = (x * 128.0).round() as i8;
assert_eq!((x * 128.0).round(), f32::from(q));
quant.extend_from_slice(&q.to_le_bytes());
}
}
file.write_all(&quant)
}
+105
View File
@@ -0,0 +1,105 @@
use std::num::NonZeroUsize;
use acyclib::{
dag::NodeId,
device::{
function::{self, DeviceFunction},
tensor::Shape,
},
graph::{
builder::GraphBuilderNode,
ir::{
node::AnnotatedNode,
operation::{binary::SoftmaxCrossEntropy, GraphIROperationBase, GraphIROperationCompilable},
GraphIR, GraphIRError,
},
Graph, GraphNodeIdTy,
},
};
use bullet_cuda_backend::{
kernel::{Expr, Kernel, KernelArgs, KernelInput},
CudaDevice, CudaMarker,
};
use crate::inputs::MAX_MOVES;
#[derive(Clone, Debug)]
pub struct OptimisedSoftmaxCrossEntropy(SoftmaxCrossEntropy);
impl OptimisedSoftmaxCrossEntropy {
pub fn new<'a>(logits: GraphBuilderNode<'a, CudaMarker>, targets: GraphBuilderNode<'a, CudaMarker>) -> Self {
Self(SoftmaxCrossEntropy { logits: logits.annotated_node(), targets: targets.annotated_node() })
}
}
impl GraphIROperationBase<CudaMarker> for OptimisedSoftmaxCrossEntropy {
fn nodes(&self) -> Vec<AnnotatedNode> {
GraphIROperationBase::<CudaMarker>::nodes(&self.0)
}
fn output_shape(&self, ir: &GraphIR<CudaMarker>) -> Result<Shape, GraphIRError> {
assert_eq!(self.0.logits.shape, Shape::new(MAX_MOVES, 1));
self.0.output_shape(ir)
}
fn ancillary_buffers(
&self,
ir: &GraphIR<CudaMarker>,
) -> Result<Vec<(Shape, Option<NonZeroUsize>, bool)>, GraphIRError> {
self.0.ancillary_buffers(ir)
}
}
impl GraphIROperationCompilable<CudaMarker> for OptimisedSoftmaxCrossEntropy {
fn forward_pass(&self, graph: &Graph<CudaDevice>, output_node: NodeId) -> DeviceFunction<CudaDevice> {
let logits = graph.get_ref(self.0.logits.idx, GraphNodeIdTy::Values);
let targets = graph.get_ref(self.0.targets.idx, GraphNodeIdTy::Values);
let smax = graph.get_ref(output_node, GraphNodeIdTy::Ancillary(0));
let output = graph.get_ref(output_node, GraphNodeIdTy::Values);
let mut func = DeviceFunction::default();
func.push(function::MaybeUpdateBatchSize { input: logits.clone(), output: smax.clone() });
func.push(function::MaybeUpdateBatchSize { input: logits.clone(), output: output.clone() });
let threads = 512;
let entries_per_block = threads / 32;
let batch_size = Expr::Var;
let blocks = (batch_size.clone() + entries_per_block - 1) / entries_per_block;
let grid_dim = [blocks, Expr::Const(1), Expr::Const(1)];
let block_dim = [threads, 1, 1].map(Expr::Const);
let shared_mem_bytes = Expr::Const(0);
let layout = None;
let batched = logits.batch_size().is_some();
let shape = Shape::new(MAX_MOVES, 1);
let inputs = vec![
KernelInput::Size(batch_size),
KernelInput::Slice { slice: logits, layout, mutable: false, batched, shape },
KernelInput::Slice { slice: smax.clone(), layout, mutable: true, batched, shape },
];
let args = KernelArgs { inputs, grid_dim, block_dim, shared_mem_bytes };
let code = include_str!("loss/softmax.cu")
.lines()
.skip(5)
.map(|x| format!("{x}\n"))
.collect::<String>()
.replace("THREADS", &threads.to_string())
.replace("SIZE", &MAX_MOVES.to_string());
let kernel = unsafe { Kernel::new("Softmax".to_string(), code, args) };
func.push(kernel.unwrap());
func.push(function::CrossEntropy { a: smax, b: targets, output });
func
}
fn backward_pass(&self, graph: &Graph<CudaDevice>, output_node: NodeId) -> DeviceFunction<CudaDevice> {
GraphIROperationCompilable::<CudaMarker>::backward_pass(&self.0, graph, output_node)
}
}
+54
View File
@@ -0,0 +1,54 @@
#ifndef STUFF
#define THREADS 512;
#define SIZE 64
#endif
constexpr int threads = THREADS;
constexpr int per_block = threads / 32;
constexpr int size = SIZE;
constexpr int per_thread = size / 32;
extern "C" __global__ void kernel(const int k, const float* input, float* output)
{
const int entry = per_block * blockIdx.x + (threadIdx.x / 32);
const int widx = threadIdx.x % 32;
if (entry >= k)
return;
float elems[per_thread];
elems[0] = input[widx + size * entry];
float maximum = elems[0];
#pragma unroll
for (int i = 1; i < per_thread; i++) {
elems[i] = input[widx + 32 * i + size * entry];
maximum = max(maximum, elems[i]);
}
maximum = max(maximum, __shfl_xor_sync(0xffffffff, maximum, 16));
maximum = max(maximum, __shfl_xor_sync(0xffffffff, maximum, 8));
maximum = max(maximum, __shfl_xor_sync(0xffffffff, maximum, 4));
maximum = max(maximum, __shfl_xor_sync(0xffffffff, maximum, 2));
maximum = max(maximum, __shfl_xor_sync(0xffffffff, maximum, 1));
float denom = 0.0F;
#pragma unroll
for (int i = 0; i < per_thread; i++) {
elems[i] = expf(elems[i] - maximum);
denom += elems[i];
}
denom += __shfl_xor_sync(0xffffffff, denom, 16);
denom += __shfl_xor_sync(0xffffffff, denom, 8);
denom += __shfl_xor_sync(0xffffffff, denom, 4);
denom += __shfl_xor_sync(0xffffffff, denom, 2);
denom += __shfl_xor_sync(0xffffffff, denom, 1);
#pragma unroll
for (int i = 0; i < per_thread; i++) {
output[widx + 32 * i + size * entry] = elems[i] / denom;
}
}
+174
View File
@@ -0,0 +1,174 @@
use acyclib::{
dag::NodeId,
device::{
function::{DeviceFunction, MaybeUpdateBatchSize},
tensor::Shape,
},
graph::{
builder::{Affine, GraphBuilderNode},
ir::{
node::AnnotatedNode,
operation::{util, GraphIROperationBase, GraphIROperationCompilable},
BackendMarker, GraphIR, GraphIRError,
},
Graph, GraphNodeIdTy,
},
};
use bullet_cuda_backend::{
kernel::{Expr, Kernel, KernelArgs, KernelInput},
CudaDevice, CudaMarker,
};
use crate::inputs::{MAX_MOVES, NUM_MOVES_INDICES};
#[derive(Debug)]
pub struct SelectAffine {
weights: AnnotatedNode,
biases: AnnotatedNode,
input: AnnotatedNode,
indices: AnnotatedNode,
}
impl SelectAffine {
pub fn new<'a>(
affine: Affine<'a, CudaMarker>,
input: GraphBuilderNode<'a, CudaMarker>,
indices: GraphBuilderNode<'a, CudaMarker>,
) -> Self {
Self {
weights: affine.weights.reshape(affine.weights.annotated_node().shape.transpose()).annotated_node(),
biases: affine.bias.annotated_node(),
input: input.annotated_node(),
indices: indices.annotated_node(),
}
}
}
impl<B: BackendMarker> GraphIROperationBase<B> for SelectAffine {
fn nodes(&self) -> Vec<AnnotatedNode> {
vec![self.indices, self.input, self.weights, self.biases]
}
fn output_shape(&self, ir: &GraphIR<B>) -> Result<Shape, GraphIRError> {
assert_eq!(self.weights.shape, Shape::new(self.input.shape.rows(), NUM_MOVES_INDICES));
assert_eq!(self.biases.shape, Shape::new(NUM_MOVES_INDICES, 1));
util::check_same_batching(ir, &[&self.indices, &self.input])?;
util::check_dense_eq(ir, &self.input, true)?;
util::check_dense_eq(ir, &self.indices, false)?;
util::check_dense_eq(ir, &self.weights, true)?;
util::check_dense_eq(ir, &self.biases, true)?;
util::check_not_batched(ir, &self.weights)?;
util::check_not_batched(ir, &self.biases)?;
Ok(Shape::new(MAX_MOVES, 1))
}
}
impl GraphIROperationCompilable<CudaMarker> for SelectAffine {
fn forward_pass(&self, graph: &Graph<CudaDevice>, output_node: NodeId) -> DeviceFunction<CudaDevice> {
let input = graph.get_ref(self.input.idx, GraphNodeIdTy::Values);
let indices = graph.get_ref(self.indices.idx, GraphNodeIdTy::Values);
let weights = graph.get_ref(self.weights.idx, GraphNodeIdTy::Values);
let biases = graph.get_ref(self.biases.idx, GraphNodeIdTy::Values);
let output = graph.get_ref(output_node, GraphNodeIdTy::Values);
let mut func = DeviceFunction::default();
func.push(MaybeUpdateBatchSize { input: input.clone(), output: output.clone() });
let single_size = input.single_size();
let batch_size = Expr::Var;
let threads = (single_size / 4).min(512) as i32;
let grid_dim = [Expr::Const(64), batch_size, Expr::Const(1)];
let block_dim = [threads, 1, 1].map(Expr::Const);
let shared_mem_bytes = Expr::Const(4 * threads);
assert!((threads as u32).is_power_of_two(), "hl size must be a power of 2");
assert_eq!(MAX_MOVES, 64);
let layout = None;
let mutable = false;
let inputs = vec![
KernelInput::Slice { slice: weights, layout, mutable, batched: false, shape: self.weights.shape },
KernelInput::Slice { slice: biases, layout, mutable, batched: false, shape: self.biases.shape },
KernelInput::Slice { slice: input, layout, mutable, batched: true, shape: self.input.shape },
KernelInput::Slice { slice: indices, layout: Some(64), mutable, batched: true, shape: self.indices.shape },
KernelInput::Slice { slice: output, layout, mutable: true, batched: true, shape: Shape::new(MAX_MOVES, 1) },
];
let args = KernelArgs { inputs, block_dim, grid_dim, shared_mem_bytes };
let code = include_str!("select_affine/fwd.cu")
.lines()
.skip(5)
.map(|x| format!("{x}\n"))
.collect::<String>()
.replace("THREADS", &threads.to_string())
.replace("IN_SIZE", &single_size.to_string());
let kernel = unsafe { Kernel::new("SelectAffineFwd".to_string(), code, args) };
func.push(kernel.unwrap());
func
}
fn backward_pass(&self, graph: &Graph<CudaDevice>, output_node: NodeId) -> DeviceFunction<CudaDevice> {
let input = graph.get_ref(self.input.idx, GraphNodeIdTy::Values);
let indices = graph.get_ref(self.indices.idx, GraphNodeIdTy::Values);
let weights = graph.get_ref(self.weights.idx, GraphNodeIdTy::Values);
let input_grad = graph.get_ref(self.input.idx, GraphNodeIdTy::Gradients);
let weights_grad = graph.get_ref(self.weights.idx, GraphNodeIdTy::Gradients);
let biases_grad = graph.get_ref(self.biases.idx, GraphNodeIdTy::Gradients);
let output_grad = graph.get_ref(output_node, GraphNodeIdTy::Gradients);
let mut func = DeviceFunction::default();
func.push(MaybeUpdateBatchSize { input: output_grad.clone(), output: input_grad.clone() });
assert_eq!(MAX_MOVES, 64);
let single_size = input.single_size();
let batch_size = Expr::Var;
let threads = (single_size / 4).min(1024) as i32;
let grid_dim = [Expr::Const(64), batch_size, Expr::Const(1)];
let block_dim = [threads, 1, 1].map(Expr::Const);
let shared_mem_bytes = Expr::Const(16 * threads);
let layout = None;
let mutable = false;
let inputs = vec![
KernelInput::Slice { slice: weights, layout, mutable, batched: false, shape: self.weights.shape },
KernelInput::Slice { slice: input, layout, mutable, batched: true, shape: self.input.shape },
KernelInput::Slice { slice: indices, layout: Some(64), mutable, batched: true, shape: self.indices.shape },
KernelInput::Slice { slice: output_grad, layout, mutable, batched: true, shape: Shape::new(MAX_MOVES, 1) },
KernelInput::Slice { slice: input_grad, layout, mutable: true, batched: true, shape: self.input.shape },
KernelInput::Slice {
slice: weights_grad,
layout,
mutable: true,
batched: false,
shape: self.weights.shape,
},
KernelInput::Slice { slice: biases_grad, layout, mutable: true, batched: false, shape: self.biases.shape },
];
let args = KernelArgs { inputs, grid_dim, block_dim, shared_mem_bytes };
let code = include_str!("select_affine/bwd.cu")
.lines()
.skip(4)
.map(|x| format!("{x}\n"))
.collect::<String>()
.replace("IN_SIZE", &single_size.to_string());
let kernel = unsafe { Kernel::new("SelectAffineBwd".to_string(), code, args) };
func.push(kernel.unwrap());
func
}
}
@@ -0,0 +1,67 @@
#ifndef STUFF
#define IN_SIZE 1024
#endif
constexpr int in_size = IN_SIZE;
extern "C" __global__ void kernel(
const float* weights,
const float* input,
const int* moves,
const float* output_grad,
float* input_grad,
float* weights_grad,
float* biases_grad
) {
extern __shared__ float sdata[];
const int batch_size = gridDim.y;
const int loc_in_batch = blockIdx.y;
const int loc_in_moves = blockIdx.x;
const int tid = threadIdx.x;
const int locmb = loc_in_batch * 64 + loc_in_moves;
const int move = moves[locmb];
if (move != -1)
{
const float grd = output_grad[locmb];
const float4* tW = reinterpret_cast<const float4*>(weights + in_size * move);
const float4* tI = reinterpret_cast<const float4*>(input + in_size * loc_in_batch);
if (tid == 0) atomicAdd(biases_grad + move, grd);
for (int idx = tid; idx < in_size / 4; idx += blockDim.x)
{
const int section = 4 * blockDim.x * (idx / blockDim.x) + tid;
const float4 ti = tI[idx];
const float4 tw = tW[idx];
sdata[4 * tid ] = ti.x;
sdata[4 * tid + 1] = ti.y;
sdata[4 * tid + 2] = ti.z;
sdata[4 * tid + 3] = ti.w;
__syncthreads();
float* tWg = weights_grad + in_size * move + section;
atomicAdd(tWg , grd * sdata[tid ]);
atomicAdd(tWg + blockDim.x , grd * sdata[tid + blockDim.x ]);
atomicAdd(tWg + blockDim.x * 2, grd * sdata[tid + blockDim.x * 2]);
atomicAdd(tWg + blockDim.x * 3, grd * sdata[tid + blockDim.x * 3]);
__syncthreads();
sdata[4 * tid ] = tw.x;
sdata[4 * tid + 1] = tw.y;
sdata[4 * tid + 2] = tw.z;
sdata[4 * tid + 3] = tw.w;
__syncthreads();
float* tIg = input_grad + in_size * loc_in_batch + section;
atomicAdd(tIg , grd * sdata[tid ]);
atomicAdd(tIg + blockDim.x , grd * sdata[tid + blockDim.x ]);
atomicAdd(tIg + blockDim.x * 2, grd * sdata[tid + blockDim.x * 2]);
atomicAdd(tIg + blockDim.x * 3, grd * sdata[tid + blockDim.x * 3]);
__syncthreads();
}
}
}
@@ -0,0 +1,68 @@
#ifndef STUFF
#define THREADS 512
#define IN_SIZE 1024
#endif
constexpr int threads = THREADS;
constexpr int in_size = IN_SIZE;
extern "C" __global__ void kernel(
const float* weights,
const float* biases,
const float* input,
const int* moves,
float* output
) {
extern __shared__ float sdata[];
const int batch_size = gridDim.y;
const int loc_in_batch = blockIdx.y;
const int loc_in_moves = blockIdx.x;
const int tid = threadIdx.x;
const int locmb = loc_in_batch * 64 + loc_in_moves;
const int move = moves[locmb];
const float4* tW = reinterpret_cast<const float4*>(weights + in_size * move);
const float4* tI = reinterpret_cast<const float4*>(input + in_size * loc_in_batch);
if (move != -1)
{
float local = 0.0F;
#pragma unroll
for (int idx = tid; idx < in_size / 4; idx += threads)
{
const float4 tw = tW[idx];
const float4 ti = tI[idx];
local += tw.x * ti.x + tw.y * ti.y + tw.z * ti.z + tw.w * ti.w;
}
sdata[tid] = local;
__syncthreads();
if constexpr (threads >= 1024) { if (tid < 512) sdata[tid] += sdata[tid + 512]; __syncthreads(); }
if constexpr (threads >= 512) { if (tid < 256) sdata[tid] += sdata[tid + 256]; __syncthreads(); }
if constexpr (threads >= 256) { if (tid < 128) sdata[tid] += sdata[tid + 128]; __syncthreads(); }
if constexpr (threads >= 128) { if (tid < 64) sdata[tid] += sdata[tid + 64]; __syncthreads(); }
if (tid < 32)
{
float partial = sdata[tid];
if constexpr (threads >= 64) { partial += sdata[tid + 32]; }
partial += __shfl_down_sync(0xffffffff, partial, 16);
partial += __shfl_down_sync(0xffffffff, partial, 8);
partial += __shfl_down_sync(0xffffffff, partial, 4);
partial += __shfl_down_sync(0xffffffff, partial, 2);
partial += __shfl_down_sync(0xffffffff, partial, 1);
if (tid == 0)
{
output[locmb] = partial + biases[move];
}
}
}
else if (tid == 0)
{
output[locmb] = -10000.0F;
}
}
+25
View File
@@ -0,0 +1,25 @@
# Trains Rigby's policy network. Run from anywhere:
# powershell -ExecutionPolicy Bypass -File C:\Users\rektd\repos\Rigby\train\policy\train.ps1
# Extra arguments go to the trainer, e.g.:
# ... train.ps1 --superbatches 60 --hidden 4096 --id rigby-policy-v2
# ... train.ps1 --check checkpoints\rigby-policy-40
# Data: ..\data\lc0\policy.binpack, made by fetch.ps1 (or by lc02monty + interleave).
param([Parameter(ValueFromRemainingArguments = $true)] [string[]] $TrainerArgs)
# Native tools report through exit codes; 'Stop' would turn cargo's progress
# output on stderr into errors under Windows PowerShell.
$ErrorActionPreference = 'Continue'
Set-Location $PSScriptRoot
. .\env.ps1
if (-not ($TrainerArgs -contains '--data') -and -not ($TrainerArgs -contains '--check') -and
-not (Test-Path '..\data\lc0\policy.binpack')) {
throw 'No training data: ..\data\lc0\policy.binpack is missing (run fetch.ps1)'
}
cargo build --release --bin rigby-policy
if ($LASTEXITCODE -ne 0) { throw 'build failed' }
& .\target\release\rigby-policy.exe @TrainerArgs
exit $LASTEXITCODE
+671
View File
@@ -0,0 +1,671 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "anyhow"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
[[package]]
name = "arrayvec"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56"
[[package]]
name = "autocfg"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
[[package]]
name = "bitflags"
version = "2.13.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
[[package]]
name = "bullet-compiler"
version = "0.1.0"
dependencies = [
"half",
]
[[package]]
name = "bullet-gpu"
version = "0.1.0"
dependencies = [
"bullet-compiler",
]
[[package]]
name = "bullet-trainer"
version = "0.1.0"
dependencies = [
"bullet-compiler",
"bullet-gpu",
"rand_distr",
"rand_xoshiro",
]
[[package]]
name = "bullet_lib"
version = "1.0.0"
dependencies = [
"bullet-compiler",
"bullet-gpu",
"bullet-trainer",
"bulletformat",
"montyformat",
"oorandom",
"rand 0.9.5",
"sfbinpack",
"viriformat",
]
[[package]]
name = "bulletformat"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d171953264e8dc3aa62757255e602e507fdd358a94e3cdacb9e481ff3a1c6b0"
[[package]]
name = "bumpalo"
version = "3.20.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db"
[[package]]
name = "cc"
version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ef9e3e8154a45c7a95cff4c1299702106ad94062d7bb85fdc5d3a5afd91d45"
dependencies = [
"find-msvc-tools",
"jobserver",
"libc",
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
[[package]]
name = "crunchy"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
[[package]]
name = "equivalent"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"
[[package]]
name = "find-msvc-tools"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
[[package]]
name = "futures-core"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e"
[[package]]
name = "futures-task"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd"
[[package]]
name = "futures-util"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc"
dependencies = [
"futures-core",
"futures-task",
"pin-project-lite",
"slab",
]
[[package]]
name = "getrandom"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd"
dependencies = [
"cfg-if",
"libc",
"r-efi 5.3.0",
"wasip2",
]
[[package]]
name = "getrandom"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
dependencies = [
"cfg-if",
"libc",
"r-efi 6.0.0",
]
[[package]]
name = "half"
version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b"
dependencies = [
"cfg-if",
"crunchy",
"zerocopy",
]
[[package]]
name = "hashbrown"
version = "0.17.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
[[package]]
name = "indexmap"
version = "2.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "jobserver"
version = "0.1.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3"
dependencies = [
"getrandom 0.4.3",
"libc",
]
[[package]]
name = "js-sys"
version = "0.3.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a"
dependencies = [
"cfg-if",
"futures-util",
"wasm-bindgen",
]
[[package]]
name = "libc"
version = "0.2.191"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
[[package]]
name = "libm"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
[[package]]
name = "memchr"
version = "2.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
[[package]]
name = "montyformat"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4caf9c718f831a8568f030576e6a6e6aa487ed5f8732ddb0ba79e9a3ea0421ca"
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
"libm",
]
[[package]]
name = "oorandom"
version = "11.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e"
[[package]]
name = "pin-project-lite"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
[[package]]
name = "pkg-config"
version = "0.3.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548"
[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro2"
version = "1.0.107"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.47"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
dependencies = [
"proc-macro2",
]
[[package]]
name = "r-efi"
version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "r-efi"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
[[package]]
name = "rand"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41"
dependencies = [
"rand_chacha",
"rand_core 0.9.5",
]
[[package]]
name = "rand"
version = "0.10.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af"
dependencies = [
"getrandom 0.4.3",
"rand_core 0.10.1",
]
[[package]]
name = "rand_chacha"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
"ppv-lite86",
"rand_core 0.9.5",
]
[[package]]
name = "rand_core"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c"
dependencies = [
"getrandom 0.3.4",
]
[[package]]
name = "rand_core"
version = "0.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69"
[[package]]
name = "rand_distr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4d431c2703ccf129de4d45253c03f49ebb22b97d6ad79ee3ecfc7e3f4862c1d8"
dependencies = [
"num-traits",
"rand 0.10.3",
]
[[package]]
name = "rand_xoshiro"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "662effc7698e08ea324d3acccf8d9d7f7bf79b9785e270a174ea36e56900c91d"
dependencies = [
"rand_core 0.10.1",
]
[[package]]
name = "raw-cpuid"
version = "11.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "498cd0dc59d73224351ee52a95fee0f1a617a2eae0e7d9d720cc622c73a54186"
dependencies = [
"bitflags",
]
[[package]]
name = "rigby-value"
version = "0.1.0"
dependencies = [
"bullet-trainer",
"bullet_lib",
"zstd",
]
[[package]]
name = "rustversion"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
[[package]]
name = "serde"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba"
dependencies = [
"serde_core",
"serde_derive",
]
[[package]]
name = "serde_core"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.229"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
dependencies = [
"proc-macro2",
"quote",
"syn 3.0.10",
]
[[package]]
name = "serde_spanned"
version = "0.6.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3"
dependencies = [
"serde",
]
[[package]]
name = "sfbinpack"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4db427bcbaeb4745893f6cd842c50f30f21ba28d18bb9bbee48061a2fcaa7e35"
dependencies = [
"arrayvec",
"js-sys",
"raw-cpuid",
"thiserror",
"wasm-bindgen",
]
[[package]]
name = "shlex"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
[[package]]
name = "slab"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"
[[package]]
name = "syn"
version = "2.0.119"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thiserror"
version = "2.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "2.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524"
dependencies = [
"proc-macro2",
"quote",
"syn 3.0.10",
]
[[package]]
name = "toml"
version = "0.8.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.22.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"
dependencies = [
"indexmap",
"serde",
"serde_spanned",
"toml_datetime",
"toml_write",
"winnow",
]
[[package]]
name = "toml_write"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801"
[[package]]
name = "unicode-ident"
version = "1.0.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
[[package]]
name = "viriformat"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e889c0fcc2bd229a3b72e11b6b826bef4b9d107ce05f4bc2172d1a87ac5027e"
dependencies = [
"anyhow",
"arrayvec",
"bulletformat",
"rand 0.9.5",
"serde",
"toml",
]
[[package]]
name = "wasip2"
version = "1.0.4+wasi-0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487"
dependencies = [
"wit-bindgen",
]
[[package]]
name = "wasm-bindgen"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c"
dependencies = [
"cfg-if",
"rustversion",
"wasm-bindgen-macro",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a"
dependencies = [
"bumpalo",
"proc-macro2",
"quote",
"syn 3.0.10",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e"
dependencies = [
"unicode-ident",
]
[[package]]
name = "winnow"
version = "0.7.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"
dependencies = [
"memchr",
]
[[package]]
name = "wit-bindgen"
version = "0.57.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"
[[package]]
name = "zerocopy"
version = "0.8.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5fe1f8f1b06191a00962174c61aa5005e0bb391a6d80d07e24d115c01a92ed8"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "863ad3ac83293fb4d740aedbfdc9240dd8d1a50c1099acd76ce80ce7c7230c7f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]]
name = "zstd"
version = "0.13.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50adf04cf3ec914b0b9905c9dde90c80fe74bfd701e331fc80a39c512c525278"
dependencies = [
"zstd-safe",
]
[[package]]
name = "zstd-safe"
version = "7.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "498d94ad68720c89b4fbe41b9090850651e68cb2dd9210ce7ffbff3a94653819"
dependencies = [
"zstd-sys",
]
[[package]]
name = "zstd-sys"
version = "2.1.3+zstd.1.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f729a06d0257428fd9d997ac8db7e1407bd0262ab016b085b36bc52957c0052d"
dependencies = [
"cc",
"pkg-config",
]
+17
View File
@@ -0,0 +1,17 @@
[package]
name = "rigby-value"
version = "0.1.0"
edition = "2024"
publish = false
# Trains Rigby's value network with bullet on Lc0 data (Stockfish binpack format).
# bullet comes from the local clone next to this repository (C:\Users\rektd\repos\bullet).
[dependencies]
bullet_lib = { path = "../../../bullet/crates/bullet_lib", features = ["cuda"] }
bullet_trainer = { package = "bullet-trainer", path = "../../../bullet/crates/trainer" }
zstd = "0.13"
[profile.release]
opt-level = 3
lto = true
codegen-units = 1
+186
View File
@@ -0,0 +1,186 @@
//! Rigby value network trainer.
//!
//! Architecture: (768 -> HIDDEN)x2 -> 1, SCReLU, dual perspective.
//! Data: Lc0-derived positions from linrock, either Stockfish binpacks (`.binpack`,
//! filtered here) or bulletformat files, raw (`.bin`) or zstd-compressed
//! (`.bin.zst`, read directly; e.g. the S2 set, already filtered and shuffled).
//! Target: WDL * game result + (1 - WDL) * sigmoid(score / SCALE).
//!
//! Usage:
//! cargo run --release -- [--data <file>]... [--superbatches N] [--hidden N] [--id NAME] [--batches N]
//! (--batches: batches of 16384 per superbatch, 6104 = 100M positions; smaller for speed tests)
//! cargo run --release -- --check checkpoints/<id>-<superbatch> [--hidden N]
//!
//! `--check` loads a checkpoint and prints the network's evaluation (centipawns,
//! side to move) of a few fixed positions, as a reference for the engine's own
//! inference (Rigby's `evalfens` command prints the same list).
//!
//! The network is written to checkpoints/<id>-<superbatch>/quantised.bin every
//! SAVE_RATE superbatches and at the end. Inference in Rigby has to use the same
//! HIDDEN, SCALE, QA and QB.
mod zstd_reader;
use bullet_lib::{
game::inputs::Chess768,
nn::optimiser::AdamW,
trainer::{
save::SavedFormat,
schedule::{TrainingSchedule, TrainingSteps, lr, wdl},
settings::LocalSettings,
},
value::{
ValueTrainerBuilder,
loader::{
DirectSequentialDataLoader,
sfbinpack::{MoveType, PieceType, SfBinpackLoader, TrainingDataEntry},
},
},
};
const DEFAULT_HIDDEN: usize = 1024;
const SCALE: i32 = 400;
const QA: i16 = 255;
const QB: i16 = 64;
const DEFAULT_DATA: &str = "../data/test80-2024-02-feb-2tb7p.min-v2.v6.binpack";
const DEFAULT_SUPERBATCHES: usize = 40;
const SAVE_RATE: usize = 10;
const WDL: f32 = 0.4;
const LOADER_THREADS: usize = 6;
/// Keep quiet, settled positions: past the opening, not in check, a quiet best
/// move and a sane score.
fn filter(entry: &TrainingDataEntry) -> bool {
entry.ply >= 16
&& !entry.pos.is_checked(entry.pos.side_to_move())
&& entry.score.unsigned_abs() <= 10000
&& entry.mv.mtype() == MoveType::Normal
&& entry.pos.piece_at(entry.mv.to()).piece_type() == PieceType::None
}
/// Positions for `--check`; keep in sync with Rigby's `evalfens` command.
const CHECK_FENS: [&str; 8] = [
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1",
"rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR b KQkq - 0 1",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w KQkq - 0 1",
"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R b KQkq - 0 1",
"6k1/5pp1/1p2p2p/1Pq1Pn2/2P2P2/6P1/4Q1BP/6K1 w - - 1 30",
"8/8/3k4/2p1p3/2P1P3/3K4/8/8 w - - 0 1",
"4k3/8/8/8/8/8/8/R3K3 w - - 0 1",
"4k3/8/8/8/8/8/8/R3K3 b - - 0 1",
];
struct Args {
data: Vec<String>,
superbatches: usize,
hidden: usize,
batches: usize,
id: String,
check: Option<String>,
}
fn parse_args() -> Args {
let mut args = Args {
data: Vec::new(),
superbatches: DEFAULT_SUPERBATCHES,
hidden: DEFAULT_HIDDEN,
batches: 6104,
id: "rigby-value".to_string(),
check: None,
};
let mut it = std::env::args().skip(1);
while let Some(arg) = it.next() {
match arg.as_str() {
"--data" => args.data.push(it.next().expect("--data needs a path")),
"--superbatches" => {
args.superbatches = it.next().expect("--superbatches needs a number").parse().expect("not a number")
}
"--hidden" => args.hidden = it.next().expect("--hidden needs a number").parse().expect("not a number"),
"--batches" => args.batches = it.next().expect("--batches needs a number").parse().expect("not a number"),
"--id" => args.id = it.next().expect("--id needs a name"),
"--check" => args.check = Some(it.next().expect("--check needs a checkpoint directory")),
other => panic!("unknown argument: {other}"),
}
}
if args.check.is_some() {
return args;
}
if args.data.is_empty() {
args.data.push(DEFAULT_DATA.to_string());
}
for path in &args.data {
assert!(std::path::Path::new(path).exists(), "data file not found: {path}");
}
args
}
fn main() {
let args = parse_args();
let hidden = args.hidden;
let mut trainer = ValueTrainerBuilder::default()
.dual_perspective()
.optimiser(AdamW)
.inputs(Chess768)
.save_format(&[
SavedFormat::id("l0w").round().quantise::<i16>(QA),
SavedFormat::id("l0b").round().quantise::<i16>(QA),
SavedFormat::id("l1w").round().quantise::<i16>(QB),
SavedFormat::id("l1b").round().quantise::<i16>(QA * QB),
])
.loss_fn(|output, target| output.sigmoid().squared_error(target))
.build(|builder, stm_inputs, ntm_inputs| {
let l0 = builder.new_affine("l0", 768, hidden);
let l1 = builder.new_affine("l1", 2 * hidden, 1);
let stm_hidden = l0.forward(stm_inputs).screlu();
let ntm_hidden = l0.forward(ntm_inputs).screlu();
l1.forward(stm_hidden.concat(ntm_hidden))
});
if let Some(checkpoint) = &args.check {
trainer.load_from_checkpoint(checkpoint);
for fen in CHECK_FENS {
// bulletformat's text form: <fen> | <score> | <result>
let raw = trainer.eval(&format!("{fen} | 0 | 0.5"));
println!("{:6.0} cp {fen}", raw * SCALE as f32);
}
return;
}
let schedule = TrainingSchedule {
net_id: args.id.clone(),
eval_scale: SCALE as f32,
steps: TrainingSteps {
batch_size: 16_384,
batches_per_superbatch: args.batches,
start_superbatch: 1,
end_superbatch: args.superbatches,
},
wdl_scheduler: wdl::ConstantWDL { value: WDL },
lr_scheduler: lr::CosineDecayLR {
initial_lr: 0.001,
final_lr: 0.001 * 0.3f32.powi(5),
final_superbatch: args.superbatches,
},
save_rate: SAVE_RATE,
};
let settings =
LocalSettings { threads: LOADER_THREADS, test_set: None, output_directory: "checkpoints", batch_queue_size: 64 };
let paths: Vec<&str> = args.data.iter().map(String::as_str).collect();
if paths.iter().all(|p| p.ends_with(".bin.zst")) {
trainer.run(&schedule, &settings, &zstd_reader::ZstdBulletReader::new(&paths));
} else if paths.iter().all(|p| p.ends_with(".bin")) {
trainer.run(&schedule, &settings, &DirectSequentialDataLoader::new(&paths));
} else {
assert!(
paths.iter().all(|p| p.ends_with(".binpack")),
"--data files must be all .bin.zst, all .bin or all .binpack"
);
let data_loader = SfBinpackLoader::new_concat_multiple(&paths, 1024, LOADER_THREADS, filter);
trainer.run(&schedule, &settings, &data_loader);
}
}
+75
View File
@@ -0,0 +1,75 @@
//! Reads bulletformat positions straight from zstd-compressed files (linrock's
//! `*.bullet.bin.zst`), so the data never has to be unpacked to disk: training
//! needs ~30 MB/s of compressed input, which even an HDD gives easily.
//!
//! Files are read one after the other and the list repeats forever, like bullet's
//! `DirectSequentialDataLoader`; each file must already be shuffled.
use std::{
fs::File,
io::{BufReader, Read},
};
use bullet_lib::game::formats::bulletformat::ChessBoard;
use bullet_trainer::reader::DataReader;
#[derive(Clone)]
pub struct ZstdBulletReader {
paths: Vec<String>,
}
impl ZstdBulletReader {
pub fn new(paths: &[&str]) -> Self {
for path in paths {
assert!(std::path::Path::new(path).exists(), "data file not found: {path}");
}
Self { paths: paths.iter().map(|p| p.to_string()).collect() }
}
}
/// Reads until `buf` is full or the stream ends; returns the bytes read.
fn read_full(reader: &mut impl Read, buf: &mut [u8]) -> usize {
let mut filled = 0;
while filled < buf.len() {
match reader.read(&mut buf[filled..]) {
Ok(0) => break,
Ok(n) => filled += n,
Err(e) if e.kind() == std::io::ErrorKind::Interrupted => {}
Err(e) => panic!("reading training data: {e}"),
}
}
filled
}
impl DataReader<ChessBoard> for ZstdBulletReader {
fn read_chunks<F: FnMut(&[ChessBoard]) -> bool>(&self, mut skip: usize, mut f: F) {
const SIZE: usize = size_of::<ChessBoard>();
const CAP: usize = (64 << 20) / SIZE;
let mut buf = vec![ChessBoard::default(); CAP];
loop {
for path in &self.paths {
let file = BufReader::with_capacity(4 << 20, File::open(path).unwrap());
let mut decoder = zstd::stream::read::Decoder::with_buffer(file).unwrap();
loop {
// ChessBoard is plain bytes (bulletformat's 32-byte record).
let bytes = unsafe { std::slice::from_raw_parts_mut(buf.as_mut_ptr().cast::<u8>(), CAP * SIZE) };
let n = read_full(&mut decoder, bytes);
if n == 0 {
break;
}
assert_eq!(n % SIZE, 0, "{path} is not a whole number of positions");
let mut chunk = &buf[..n / SIZE];
if skip > 0 {
let s = skip.min(chunk.len());
skip -= s;
chunk = &chunk[s..];
}
if !chunk.is_empty() && f(chunk) {
return;
}
}
}
}
}
}
+36
View File
@@ -0,0 +1,36 @@
# Trains Rigby's value network. Run from anywhere:
# powershell -ExecutionPolicy Bypass -File C:\Users\rektd\repos\Rigby\train\value\train.ps1
# Extra arguments go to the trainer, e.g.:
# ... train.ps1 --superbatches 60 --id rigby-value-v2
# ... train.ps1 --data ..\data\a.binpack --data ..\data\b.binpack
param([Parameter(ValueFromRemainingArguments = $true)] [string[]] $TrainerArgs)
$ErrorActionPreference = 'Stop'
Set-Location $PSScriptRoot
# CUDA 13.3 (the toolkit bullet links against) and cargo
$env:CUDA_PATH = 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v13.3'
$env:PATH = "$env:USERPROFILE\.cargo\bin;$env:CUDA_PATH\bin\x64;$env:PATH"
# The bullet clone the trainer builds against
if (-not (Test-Path '..\..\..\bullet\crates\bullet_lib')) {
throw 'bullet not found next to the Rigby repo: git clone https://github.com/jw1912/bullet C:\Users\rektd\repos\bullet'
}
# Default data: unpack the .zst once if only the compressed file is there
$data = '..\data\test80-2024-02-feb-2tb7p.min-v2.v6.binpack'
if (-not ($TrainerArgs -contains '--data') -and -not (Test-Path $data)) {
if (-not (Test-Path "$data.zst")) { throw "No training data: $data(.zst) is missing" }
Write-Host "Unpacking $data.zst ..."
$src = (Resolve-Path "$data.zst").Path
python -P -c "import zstandard,sys,os; s=sys.argv[1]; d=s[:-4]; zstandard.ZstdDecompressor().copy_stream(open(s,'rb'), open(d+'.part','wb'), read_size=1<<24, write_size=1<<24); os.replace(d+'.part', d)" $src
}
cargo build --release
if ($LASTEXITCODE -ne 0) { throw 'build failed' }
& .\target\release\rigby-value.exe @TrainerArgs
if ($LASTEXITCODE -ne 0) { throw "training failed ($LASTEXITCODE)" }
Write-Host ''
Write-Host 'Done. Networks are in' (Resolve-Path .\checkpoints).Path