1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! # Game-tree search
//!
//! Adversarial game-tree search for computer opponents in board, card and turn-based games:
//! choosing a move when an opponent chooses the next one.
//!
//! ## Scope
//!
//! - Minimax and negamax
//! - Alpha-beta pruning with move ordering, principal variation search (PVS/NegaScout) and MTD(f)
//! - Iterative deepening with transposition tables, aspiration windows and quiescence search
//! - Expectimax for games with chance nodes
//! - Monte Carlo tree search with UCT
//!
//! ## Usage
//!
//! A [`Game`] describes positions, their moves, the [`Side`] to move and a [`Score`] from
//! [`Side::Max`]'s point of view. The side to move belongs to the position, so one side may
//! move several times in a row.
//!
//! [`minimax()`] and [`negamax()`] search every line to a fixed depth and serve as the
//! reference. [`alpha_beta()`], [`pvs()`] and [`mtdf()`] return the same score while skipping
//! moves that cannot change the decision, helped by [`Game::order_moves`] and, where a game
//! allows it, by [`Game::satisfices`], which trades that exactness for speed. Each returns a [`SearchResult`]: the score and its [`Bound`], the
//! principal variation with a score and bound per step, and every root move searched.
//! [`deepen()`] runs alpha-beta one ply deeper at a time until a [`Budget`] of positions or
//! time runs out, trying each iteration's principal variation first in the next; a
//! [`Deepening`] hook can stop it after any iteration or give it aspiration windows.
//! [`expectimax()`] searches [`Stochastic`] games, whose chance positions, such as dice
//! rolls, are worth the [`Expectation`] of their outcomes.
//!
//! [`Mcts`] grows a tree by random simulations instead, for games too wide or too hard to
//! evaluate for a full search; its selection rule ([`Uct`], or [`Puct`] guided by move
//! priors from the [`Evaluator`]), leaf evaluation and random source are replaceable.
//!
//! [`Game::noisy_moves`] turns on quiescence search: past the horizon, every search goes on
//! through moves such as captures until the position is quiet.
//!
//! A [`Hashed`] game can give its [`Searcher`] a transposition [`Table`], such as
//! [`SlotTable`], with [`Searcher::with_table`]: positions reached by different move orders
//! are then answered from the table instead of being searched again. A
//! [`Searcher`] keeps the working buffers between searches, so repeated searches stop
//! allocating once warm.
//!
//! For many searches at once, such as one per game agent, keep one searcher per thread or
//! agent and share the game by reference: searches take `&G`, and searchers are `Send`
//! whenever their moves and scores are.
//!
//! Repository: <https://github.com/sunsided/game-tree-search>
extern crate alloc;
extern crate std;
pub use ;
pub use Bound;
pub use ;
pub use ;
pub use ;
pub use RandCore;
pub use ;
pub use minimax;
pub use mtdf;
pub use negamax;
pub use pvs;
pub use ;
pub use ;
pub use Budget;
pub use ;
pub use MapTable;
pub use ;
/// Doctests for the code examples in README.md (not part of the API).