From 648dce3cfae16253472ed87674de448555ef0a15 Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sun, 12 Aug 2018 12:05:12 +0200 Subject: Test cases that do the iron curtain --- src/engine/bitwise_engine.rs | 8 ++++---- src/strategy/monte_carlo.rs | 12 ++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/engine/bitwise_engine.rs b/src/engine/bitwise_engine.rs index d8cbec6..0bcacbc 100644 --- a/src/engine/bitwise_engine.rs +++ b/src/engine/bitwise_engine.rs @@ -64,10 +64,7 @@ impl BitwiseGameState { BitwiseGameState::update_construction(&mut self.player_buildings); BitwiseGameState::update_construction(&mut self.opponent_buildings); - - BitwiseGameState::update_iron_curtain(&mut self.player_buildings, self.round); - BitwiseGameState::update_iron_curtain(&mut self.opponent_buildings, self.round); - + BitwiseGameState::fire_teslas(&mut self.player, &mut self.player_buildings, &mut self.opponent, &mut self.opponent_buildings); BitwiseGameState::add_missiles(&mut self.player_buildings); @@ -79,6 +76,9 @@ impl BitwiseGameState { BitwiseGameState::add_energy(&mut self.player, &mut self.player_buildings); BitwiseGameState::add_energy(&mut self.opponent, &mut self.opponent_buildings); + BitwiseGameState::update_iron_curtain(&mut self.player_buildings, self.round); + BitwiseGameState::update_iron_curtain(&mut self.opponent_buildings, self.round); + self.round += 1; self.update_status(); diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs index 95d87fa..b02ebf4 100644 --- a/src/strategy/monte_carlo.rs +++ b/src/strategy/monte_carlo.rs @@ -134,12 +134,14 @@ fn random_movePoint>(all_buildings: &[BuildingType], iron_ Command::Nothing } else if iron_curtain_available && building_choice_index == all_buildings.len() + 1 { Command::IronCurtain - } else { + } else if free_positions_count > 0 { let position_choice = rng.gen_range(0, free_positions_count); Command::Build( get_point(position_choice), all_buildings[building_choice_index] ) + } else { + Command::Nothing } } @@ -202,10 +204,12 @@ impl CommandScore { let unoccupied_cells = (0..state.unoccupied_player_cell_count()).map(|i| state.location_of_unoccupied_player_cell(i)); let building_command_count = unoccupied_cells.len()*all_buildings.len(); - let nothing_count = 1; - let mut commands = Vec::with_capacity(building_command_count + nothing_count); + let mut commands = Vec::with_capacity(building_command_count + 2); commands.push(CommandScore::new(Command::Nothing)); + if state.player_can_build_iron_curtain() { + commands.push(CommandScore::new(Command::IronCurtain)); + } for position in unoccupied_cells { for &building in &all_buildings { @@ -238,7 +242,7 @@ fn sensible_buildings(player: &Player, _player_buildings: &PlayerBuildings, has_ } -//TODO: Heuristic that avoids building the initial energy towers all in the same row? +//TODO: Heuristic that avoids building the initial energy towers all in the same row? Max energy in a row? //TODO: Update cutoff to maybe build iron curtains #[cfg(feature = "energy-cutoff")] fn sensible_buildings(player: &Player, player_buildings: &PlayerBuildings, has_max_teslas: bool) -> Vec { -- cgit v1.2.3