Skip to main content

Crate ai_tictactoe

Crate ai_tictactoe 

Source
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 run

Licensed under the MIT License.

Structs§

Candidate
DecisionReport
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.
SearchReport
Complete exact-search result for a position.
SearchStats
SearchTree
A bounded tree annotated with exact tablebase values.
Square
One of the nine squares, numbered rank-first from a1 to c3.
Tablebase
An exact table for every position reachable from the empty board.
TreeEdge

Enums§

Algorithm
Exact solving method used by search.
DecisionReason
GameResult
MoveError
Outcome
Exact game-theoretic result from the current side’s perspective.
PlayStrategy
A move-selection policy used for the playable opponent.
Side

Functions§

build_tree
Builds an exact, tablebase-annotated tree up to depth plies.
choose_move
Chooses one move with strategy.
perft
Counts leaf positions reached at exactly depth plies or at game end.
search
Solves position exactly with the selected algorithm.