simple_mcts/lib.rs
1//! A Rust library providing a highly configurable and efficient
2//! Monte Carlo Tree Search (MCTS) implementation.
3//!
4//! This library supports various game types and integrates with external
5//! game evaluators for flexible AI development. It includes both
6//! single-instance and batch-processing capabilities for MCTS.
7//!
8//! # Modules
9//! - `tree`: Implements the core tree data structure used by MCTS.
10//! - `game`: Defines traits for game logic and state evaluation.
11//! - `mcts`: Provides the single-instance MCTS algorithm.
12//! - `mcts_batch`: Offers an MCTS implementation capable of processing multiple
13//! game instances in parallel for increased throughput.
14//! - `utils`: Contains general utility functions.
15//! - `test_utils`: Provides helper implementations for testing the MCTS algorithms.
16//!
17//! # Examples
18//! ```rust
19//! use simple_mcts::{Mcts, test_utils::{GameTest, GameEvaluatorTest2}, MctsError};
20//!
21//! fn main() -> Result<(), MctsError> {
22//! let mut mcts: Mcts<GameTest, 4> = Mcts::<GameTest, 4>::new();
23//! let evaluator = GameEvaluatorTest2::new();
24//!
25//! // Perform 100 MCTS iterations
26//! for _ in 0..100 {
27//! mcts.iterate(&evaluator)?;
28//! }
29//!
30//! // Get the best action based on visit counts
31//! let (score, policy) = mcts.get_result();
32//! println!("Best action score: {}, Policy: {:?}", score, policy);
33//!
34//! // Play the best action and update the MCTS tree
35//! let best_action_index = policy.iter()
36//! .enumerate()
37//! .max_by(|(_, &a), (_, &b)| a.partial_cmp(&b).unwrap())
38//! .map(|(index, _)| index)
39//! .unwrap_or(0); // Default to first action if policy is empty
40//! mcts.play(best_action_index)?;
41//!
42//! // Continue with the next game state
43//! Ok(())
44//! }
45//! ```
46//!
47//! This library aims to be a robust foundation for AI development in board games,
48//! particularly those benefiting from tree search algorithms like AlphaZero.
49
50mod tree;
51mod game;
52mod mcts;
53mod mcts_batch;
54pub mod utils;
55
56#[doc(hidden)]
57pub mod test_utils;
58
59use tree::*;
60pub use game::*;
61pub use mcts::*;
62pub use mcts_batch::*;