mctrust 0.4.0

Universal search & planning toolkit — MCTS, bandit search, pluggable evaluators, tree reuse, DAG transpositions, root parallelism. Define an Environment, search handles the rest.
Documentation
use mctrust::{Environment, Outcome, Reward, SearchConfig, TreeSearch};

#[derive(Clone)]
struct Counter {
    value: i32,
    target: i32,
}

#[derive(Clone, Debug, PartialEq)]
enum Action {
    Increment,
    Decrement,
}

impl Environment for Counter {
    type Action = Action;

    fn legal_actions(&self) -> Vec<Action> {
        vec![Action::Increment, Action::Decrement]
    }

    fn apply(&mut self, action: &Action) {
        match action {
            Action::Increment => self.value += 1,
            Action::Decrement => self.value -= 1,
        }
    }

    fn evaluate(&self) -> Outcome {
        if self.value == self.target {
            Outcome::Success(Reward::WIN)
        } else {
            Outcome::Ongoing
        }
    }
}

fn main() {
    let state = Counter {
        value: 0,
        target: 5,
    };
    let config = SearchConfig::builder().iterations(1_000).build();
    let mut search = TreeSearch::new(state, config);

    let best = search.run();
    println!("Best action: {best:?}");
}