Under the Hood

How the Backgammon AI Works: Expectiminimax and the Dice

Published September 12, 2026 · LK Forge

21
distinct dice rolls averaged per chance node
2-ply
lookahead on Hard, across the dice
5
position signals: race, borne-off, points, primes, blots
0
servers — runs in your browser

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.

15 mixed rolls · 2/36 each 6 dbl 30/36 = 83.3% of the probability 6/36 = 16.7% The 36 equally-likely dice outcomes, grouped into 21 distinct rolls lkforge.com

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.

Three levels, one idea. Beginner plays loose, punishable moves; Medium plays a solid game; Hard runs the two-ply expectiminimax search. What separates a good backgammon move from a bad one is rarely a single line — it is the average outcome over the dice, which is exactly what expectiminimax computes.

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: it plays its own move, then looks one move further by averaging your most likely replies across the whole dice distribution. 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 →