From 088f0aeb23789ace5e9b77e75d5c23f5442e4cdc Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Sat, 9 Jun 2018 10:27:29 +0200 Subject: Added pruning of buying energy buildings behind a feature flag --- src/strategy/sample.rs | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 src/strategy/sample.rs (limited to 'src/strategy/sample.rs') diff --git a/src/strategy/sample.rs b/src/strategy/sample.rs deleted file mode 100644 index 370df2f..0000000 --- a/src/strategy/sample.rs +++ /dev/null @@ -1,40 +0,0 @@ -use engine; -use engine::command::*; - -use rand::{thread_rng, Rng}; - -pub fn choose_move(settings: &engine::settings::GameSettings, state: &engine::GameState) -> Command { - let mut rng = thread_rng(); - - if state.player.can_afford_defence_buildings(settings) { - for y in 0..settings.size.y { - if is_under_attack(state, y) { - let p_options = state.unoccupied_player_cells_in_row(y); - if let Some(&p) = rng.choose(&p_options) { - return Command::Build(p, BuildingType::Defence); - } - } - } - } - - if state.player.can_afford_all_buildings(settings) { - let option = rng.choose(&state.unoccupied_player_cells); - let buildings = [BuildingType::Attack, BuildingType::Defence, BuildingType::Energy]; - let building = rng.choose(&buildings); - match (option, building) { - (Some(&p), Some(&building)) => Command::Build(p, building), - _ => Command::Nothing - } - } - else { - Command::Nothing - } -} - -fn is_under_attack(state: &engine::GameState, y: u8) -> bool { - let attack = state.opponent_buildings.iter() - .any(|b| b.pos.y == y && b.weapon_damage > 0); - let defences = state.player_buildings.iter() - .any(|b| b.pos.y == y && b.health > 5); - attack && !defences -} -- cgit v1.2.3