Raccoon

A modern neural engine for backgammon

Backgammon’s strongest engines are built on 1990s technology. Raccoon is an attempt to rebuild one from scratch with the methods that have since transformed chess, shogi, and Go — a deep residual policy-value network, Monte Carlo tree search, and large-scale supervised distillation.

GNU Backgammon (GNUBG) has been the reference open-source engine for two decades. Its evaluator is a small, hand-tuned neural network in the TD-Gammon lineage, and its strength comes mostly from full-width search on top of that network — search that costs roughly two orders of magnitude more compute per decision than a single network evaluation. Raccoon asks whether a modern network can absorb that search quality into its weights instead, so that a single forward pass plays at the level GNUBG needs a deep search to reach.

Where it stands today

Raccoon is scored on the BGSage money benchmark: 14,693 checker decisions with cubeless-equity references from rollouts. The metric is PR — mean move-selection error over the benchmark, scaled by 500. Lower is better; 0 would mean never picking a suboptimal move.

Engine Compute per decision PR (n = 14,693)
GNUBG, 2-ply full-width search ~1.3 s 0.56
Raccoon, single network evaluation ~10 ms 0.93
GNUBG, single network evaluation (0-ply) ~10 ms 2.14

Raccoon figure: checkpoint exp017-ep12, the current best network — a 10-block, 256-channel ResNet trained on 40M positions distilled from GNUBG’s 2-ply search. GNUBG figures scored on the identical benchmark. Full method and per-epoch curves: Supervised & Expert-Iteration Analysis.

Read plainly: at equal cost, Raccoon’s checker play is well past GNUBG’s own network, and it has closed most of the distance to GNUBG’s 2-ply search while doing no search at all.

That now holds over the board, not just on the benchmark. The current cube-capable network wins +0.046 ± 0.005 points per game against GNUBG at 0-ply over 6,000 cubeless money games — the first time a Raccoon network has been shown to beat the teacher it was distilled from in actual play (exp020). An earlier checkpoint had measured −0.053 ± 0.046 on the same yardstick, a real if small deficit (exp011b).

The plain, unadjusted average over those same 6,000 games is +0.018 ± 0.035 and settles nothing. The edge is only visible because the games were scored with variance-reduced rollouts, which are worth about 55× as many games — reading the same result to ±0.005 instead of ±0.035.

Two thirds of that margin was found rather than trained. The first measurement came in at only +0.013 ± 0.005 (exp019), well short of what the benchmark predicted, and chasing the gap turned up a bug: on doubles, the engine chose its four half-moves two at a time instead of all together, conceding 0.062 points on the one doubles turn in six where that mattered. Fixing the search — not the network — was worth +0.033 ppg (exp020).

The honest caveats: this is checker play only, cubeless. Raccoon does not yet handle the doubling cube, which is half of competitive backgammon. It is a research engine, not a product.

How it works

Piece Approach
Board encoding Custom (26, 2, 12) tensor — checker planes per player, bar/borne-off/dice broadcasts, plus handcrafted pip, blot, anchor, and contact features
Network ResNet with a shared trunk, a 1352-way policy head over OpenSpiel’s action encoding, and a value head
Search AlphaZero-style MCTS with PUCT selection; dice are sampled at chance nodes so the tree holds only decision nodes
Training Supervised distillation from GNUBG’s search, expert iteration (DAgger) on self-play distributions, and TD self-play — see the analyses below for which of these actually worked

Game rules and legal-move generation come from OpenSpiel; everything else — encoder, network, search, training loops, evaluation harnesses — is written from scratch in Python and PyTorch.

Roadmap

  • Cube-capable value head. Move from a scalar equity to a six-outcome distribution (win/gammon/backgammon, either side), the prerequisite for doubling and take/pass decisions.
  • A stronger teacher. Distilling from deeper GNUBG search rather than more 2-ply data — the residual gap to the teacher is search, not data.
  • Match play, where score-dependent equity and the cube dominate.
  • Engine integration. The Raccoon Game Protocol is a UCI-style text protocol so analysis GUIs can embed the engine.

Research write-ups

Every experiment is documented with its hypothesis, primary metric, sample size, and conclusion — including the ones that failed.

Doc What it covers
Supervised & Expert Iteration Distilling GNUBG, on-distribution DAgger, consolidation — the current best results
Self-Play Analysis What pure AlphaZero self-play achieved, and why it plateaued
Variance-Reduced Rollouts Measuring a 0.05 ppg edge without playing hundreds of thousands of games — method, proof of unbiasedness, the head-to-head result, and the doubles bug it uncovered
Architecture Board encoding, network, MCTS, and training loop design
MCTS Explained Simulations, PUCT selection, temperature, Dirichlet noise
Training Parameters Every CLI flag explained with intuition and reference points
GCP Guide Running training on Google Cloud GPU VMs
API Reference Generated module documentation

Try it

Raccoon is open source under the MIT licence.

git clone https://github.com/lassehjorthmadsen/raccoon.git
cd raccoon
make setup          # install in editable mode with dev deps
make test           # run the test suite
make play           # play against Raccoon in the terminal

Training runs need an experiment name; outputs land in experiments/<name>/:

python3 scripts/train.py --experiment-name my-run --iterations 100 \
  --games-per-iter 50 --simulations 100 --lr 0.001 \
  --channels 128 --num-blocks 6 --checkpoint-every 10

Source: github.com/lassehjorthmadsen/raccoon · Questions and collaboration: get in touch.