From b78eae28a11edefb27599d16307f248b52f74b6d Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sun, 2 Sep 2018 20:48:15 +0200 Subject: Made it possible to build iron curtains as they become available --- src/engine/bitwise_engine.rs | 5 +++++ src/strategy/monte_carlo.rs | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/engine/bitwise_engine.rs b/src/engine/bitwise_engine.rs index afd4bcc..35b574e 100644 --- a/src/engine/bitwise_engine.rs +++ b/src/engine/bitwise_engine.rs @@ -336,6 +336,11 @@ impl Player { self.iron_curtain_available && self.iron_curtain_remaining == 0 } + pub fn can_build_iron_curtain_in(&self, round: u16, moves: u8) -> bool { + let unlocks = round % IRON_CURTAIN_UNLOCK_INTERVAL > round + u16::from(moves) % IRON_CURTAIN_UNLOCK_INTERVAL; + (self.iron_curtain_available || unlocks) && self.iron_curtain_remaining.saturating_sub(moves) == 0 + } + pub fn unoccupied_cell_count(&self) -> usize { self.occupied.count_zeros() as usize } pub fn location_of_unoccupied_cell(&self, i: usize) -> Point { let bit = find_bit_index_from_rank(self.occupied, i as u64); diff --git a/src/strategy/monte_carlo.rs b/src/strategy/monte_carlo.rs index 1a4c400..f6b8956 100644 --- a/src/strategy/monte_carlo.rs +++ b/src/strategy/monte_carlo.rs @@ -257,7 +257,7 @@ fn random_move(player: &Player, opponent: &Player, rng: &mut R) -> Comma 0 } else { // TODO: take into account opponent attacks and defence in row? - 8 + opponent.count_energy_towers_in_row(point.y()) - player.count_attack_towers_in_row(point.y()) + 8 + opponent.count_energy_towers_in_row(point.y()) + opponent.count_towers_in_row(point.y()) - player.count_attack_towers_in_row(point.y()) }; attack_end += weight; @@ -402,9 +402,11 @@ impl CommandScore { } let building_command_count = unoccupied_cells.len()*all_buildings.len(); - + let mut commands = Vec::with_capacity(building_command_count + 1); - if state.player.can_build_iron_curtain() && IRON_CURTAIN_PRICE.saturating_sub(state.player.energy) / energy_generated < 4 { + let time_to_curtain_energy = (IRON_CURTAIN_PRICE.saturating_sub(state.player.energy) / energy_generated) as u8; + + if time_to_curtain_energy < 4 && state.player.can_build_iron_curtain_in(state.round, time_to_curtain_energy) { commands.push(CommandScore::new(Command::IronCurtain, state.player.energy < IRON_CURTAIN_PRICE)); } -- cgit v1.2.3