Expand description
§ai-tictactoe
A tic-tac-toe rules and search library with perfect play.
§Use it
Add the crate to your project:
[dependencies]
ai-tictactoe = "0.1"Build the tablebase once, then use it for each position:
use ai_tictactoe::{Algorithm, Position, Tablebase, search};
let position = Position::default();
let tablebase = Tablebase::build();
let result = search(position, Algorithm::Tablebase, &tablebase);
assert!(result.best_move.is_some());The crate also includes negamax, memoized search, symmetry reduction, and a small line-oriented engine.
cargo test
cargo runLicensed under the MIT License.
Structs§
- Candidate
- Decision
Report - Engine
- One protocol session. This is shared by the native binary and WASM.
- Move
- A tic-tac-toe move is exactly one square.
- Position
- The whole game state: one nine-bit board per side and the side to move.
- Search
Report - Complete exact-search result for a position.
- Search
Stats - Search
Tree - A bounded tree annotated with exact tablebase values.
- Square
- One of the nine squares, numbered rank-first from
a1toc3. - Tablebase
- An exact table for every position reachable from the empty board.
- Tree
Edge
Enums§
- Algorithm
- Exact solving method used by
search. - Decision
Reason - Game
Result - Move
Error - Outcome
- Exact game-theoretic result from the current side’s perspective.
- Play
Strategy - A move-selection policy used for the playable opponent.
- Side
Functions§
- build_
tree - Builds an exact, tablebase-annotated tree up to
depthplies. - choose_
move - Chooses one move with
strategy. - perft
- Counts leaf positions reached at exactly
depthplies or at game end. - search
- Solves
positionexactly with the selectedalgorithm.