use crate::policy::backprop::BackpropagationPolicy; use crate::policy::decision::DecisionPolicy; use crate::policy::selection::SelectionPolicy; use crate::policy::simulation::SimulationPolicy; use crate::state::GameState; use std::time::Duration; /// Configuration for the MCTS algorithm #[derive(Debug)] pub struct MCTSConfig { /// The maximum number of iterations to run when searching /// /// The search will stop after the given number of iterations, even if there /// is search time has not exceeded `max_time`. pub max_iterations: usize, /// The maximum time to run the search /// /// If set, the search will stop after this duration even if the maximum /// iterations hasn't been reached. pub max_time: Option, /// The size to initially allocate for the search tree /// /// This pre-allocates memory for the search tree which ensures contiguous /// memory and improves performance by preventing the resizing of tree /// as we explore. pub tree_size_allocation: usize, /// The selection policy /// /// This dictates the path through which the game tree is searched. As such /// the policy has a large impact on the overall aglorthm exeuction pub selection_policy: SelectionPolicy, /// The simulation policy /// /// This dictates the game siluation when expanding and evaluating the /// search tree. Random is generally a good default. pub simulation_policy: SimulationPolicy, /// The backpropagation policy /// /// This dictates how the results of the simulation playouts are propagated /// back up the tree. pub backprop_policy: BackpropagationPolicy, /// The decision policy /// /// This dictates how the MCTS algorithm determines its final decision /// after iterating through the search tree pub decision_policy: DecisionPolicy, } impl Default for MCTSConfig { fn default() -> Self { MCTSConfig { max_iterations: 10_000, max_time: None, tree_size_allocation: 10_000, selection_policy: SelectionPolicy::UCB1Tuned(1.414), simulation_policy: SimulationPolicy::Random, backprop_policy: BackpropagationPolicy::Standard, decision_policy: DecisionPolicy::MostVisits, } } }