Chess isn't the only game with a neural network hiding inside it. This is a
backgammon engine, built from scratch — and the interesting part is
that nobody taught it how to play. It started with random weights, sat
down opposite a copy of itself, and after a few thousand games it had worked out the
things good players know: race when you're ahead, build a prime, don't leave a blot
under the gun, press for the gammon when you're winning big.
Backgammon has a special place in this story. In 1992 Gerald Tesauro's
TD-Gammon famously learned world-class play purely from self-play — one
of the first great demonstrations that a network could discover expert judgement on its
own, years before it became fashionable. This little engine walks the same path with
modern tools.
Backgammon-NN is a whole toolkit, not just a board. The network learns by
self-play, and you can take it further: extend the training
to grow stronger nets, design and build new networks, pit engines against
each other in automatic matches — against other engines or against itself —
and play the result on your PC, in a desktop board or from the console.
The desktop app: play the net at 0/1/2-ply with the doubling cube, a live win-probability bar, and a move list with equities.
Under the hood
A fast, correct core
The engine — board, dice, move generation, evaluators — is written in
Rust. Getting the rules exactly right is the whole game, so the move
generator is differentially tested against the independent
wildbg reference engine across 3.15 million
position–dice pairs: zero mismatches.
It learned from itself
A small network (198 inputs → 128 → 5) predicts the
chance of a win, gammon and backgammon. It was trained by
Monte-Carlo self-play from random weights — no opening books, no human
games — and grew to beat the hand-crafted evaluator ~84% of the time.
Runs anywhere, fast
Trained in PyTorch, exported to ONNX, and run
natively back inside the Rust engine — the three agree to within a rounding error.
On top sits an n-ply search (0/1/2-ply) that looks ahead and averages
over every roll of the dice.
Does it actually play well?
The honest test is head-to-head play. Against a player that just makes random legal
moves it wins essentially every game — usually by a gammon or backgammon. Against
HCE, a competent hand-written evaluator that races and counts pips, the
network wins about 84%. And looking one move deeper (1-ply search) beats
the very same network playing instantly (0-ply) 62.5% of the time — the
search is doing real work.
Estimated Elo, chained from measured head-to-head win rates (Random anchored at 0).
Backgammon win rates are compressed by dice luck, so the gaps are approximate — but the
order, and the steady climb from each extra ply of lookahead, are real.
Neural net (trained ~24,000 self-play games), head-to-head
Match-up
Win rate
Points per game
vs Random
99.6%
+2.72
vs HCE (hand-crafted)
84%
+1.44
1-ply vs 0-ply (same net)
62.5%
+0.53
2-ply vs 1-ply (same net)
58%
+0.22
Since these figures, the engine has been strengthened considerably.
A deeper self-learning network now leaks far fewer gammons and plays on par with — or
ahead of — the independent wildbg engine at equal thinking time, and
its rollout search runs 2.5× faster.
Read the full development report →
More than a board — a self-learning lab
Backgammon-NN isn't a finished object; it's something to run, train, and push further:
Extend the training. Keep the self-play loop going and the network
grows stronger — the same loop that took it from random moves to beating the
hand-crafted evaluator ~84%.
Build new networks. Change the shape — width, depth, inputs — and
train a fresh net from scratch to see how strong it becomes.
Run automatic matches. Pit engines head-to-head in mirrored-dice
matches — a new net against an old one, against the heuristic, or the engine
against itself — and read off the win rate and points-per-game.
Play it two ways. A polished graphical desktop app
(roll, move, double, watch the evaluation bar) and a lightweight text-only
console app that plays right in your terminal — both let you pick the engine's
search depth.
Sit down and play
Play it however you like: a polished graphical desktop board or a quick
text-only console game in your terminal. In the desktop app you roll the dice
(they tumble), click a checker and its destination, and the engine answers — its
checkers sliding across the board while a panel logs every move with its equity.
You get the full game, including the parts that make backgammon backgammon:
The doubling cube. Offer a double when you're ahead and watch the
engine decide whether to take or drop; it will double you back when the game turns.
A live evaluation bar. A chess-style bar down the side shows your
win probability in real time, from your point of view — it swings as the position
turns.
Choose your opponent's depth. Play the instant 0-ply network, or
give it one or two plies of lookahead when you want a sterner test.
Built with: Rust (engine core), PyTorch (training), ONNX + tract
(native inference), and PySide6 (the desktop board). A small self-taught net, a correct
engine, and a board to lose to it on.
Run it from source
Backgammon-NN is open source. With Rust (stable) and
Python 3.9+ installed, you can build it and be playing in a few
minutes:
# 1 · clone the repository
git clone https://github.com/Chris-Whittington-Chess/Backgammon-NN
cd Backgammon-NN
# 2 · create a Python environment and install the dependencies
python -m venv .venv
.venv/Scripts/pip install maturin numpy torch onnx onnxruntime PySide6
# 3 · build the Rust engine's Python bindings
cd crates/bgpy
../../.venv/Scripts/maturin develop --release
cd ../..
# 4 · play — the graphical desktop app…
.venv/Scripts/python gui/app.py
# …or the text-only console app
.venv/Scripts/python trainer/console_play.py
Commands are shown for Windows; on macOS or Linux use .venv/bin/ in place
of .venv/Scripts/. The repository ships with a trained network, so the
app plays straight after the build — or kick off your own training run with
trainer/train.py, and benchmark engines against each other with the
match runner.