How the Backgammon AI Works: Expectiminimax and the Dice
The opponent on LK Forge Backgammon faces a problem the chess and Othello engines never do: it cannot know what will happen next. The dice roll between turns, so this is not a perfect-information game — and that changes the algorithm entirely.
Chance nodes: minimax that rolls the dice
Plain minimax assumes both players simply choose moves. Backgammon inserts a roll in between, so the engine uses expectiminimax — the classic algorithm for games with randomness. Alongside the usual move nodes it adds chance nodes that do not pick the best branch; instead they average the evaluation over every possible roll, each weighted by how likely it is.
There are exactly 21 distinct rolls: 15 mixed rolls like 3-1, each of which can come up two ways (3-1 or 1-3) for probability 2/36, and 6 doubles like 5-5, each coming up one way for 1/36. A double is genuinely half as likely as a given mixed roll, and the engine weights them accordingly — the 21 weights sum to exactly 1.
A chance node's value is the probability-weighted average of the best reply to each of the 21 rolls — exact combinatorics, not an estimate.
Generating the legal plays
On its own turn the engine first works out every legal way to play the two numbers it rolled, respecting the real rules: you must use as many of your dice as you can, and if only one will go, you must play the larger. That set can be surprisingly large, which is why the search is kept to two plies rather than the deep trees a game like Connect 4 allows.
// expectiminimax chance node: average over the 21 weighted rolls function chanceValue(pos, depth) { let ev = 0; for (const { roll, p } of DICE) { // 15 mixed @ 2/36, 6 doubles @ 1/36 const best = bestReply(pos, roll, depth); // the mover picks their best play ev += p * evaluate(best); } return ev; // probability-weighted average }
What it actually rewards
Each position is scored on the things that win backgammon games: the pip count (who is ahead in the race), checkers already borne off, made points and primes that wall the opponent in, and blot exposure — lone checkers that can be hit and sent all the way back to the bar. At the Hard level the engine looks a move further, weighing your most likely replies across the whole dice distribution before it commits.
The benchmark
The numbers come from scripts/benchmark-backgammon.mjs, which loads the exact engine the game ships (the inline engine block of the game page) and self-plays it in Node. Dice luck dominates single games, so it uses duplicate dice: every seeded dice sequence is played twice with the colours swapped, and both sides get the same rolls. Win is the share of games won; gammon and backgammon are the share of all games won by that margin (2 and 3 points). Points per game is the net result, with no doubling cube. Measured October 21, 2026.
The three levels
| Matchup (2,000 games) | Win | Gammon | Backgammon | Points / game |
|---|---|---|---|---|
| Beginner vs a random mover | 90.2% | 27.4% | 51.6% | +2.04 |
| Medium vs a random mover | 99.5% | 20.6% | 76.0% | +2.71 |
| Hard vs a random mover | 99.8% | 25.5% | 70.7% | +2.66 |
| Medium vs Beginner | 93.2% | 29.4% | 50.1% | +2.12 |
| Hard vs Beginner | 96.8% | 32.9% | 48.0% | +2.22 |
| Hard vs Medium | 61.8% | 14.9% | 8.1% | +0.42 |
A random mover leaves checkers stranded far back, so most of its losses are backgammons. Between real strategies the dice keep things close: even with the lookahead, Hard beats Medium a little under two games in three, at about 28 ms per turn against Medium's fraction of a millisecond.
What the lookahead buys
Hard looks ahead on its 10 best candidate plays. The second study varies that number against Medium. With one candidate, Hard simply plays Medium's own choice, which makes it the control.
| Candidates searched | Games | Win | Points / game | ms / turn |
|---|---|---|---|---|
| 1 (control) | 2,000 | 50.0% | 0.00 | 3 |
| 2 | 2,000 | 59.3% | +0.34 | 7 |
| 3 | 1,000 | 59.6% | +0.37 | 7 |
| 5 | 1,000 | 60.8% | +0.42 | 11 |
| 10 (shipped Hard) | 2,000 | 61.8% | +0.42 | 28 |
| 20 | 1,000 | 60.7% | +0.39 | 28 |
Almost all of the gain arrives with the second candidate: simply checking the runner-up play against the dice lifts the win rate from 50% to about 59%. Beyond about five candidates the extra search buys nothing measurable: 5, 10 and 20 candidates all land around 61% and +0.4 points per game, which is within the noise of these sample sizes.
node scripts/benchmark-backgammon.mjs reproduces both tables from the shipped engine. The dice and the random choices are seeded, so every run gives the same games.That is the whole engine: enumerate the legal plays, and evaluate each by averaging over the 21 rolls the dice can bring, weighted by probability. Curious how this compares to the deterministic search behind our other games? See Six Games, Three Classic Algorithms, or why none of them are language models in Real Game AI, Not a Chatbot.
FAQ
Why can't the Backgammon AI use plain minimax?
Because backgammon is not a perfect-information game — the dice make it a game of chance as well as skill. Plain minimax assumes both players simply choose moves, but here the roll comes between turns. So the engine uses expectiminimax, which adds chance nodes that average the evaluation over the possible dice rolls.
What is a chance node?
A chance node is a node in the search tree that stands for a dice roll instead of a decision. Rather than picking the best branch, it averages the value of all branches, each weighted by how likely that roll is. Backgammon has 21 distinct rolls: 15 mixed rolls at probability 2/36 each and 6 doubles at 1/36 each, which sum to 1.
How far ahead does the Backgammon AI look?
On Hard it runs a two-ply expectiminimax search: for each of its strongest candidate plays, it looks one move further by finding your best reply to every one of the 21 rolls and averaging them by probability. Beginner plays loose, punishable moves and Medium plays a solid game; all three run in your browser. The two-ply search runs entirely client-side, so nothing is sent to a server.
What does the Backgammon AI value in a position?
The things that actually win backgammon games: the pip count (who is ahead in the race), checkers already borne off, made points and primes that block the opponent, and blot exposure — lone checkers that can be hit and sent back to the bar. At the Hard level it also looks a move further, weighing your most likely replies across the whole dice distribution before committing. No single feature decides a move on its own — the search picks whichever legal play scores best once all of them are weighed together.
Take on the dice — three levels deep.
Play Backgammon →