AI Calculation
How the AI calculates the best move β gnubg neural networks at all difficulty levels.
Calculation Pipeline
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.
| Dice | Move | Strategy |
|---|---|---|
| 3-1 | 8/5, 6/5 | Make 5-point (Golden Point) |
| 6-1 | 13/7, 8/7 | Make bar-point |
| 4-2 | 8/4, 6/4 | Make 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).
Step 3: Strategy by Difficulty
0-Ply NN evaluation + Gaussian Noise
- 1.Every legal move is scored using the neural network (0-ply = direct)
- 2.Gaussian noise is added to each equity (proportional to score range)
- 3.The move with the highest noisy equity is played
0-Ply pre-filter (Top 5) β 1-Ply refinement (gnubg C++)
- 1.Move sequences leading to the same board are merged
- 2.All candidates scored with 0-ply NN, keep top 5
- 3.Each of the top 5 is re-evaluated at 1-ply (gnubg internally computes all 21 opponent dice combinations)
- 4.Best 1-ply candidate is played
0-Ply pre-filter (Top 15) β 2-Ply refinement (gnubg C++)
- 1.Move sequences leading to the same board are merged
- 2.All candidates scored with 0-ply NN, keep top 15
- 3.Each of the top 15 is re-evaluated at 2-ply (gnubg computes two levels of lookahead internally in C++)
- 4.Best 2-ply candidate is played
Doubling Cube Strategy
All doubling decisions use NN-based win probability for precise assessment.
| Double at | Accept at | |
|---|---|---|
| Easy | Never | Always |
| 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:
| Parameter | Default | Effect |
|---|---|---|
| easy_noise | 0.30 | Randomness strength for Easy (0 = perfect, 1 = chaotic) |
| max_doubles_per_player | 3 | Max doubles per player per game |
Summary
| Easy | Medium | Hard | |
|---|---|---|---|
| Evaluation | gnubg-NN | gnubg-NN | gnubg-NN |
| Pre-filter | β | 0-Ply Top 5 | 0-Ply Top 15 |
| Ply Depth | 0-Ply | 1-Ply | 2-Ply |
| Noise | Yes | β | β |
| Compute Time | ~0.1ms | ~0.5ms | ~285ms |