19 lines
582 B
Rust
19 lines
582 B
Rust
//! Random play simulation policy
|
|
//!
|
|
//! Actions are chosen at random
|
|
|
|
use crate::state::GameState;
|
|
use crate::tree::node::{Node, RewardVal};
|
|
use rand::prelude::IndexedRandom;
|
|
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::rng()).unwrap();
|
|
state = state.state_after_action(&action);
|
|
}
|
|
state.rewards_for_players()
|
|
}
|