woggioni dd3b918561 replace broken AI search with negamax and alpha-beta
- fix the no-op best-score update that ignored all but the first reply
- alternate sides correctly with negamax and add alpha-beta pruning
- score terminal wins and losses above material evaluations
- treat depth zero as one ply instead of underflowing
- guard relative_score against an empty board
- add hanging-piece, recapture, terminal, and depth regression tests
2026-10-19 19:56:37 +00:00
2025-06-23 13:26:20 +08:00
2025-07-08 22:32:58 +08:00
2025-07-08 22:32:58 +08:00
2025-07-08 22:32:58 +08:00
2025-07-08 22:32:58 +08:00
2025-06-23 13:26:20 +08:00

rdraught

A draughts (checkers) engine written in Rust, with a no_std core library and several front ends.

Workspace

Crate Description
rdraught no_std game engine, move generation, AI, and undo/redo history.
rdraught-ui-common Small geometry and shared-state helpers used by the graphical front ends.
rdraught-gtk GTK4 desktop front end (the most complete one).
rdraught-wasm Browser front end using the Canvas 2D API and wasm-bindgen.
rdraught-w4 WASM-4 front end. Work in progress.
rdraught-sdl SDL3 front end. Work in progress.
rdraught-cli Scratch rustyline program; not a playable CLI yet.

Rules

The rules implemented by the engine are an 8x8 draughts variant:

  • Each player starts with twelve men.
  • Captures are mandatory.
  • A multi-capture sequence must be completed with the same piece.
  • Men move one square diagonally forward.
  • Men cannot capture backwards in this implementation.
  • Kings move one square diagonally in any direction and can capture in any direction.
  • A man is promoted to a king when it reaches the opponent's back row.
  • Draw rules (repetition, move limits) are not implemented yet.

AI

The engine exposes a fixed-depth negamax search with alpha-beta pruning through DraughtsGame::get_best_move(max_depth). A depth of zero is treated as one ply. Wins and losses dominate material scoring, and faster wins are preferred. The search has no time or node budget and no draw/repetition detection, so choose a modest depth for positions with many pieces.

Requirements

  • Rust 1.87 or newer. The workspace uses edition 2024.
  • rustfmt and clippy for the checks described below.
  • GTK4 development packages (including Graphene and librsvg) for rdraught-gtk.
  • The wasm32-unknown-unknown target and Trunk for rdraught-wasm.
  • The WASM-4 toolchain for rdraught-w4.
  • A C/C++ toolchain for rdraught-sdl, which builds SDL3 from source.

On Debian/Ubuntu, the GTK front end needs packages such as:

sudo apt install libgtk-4-dev libgraphene-1.0-dev librsvg2-dev pkg-config

Building and testing

The default workspace members are rdraught and rdraught-ui-common, so the common host-side checks do not require GTK or a wasm target:

cargo test
cargo test -p rdraught --features std
cargo fmt --check
cargo clippy -p rdraught --features std --all-targets

The draughts and AI unit tests are gated behind the std feature because they use std::collections::HashMap.

cargo test --workspace requires all front-end prerequisites (GTK libraries, the wasm target, and the SDL build toolchain). Use the per-front-end commands below instead.

GTK

cargo run -p rdraught-gtk

Browser WASM

rustup target add wasm32-unknown-unknown
cd rdraught-wasm
trunk serve --open

The .cargo/config.toml inside rdraught-wasm is only read when Cargo runs from that directory.

WASM-4

cd rdraught-w4
cargo build --release --target wasm32-unknown-unknown

Run Cargo from rdraught-w4 so its linker configuration is applied. The resulting module is in target/wasm32-unknown-unknown/release/.

SDL3

cargo run -p rdraught-sdl

The first build compiles SDL3 from source and can take a while.

CLI scratch program

cargo run -p rdraught-cli --bin rustyline-test

Dependencies

rdraught-ui-common uses rmath, which is published in the author's Gitea Cargo registry. The required registry configuration is committed in .cargo/config.toml, so no extra local setup is needed:

[registries.gitea]
index = "sparse+https://gitea.woggioni.net/api/packages/woggioni/cargo/"

License

MIT. See LICENSE.

S
Description
No description provided
Readme MIT
346 KiB
Languages
Rust 99.8%
HTML 0.2%