Working MCTS implementation
This is a basic working implementation of the MCTS algorithm. Though currently the algorithm is slow compared with other implemenations, and makes sub-optimal choices when playing tic-tac-toe. Therefore some modifications are needed
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
//! Random play simulation policy
|
||||
//!
|
||||
//! Actions are chosen at random
|
||||
|
||||
use crate::state::GameState;
|
||||
use crate::tree::node::{Node, RewardVal};
|
||||
use rand::prelude::SliceRandom;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub fn simulate<S: GameState>(node: &Node<S>) -> HashMap<S::Player, RewardVal> {
|
||||
let mut state: S = node.state.clone();
|
||||
while !state.is_terminal() {
|
||||
let legal_actions = state.get_legal_actions();
|
||||
let action = legal_actions.choose(&mut rand::thread_rng()).unwrap();
|
||||
state = state.state_after_action(&action);
|
||||
}
|
||||
state.rewards_for_players()
|
||||
}
|
||||
Reference in New Issue
Block a user