Skip to main content

entrenar/search/mcts/
config.rs

1//! MCTS configuration.
2//!
3//! This module contains the configuration parameters for the MCTS algorithm.
4
5/// Configuration for MCTS search
6#[derive(Debug, Clone)]
7pub struct MctsConfig {
8    /// Exploration constant for UCB1 (higher = more exploration)
9    pub exploration_constant: f64,
10    /// Maximum number of iterations
11    pub max_iterations: usize,
12    /// Maximum depth for simulation rollouts
13    pub max_simulation_depth: usize,
14    /// Whether to use policy network priors
15    pub use_policy_priors: bool,
16    /// Temperature for action selection (higher = more random)
17    pub temperature: f64,
18    /// Minimum visits before expansion
19    pub min_visits_for_expansion: usize,
20    /// Whether to reuse tree between searches
21    pub reuse_tree: bool,
22    /// Dirichlet noise alpha for exploration at root
23    pub dirichlet_alpha: f64,
24    /// Fraction of Dirichlet noise to add
25    pub dirichlet_epsilon: f64,
26}
27
28impl Default for MctsConfig {
29    fn default() -> Self {
30        Self {
31            exploration_constant: std::f64::consts::SQRT_2,
32            max_iterations: 1000,
33            max_simulation_depth: 100,
34            use_policy_priors: true,
35            temperature: 1.0,
36            min_visits_for_expansion: 1,
37            reuse_tree: false,
38            dirichlet_alpha: 0.3,
39            dirichlet_epsilon: 0.25,
40        }
41    }
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_mcts_config_default() {
50        let config = MctsConfig::default();
51        assert_eq!(config.max_iterations, 1000);
52        assert!(config.exploration_constant > 0.0);
53        assert!(config.use_policy_priors);
54    }
55}