Upgrade rand to ~0.9
This commit is contained in:
+2
-2
@@ -7,7 +7,7 @@ use crate::state::GameState;
|
||||
use crate::tree::arena::Arena;
|
||||
use crate::tree::node::{Node, RewardVal};
|
||||
use crate::tree::print_tree;
|
||||
use rand::prelude::SliceRandom;
|
||||
use rand::prelude::IndexedRandom;
|
||||
use std::collections::HashMap;
|
||||
use std::time::Instant;
|
||||
|
||||
@@ -75,7 +75,7 @@ impl<'conf, S: GameState + std::fmt::Debug> MCTS<'conf, S> {
|
||||
if !selected_node.state.is_terminal() {
|
||||
self.expand(selected_id);
|
||||
let children: &Vec<usize> = &self.arena.get_node(selected_id).children;
|
||||
let random_child: usize = *children.choose(&mut rand::thread_rng()).unwrap();
|
||||
let random_child: usize = *children.choose(&mut rand::rng()).unwrap();
|
||||
selected_id = random_child;
|
||||
}
|
||||
let rewards = self.simulate(selected_id);
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
|
||||
use crate::state::GameState;
|
||||
use crate::tree::node::{Node, RewardVal};
|
||||
use rand::prelude::SliceRandom;
|
||||
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::thread_rng()).unwrap();
|
||||
let action = legal_actions.choose(&mut rand::rng()).unwrap();
|
||||
state = state.state_after_action(&action);
|
||||
}
|
||||
state.rewards_for_players()
|
||||
|
||||
Reference in New Issue
Block a user