- make Position represent only valid board squares and use checked offsets - make move endpoints fallible and remove unchecked coordinate arithmetic - validate moves against generated legal moves, including mandatory capture - track pending multi-captures and restrict continuation to the same piece - derive pending state after undo/redo and preserve redo on invalid moves - fix circular buffer wraparound, mixed iteration, and element drops - adapt GTK and WASM to fallible endpoints and apply errors - add rule, promotion, chain, history, and coordinate regression tests
123 lines
3.3 KiB
Markdown
123 lines
3.3 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` | 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.
|
|
|
|
## 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
|
|
```
|
|
|
|
### Browser WASM
|
|
|
|
```sh
|
|
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
|
|
|
|
```sh
|
|
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
|
|
|
|
```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).
|