Crates.io | yamcts |
lib.rs | yamcts |
version | 0.1.0 |
source | src |
created_at | 2024-09-12 00:46:25.805327 |
updated_at | 2024-09-12 00:46:25.805327 |
description | An implementation of Monte Carlo Tree Search. |
homepage | |
repository | https://github.com/nowl/yamcts |
max_upload_size | |
id | 1372385 |
size | 28,948 |
This is an implementation of Monte Carlo Tree Search (MCTS) in rust.
The features that potentially make this library a bit different from the many other MCTS libraries out there:
cargo add yamcts
or in the Cargo.toml
file
[dependencies]
yamcts = "0.1.0"
run_with_duration
or run_with_iterations
on the game state to calculate next MCTS moveapply_move
on the game state and repeatsee examples/nim.rs
Run with cargo run --example nim
or cargo run --release --example nim
The default RNG uses nanorand but if you
don't want that dependency and/or would like to use a different RNG it's just necessary to
implement RngProvider
and Rng
.
use rand::prelude::*;
// Wrapper struct, in this case rand::StdRng
struct CustomRng(StdRng);
// Implement RngProvider to return an instance of CustomRng/StdRng
impl yamcts::rng::RngProvider for CustomRng {
fn init() -> Self {
CustomRng(StdRng::from_entropy())
}
}
// Implement Rng for gen_range
impl yamcts::rng::Rng for CustomRng {
fn gen_range(&mut self, bounds: Range<usize>) -> usize {
self.0.gen_range(bounds)
}
}
Then to use this RNG:
let mcts = yamcts::MCTS::<CustomRng>::default();
This project is licensed under the MIT License. See the LICENSE file for details.