- fix Xform yx and add a shared view-aware board_position helper - add GTK automatic game-over, restart, status, and multi-capture selection - pin librsvg to the 2.60 series to match GTK4/glib 0.20 - add WASM orientation, undo/redo/new/flip controls, and winner overlay - replace WASM crown images with canvas paths and remove dead files/deps - make WASM-4 playable with mouse input, crowns, winner handling, and correct mapping - move the WASM-4 release profile to the workspace root - clean up frontend dead code and update the README
152 lines
4.5 KiB
Markdown
152 lines
4.5 KiB
Markdown
# 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` | Playable GTK4 desktop front end. |
|
|
| `rdraught-wasm` | Playable browser front end using the Canvas 2D API and `wasm-bindgen`. |
|
|
| `rdraught-w4` | Playable WASM-4 front end. |
|
|
| `rdraught-sdl` | SDL3 prototype; not wired to the game yet. |
|
|
| `rdraught-cli` | Scratch `rustyline` program; not a playable CLI yet. |
|
|
|
|
The GTK, WASM, and WASM-4 front ends are currently hot-seat games: both sides
|
|
are played by people. The core AI is available but is not wired into a frontend
|
|
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. The current frontends do not use
|
|
the AI; they are hot-seat games.
|
|
|
|
## 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](https://trunkrs.dev/) 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:
|
|
|
|
```sh
|
|
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:
|
|
|
|
```sh
|
|
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
|
|
|
|
```sh
|
|
cargo run -p rdraught-gtk
|
|
```
|
|
|
|
Use the board orientation selector at startup, click a piece to select it, and
|
|
click a highlighted destination to move. The header bar has undo, redo, and
|
|
New Game buttons. The game-over dialog appears automatically; use New Game to
|
|
start another game.
|
|
|
|
### Browser WASM
|
|
|
|
```sh
|
|
rustup target add wasm32-unknown-unknown
|
|
cd rdraught-wasm
|
|
trunk serve --open
|
|
```
|
|
|
|
Click a piece and then a highlighted destination. Keyboard controls:
|
|
|
|
- `Ctrl+Z` — undo
|
|
- `Ctrl+Y` or `Ctrl+Shift+Z` — redo
|
|
- `N` — new game
|
|
- `F` — flip the board orientation
|
|
|
|
The `.cargo/config.toml` inside `rdraught-wasm` is only read when Cargo runs
|
|
from that directory.
|
|
|
|
### WASM-4
|
|
|
|
```sh
|
|
cd rdraught-w4
|
|
cargo build --release --target wasm32-unknown-unknown
|
|
```
|
|
|
|
Run Cargo from `rdraught-w4` so its linker configuration is applied. The module
|
|
is written to `../target/wasm32-unknown-unknown/release/rdraught_w4.wasm`.
|
|
|
|
Use the mouse to select a piece and click a highlighted destination to move.
|
|
After a win, click to start a new game. The board is shown in a fixed
|
|
orientation for hot-seat play.
|
|
|
|
### SDL3
|
|
|
|
```sh
|
|
cargo run -p rdraught-sdl
|
|
```
|
|
|
|
The first build compiles SDL3 from source and can take a while.
|
|
|
|
### CLI scratch program
|
|
|
|
```sh
|
|
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:
|
|
|
|
```toml
|
|
[registries.gitea]
|
|
index = "sparse+https://gitea.woggioni.net/api/packages/woggioni/cargo/"
|
|
```
|
|
|
|
## License
|
|
|
|
MIT. See [LICENSE](LICENSE).
|