ai-backgammon 0.1.0

A compact cubeless Backgammon rules and expectimax engine
Documentation
  • Coverage
  • 25%
    27 out of 108 items documented1 out of 6 items with examples
  • Size
  • Source code size: 137.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.8 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • TheGustafson/ai-backgammon
    0 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • TheGustafson

ai-backgammon

A small Backgammon engine written in Rust. It implements complete legal-turn generation, single, gammon, and backgammon outcomes, and weighted expectimax checker search for cubeless single-game play.

The doubling cube, match scoring, and the Crawford rule are intentionally out of scope.

Callers supply every dice roll. Search integrates all 21 unordered future rolls with their exact multiplicities.

The crate treats the two dice as separate moves. Legal plays therefore retain their checker-step order, while legal_outcomes groups orders that reach the same position for search.

Turn filters legal continuations from complete plays for clients that enter a move one checker at a time. Game manages the opening roll and turn phases. The optional wasm feature exposes the same game controller to browser workers.

use ai_backgammon::{Dice, Position};

let position = Position::new();
let dice = Dice::new(3, 1)?;
let plays = position.legal_plays(dice);
let next = position.play(dice, &plays[0])?;

assert_eq!(next.side_to_move(), position.side_to_move().other());
# Ok::<(), Box<dyn std::error::Error>>(())

Search averages all 21 unordered dice outcomes with their exact multiplicities. Depth counts complete future checker turns.

use ai_backgammon::{Dice, Position, SearchOptions, Searcher};

let position = Position::new();
let dice = Dice::new(3, 1)?;
let report = Searcher::new().search(
    position,
    dice,
    SearchOptions {
        max_depth: 2,
        node_limit: 100_000,
        soft_time_ms: 0,
    },
);
let best = report.best_play.expect("the opening position has legal plays");
assert!(position.legal_plays(dice).contains(&best));
# Ok::<(), Box<dyn std::error::Error>>(())

The paired self-play runner uses identical dice streams with agent colors reversed:

cargo run --release --bin selfplay -- \
  --pairs 50 --a search:2:100000 --b static --seed 0x7a1c4e90b368d25f

Run the checks with:

cargo fmt --check
cargo +1.85.0 check --locked --all-targets --all-features
cargo clippy --locked --all-targets --all-features -- -D warnings
cargo test --release --locked --all-features
RUSTDOCFLAGS="-D warnings" cargo doc --locked --all-features --no-deps --lib
cargo check --locked --target wasm32-unknown-unknown --no-default-features
cargo check --locked --target wasm32-unknown-unknown --all-features
cargo publish --dry-run