AI Calculation

How the AI calculates the best move β€” gnubg neural networks at all difficulty levels.

Calculation Pipeline

Dice→Opening Book→Legal Moves→Deduplicate→NN Evaluation→Best Move

Step 0: Check Opening Book

Before any costly computation, the AI checks for an opening book entry. These 3 universally agreed-upon opening moves are played instantly.

DiceMoveStrategy
3-18/5, 6/5Make 5-point (Golden Point)
6-113/7, 8/7Make bar-point
4-28/4, 6/4Make 4-point

Only on the unmodified starting board. Applies to all difficulty levels. For Black, points are automatically mirrored.

Step 1: Generate Legal Moves

The move generator produces all legal move combinations for the rolled dice. Typically 5–30 combinations, up to 100+ for doubles.

  • Normal roll (e.g. 3-5): Up to 2 individual moves
  • Doubles (e.g. 4-4): Up to 4 individual moves
  • Bar entry takes priority: Checkers on the bar must re-enter first
  • Bearing off: Only when all 15 checkers are in the home board

Step 2: gnubg Neural Network

All difficulty levels use the pre-trained neural networks from GNU Backgammon (gnubg-nn) β€” the gold standard of Backgammon AI since the 1990s.

3 Specialized Networks

  • β€’ Contact β€” Positions with checker contact
  • β€’ Race β€” Pure race positions without contact
  • β€’ Crashed β€” Stacked/crashed positions

The network returns 5 probabilities: P(Win), P(Gammon Win), P(Backgammon Win), P(Gammon Loss), P(Backgammon Loss).

Equity = P(Win) - P(Lose) + P(Gammon Win) - P(Gammon Loss) + P(BG Win) - P(BG Loss)

Step 3: Strategy by Difficulty

Easy~0.1ms

0-Ply NN evaluation + Gaussian Noise

  1. 1.Every legal move is scored using the neural network (0-ply = direct)
  2. 2.Gaussian noise is added to each equity (proportional to score range)
  3. 3.The move with the highest noisy equity is played
Medium~0.5ms

0-Ply pre-filter (Top 5) β†’ 1-Ply refinement (gnubg C++)

  1. 1.Move sequences leading to the same board are merged
  2. 2.All candidates scored with 0-ply NN, keep top 5
  3. 3.Each of the top 5 is re-evaluated at 1-ply (gnubg internally computes all 21 opponent dice combinations)
  4. 4.Best 1-ply candidate is played
Hard~285ms

0-Ply pre-filter (Top 15) β†’ 2-Ply refinement (gnubg C++)

  1. 1.Move sequences leading to the same board are merged
  2. 2.All candidates scored with 0-ply NN, keep top 15
  3. 3.Each of the top 15 is re-evaluated at 2-ply (gnubg computes two levels of lookahead internally in C++)
  4. 4.Best 2-ply candidate is played

Doubling Cube Strategy

All doubling decisions use NN-based win probability for precise assessment.

Double atAccept at
EasyNeverAlways
Medium
66–88% (NN)
Too-good: Gammon >25% + Win >80%
β‰₯ 25% win probability (NN)
Hard
66–82% (NN)
Too-good: Gammon >25% + Win >80%
β‰₯ 25% win probability (NN)

Admin-Configurable Parameters

These parameters can be adjusted in Settings β†’ AI:

ParameterDefaultEffect
easy_noise0.30Randomness strength for Easy (0 = perfect, 1 = chaotic)
max_doubles_per_player3Max doubles per player per game

Summary

EasyMediumHard
Evaluationgnubg-NNgnubg-NNgnubg-NN
Pre-filterβ€”0-Ply Top 50-Ply Top 15
Ply Depth0-Ply1-Ply2-Ply
NoiseYesβ€”β€”
Compute Time~0.1ms~0.5ms~285ms