diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2019-08-09 17:37:24 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2019-08-09 17:37:24 +0200 |
commit | 74becec945c19bad637cb2760ca30da9b4d395f8 (patch) | |
tree | 79aba0fa58bd274e48fd400a84fd93af26ad1dab | |
parent | 366edf57a811e979fd39c3eb7d5bb06d21de41f7 (diff) |
Removed unnecessary clone
-rw-r--r-- | src/strategy/minimax.rs | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/src/strategy/minimax.rs b/src/strategy/minimax.rs index 7cc4918..2dcd7bd 100644 --- a/src/strategy/minimax.rs +++ b/src/strategy/minimax.rs @@ -36,7 +36,7 @@ pub fn choose_move( }; while start_time.to(PreciseTime::now()) < max_time { - let _ = expand_tree(&mut root_node, &state); + let _ = expand_tree(&mut root_node, state.clone()); } eprintln!("Number of simulations: {}", root_node.score_sum.visit_count); @@ -124,16 +124,15 @@ impl AddAssign<Score> for ScoreSum { } } -fn expand_tree(node: &mut Node, state: &GameBoard) -> Score { +fn expand_tree(node: &mut Node, mut state: GameBoard) -> Score { if state.outcome != SimulationOutcome::Continue { - score(state) + score(&state) } else if let Some(commands) = node.unexplored.pop() { // TODO: Explore preemptively doing the rollout - let mut new_state = state.clone(); - new_state.simulate(commands); - let score = score(&new_state); - let unexplored = if new_state.outcome == SimulationOutcome::Continue { - move_combos(&new_state) + state.simulate(commands); + let score = score(&state); + let unexplored = if state.outcome == SimulationOutcome::Continue { + move_combos(&state) } else { Vec::new() }; @@ -191,16 +190,12 @@ fn expand_tree(node: &mut Node, state: &GameBoard) -> Score { score } else { let commands = choose_existing(node); - // TODO: Is there anyway I can avoid this clone? Clone before - // calling update_tree and just pass ownership all the way - // down. - let mut new_state = state.clone(); - new_state.simulate(commands); + state.simulate(commands); let score = expand_tree( node.children .get_mut(&commands) .expect("The existing node hasn't been tried yet"), - &new_state, + state, ); update(node, commands, score); score @@ -240,7 +235,8 @@ fn score(state: &GameBoard) -> Score { const POINTS_WEIGHT: f32 = 0.; const VICTORY_WEIGHT: f32 = 3000.; - // TODO: Try adding new features here, like max worm health, weighted in some way + // TODO: Try adding new features here, like total player health, living worms, etc + // TODO: Calibrate these weightings somehow? // TODO: Distance to dirt heatmap? Probably less relevant these days. Score { val: match state.outcome { |