From a760bc7543b186714b11648e8be515dcdfc49b95 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sun, 12 Aug 2018 09:37:44 +0200 Subject: Allowed monte carlo search to use iron curtains --- src/strategy/monte_carlo.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/strategy') diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs index 57eaaff..95d87fa 100644 --- a/src/strategy/monte_carlo.rs +++ b/src/strategy/monte_carlo.rs @@ -116,21 +116,24 @@ fn simulate_to_endstate(command_score: &mut CommandScore, state: &Bitwis fn random_player_move(state: &BitwiseGameState, rng: &mut R) -> Command { let all_buildings = sensible_buildings(&state.player, &state.player_buildings, state.player_has_max_teslas()); - random_move(&all_buildings, rng, state.unoccupied_player_cell_count(), |i| state.location_of_unoccupied_player_cell(i)) + random_move(&all_buildings, state.player_can_build_iron_curtain(), rng, state.unoccupied_player_cell_count(), |i| state.location_of_unoccupied_player_cell(i)) } fn random_opponent_move(state: &BitwiseGameState, rng: &mut R) -> Command { let all_buildings = sensible_buildings(&state.opponent, &state.opponent_buildings, state.opponent_has_max_teslas()); - random_move(&all_buildings, rng, state.unoccupied_opponent_cell_count(), |i| state.location_of_unoccupied_opponent_cell(i)) + random_move(&all_buildings, state.opponent_can_build_iron_curtain(), rng, state.unoccupied_opponent_cell_count(), |i| state.location_of_unoccupied_opponent_cell(i)) } // TODO: Given enough energy, most opponents won't do nothing -fn random_movePoint>(all_buildings: &[BuildingType], rng: &mut R, free_positions_count: usize, get_point: F) -> Command { +fn random_movePoint>(all_buildings: &[BuildingType], iron_curtain_available: bool, rng: &mut R, free_positions_count: usize, get_point: F) -> Command { let nothing_count = 1; - let building_choice_index = rng.gen_range(0, nothing_count + all_buildings.len()); + let iron_curtain_count = if iron_curtain_available { 1 } else { 0 }; + let building_choice_index = rng.gen_range(0, all_buildings.len() + nothing_count + iron_curtain_count); if building_choice_index == all_buildings.len() { Command::Nothing + } else if iron_curtain_available && building_choice_index == all_buildings.len() + 1 { + Command::IronCurtain } else { let position_choice = rng.gen_range(0, free_positions_count); Command::Build( -- cgit v1.2.3