# Rigby 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. ## Current state (0.1-dev) - Bitboard board with fancy magic attacks, fully legal move generation, copy-make. Verified with a perft suite (`Rigby perftsuite`). - 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 Needs `clang++` (C++20) and `make`. On Windows clang must have a MinGW runtime, the build targets `x86_64-w64-windows-gnu`, same as Eleanor. ``` make make EXE=Rigby-dev make EVALFILE=path/to/quantised.bin ``` `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 Standard commands: `uci`, `isready`, `ucinewgame`, `position`, `go` (`wtime btime winc binc movestogo movetime nodes depth infinite`), `stop`, `quit`, `setoption`. Extra commands: | Command | Meaning | | --- | --- | | `d` | Print the board, FEN and hash key | | `eval` | Static (network) and quiescence evaluation of the current position | | `evalfens` | Network evaluation of fixed positions, to compare with the trainer's `--check` | | `perft ` | Perft with per-move breakdown | | `perftsuite [maxdepth]` | Standard perft positions with expected counts | | `perftfile [maxdepth]` | Perft of every ` ;D1 ;D2 ...` 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 | 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 | `` | 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 graph over all playouts, so it changes whenever search behaviour changes, while the playout count stays fixed.