Skip to main content

ai_ultimate_tictactoe/
lib.rs

1#![doc = include_str!("../README.md")]
2#![forbid(unsafe_code)]
3
4mod lookup;
5#[cfg(feature = "mcts")]
6mod mcts;
7mod mv;
8#[cfg(feature = "mcts")]
9mod network;
10mod position;
11mod protocol;
12mod search;
13
14#[cfg(feature = "training")]
15mod training;
16
17#[cfg(feature = "wasm")]
18mod wasm;
19
20#[cfg(feature = "mcts")]
21pub use mcts::{
22    MCTS_PRESETS, MctsMoveStats, MctsOptions, MctsPreset, MctsReport, MctsSearcher, MctsStrategy,
23    mcts_preset,
24};
25pub use mv::{Move, ParseMoveError};
26pub use position::{
27    GameResult, MiniResult, MoveError, MoveList, Player, Position, PositionStateError,
28};
29pub use protocol::Engine;
30pub use search::{
31    SEARCH_PRESETS, SearchOptions, SearchPreset, SearchReport, Searcher, search_preset,
32};
33
34#[cfg(feature = "training")]
35pub use training::{PolicyTrainingConfig, train_policy};
36
37/// Counts legal leaf positions and stops at terminal games.
38pub fn perft(position: Position, depth: u8) -> u64 {
39    if depth == 0 {
40        return 1;
41    }
42    position
43        .legal_moves()
44        .iter()
45        .map(|mv| {
46            let child = position
47                .play(mv)
48                .expect("legal move generation must agree with play");
49            perft(child, depth - 1)
50        })
51        .sum()
52}
53
54#[cfg(feature = "wasm")]
55pub use wasm::UltimateSession;