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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! # santh-mcts — Production-grade Monte Carlo Tree Search
//!
//! A generic, zero-domain-assumption MCTS implementation with UCT selection,
//! RAVE (Rapid Action Value Estimation), and pluggable environments.
//!
//! ## Design
//!
//! This crate provides two complementary MCTS interfaces:
//!
//! 1. **Environment-based** ([`GameSearch`]) — Classic game-tree MCTS. You define
//! an [`Environment`] with actions, state transitions, and terminal conditions.
//! The engine handles selection, expansion, simulation, and backpropagation.
//! Best for: game AI, optimization, planning problems.
//!
//! 2. **Bandit-based** ([`BanditSearch`]) — Two-level MCTS for explore/exploit
//! problems where you have a flat set of arms grouped by category.
//! The engine uses UCT+RAVE to decide which arm to pull next, and you
//! feed back rewards. Best for: fuzzing, testing, hyperparameter search,
//! any problem with a pre-enumerated action space.
//!
//! ## Quick Start (Environment-based)
//!
//! ```rust
//! use mctrust::{Environment, GameState, GameSearch, SearchConfig, Reward};
//!
//! #[derive(Clone)]
//! struct MyGame { /* ... */ }
//!
//! #[derive(Clone, Debug, PartialEq)]
//! enum Move { Left, Right }
//!
//! impl Environment for MyGame {
//! type Action = Move;
//!
//! fn legal_actions(&self) -> Vec<Move> {
//! vec![Move::Left, Move::Right]
//! }
//!
//! fn apply(&mut self, action: &Move) {
//! // mutate state
//! }
//!
//! fn evaluate(&self) -> GameState {
//! GameState::Ongoing
//! }
//! }
//!
//! let game = MyGame { /* ... */ };
//! let config = SearchConfig::default();
//! let mut search = GameSearch::new(game, config);
//! let best_move = search.run();
//! ```
//!
//! ## Quick Start (Bandit-based)
//!
//! ```rust
//! use mctrust::{BanditSearch, BanditConfig};
//!
//! let mut search = BanditSearch::new(BanditConfig::default());
//!
//! // Register 100 arms across 5 groups.
//! for group in 0..5u64 {
//! for arm in 0..20u64 {
//! search.add_arm(group * 20 + arm, group as u32);
//! }
//! }
//!
//! // Pull arms and feed rewards.
//! while let Some(arm_id) = search.next_arm() {
//! let reward = 0.5; // your evaluation
//! search.observe(arm_id, reward);
//! }
//! ```
//!
//! ## Features
//!
//! - **UCT selection** with configurable exploration constant
//! - **RAVE** for rapid cross-branch value estimation
//! - **Flat arena storage** for cache-efficient tree traversal
//! - **Budget control** (iteration cap, time budget hooks)
//! - **Configurable reward** — bring your own reward function
//! - **Thread-safe RNG** via `StdRng` (no `ThreadRng` footgun)
//! - **Zero domain assumptions** — works for games, fuzzing, optimization, anything
//!
//! ## References
//!
//! - Kocsis & Szepesvári, "Bandit-based Monte Carlo Planning" (2006)
//! - Gelly & Silver, "Monte-Carlo tree search and rapid action value estimation
//! in computer Go" (2011)
//! - Browne et al., "A Survey of Monte Carlo Tree Search Methods" (2012)
pub use ;
pub use ;
pub use Heuristic;
pub use ;
pub use ;
pub use NodeStats;
pub use Reward;