def adept(self, unit): ability = AbilityId.ADEPTPHASESHIFT_ADEPTPHASESHIFT if ability in unit.abilities: closest_attackable_enemy = get_closest_attackable_enemy(self, unit) if closest_attackable_enemy: return [unit(ability, closest_attackable_enemy.position)] return []
def drone(self, unit): actions = [] closest_attackable_enemy = get_closest_attackable_enemy(self, unit) if closest_attackable_enemy: actions += worker_decisions(self, unit, closest_attackable_enemy) if hasattr(unit, 'is_retreating') and unit.is_retreating: if closest_attackable_enemy.movement_speed > unit.movement_speed: ability = AbilityId.BURROWDOWN_DRONE if ability in unit.abilities: return [unit(ability)] return actions
def scv(self, unit): actions = [] closest_attackable_enemy = get_closest_attackable_enemy(self, unit) if closest_attackable_enemy: actions += worker_decisions(self, unit, closest_attackable_enemy) if hasattr(unit, 'is_retreating') and unit.is_retreating: # if closest_attackable_enemy.movement_speed > unit.movement_speed: closest_townhall = get_closest_unit(self, unit, self.townhalls) if unit.distance_to(closest_townhall) < unit.sight_range: ability = AbilityId.LOADALL_COMMANDCENTER if ability in closest_townhall.abilities: return [closest_townhall(ability, unit)] return actions
def attack(self, unit): actions = [] if self.all_enemy_units_and_structures: target = get_best_target_in_range(self, unit) if not target: target = get_closest_attackable_enemy(self, unit) unit.is_retreating = False if target: actions += [unit(AbilityId.ATTACK_ATTACK, target.position)] else: pass else: actions += find_enemy(self, unit) return actions
def sentry(self, unit): closest_attackable_enemy = get_closest_attackable_enemy(self, unit) if closest_attackable_enemy: return [] ability = AbilityId.FORCEFIELD_FORCEFIELD if ability in unit.abilities: closest_enemy = get_closest_unit(self, unit, self.enemy_units_and_structures) if closest_enemy and not closest_enemy.is_flying: if unit.is_retreating: position = closest_enemy.position.towards(unit.position, 1) else: position = closest_enemy.position.towards(unit.position, -1) return [unit(ability, position)] return []
def reaper(self, unit): actions = [] ability = AbilityId.KD8CHARGE_KD8CHARGE if ability in unit.abilities: closest_attackable_enemy = get_closest_attackable_enemy(self, unit) if closest_attackable_enemy: if closest_attackable_enemy.type_id == UnitTypeId.OVERLORD: actions.extend([]) if unit.is_retreating: position = closest_attackable_enemy.position.towards( unit.position, 1) else: position = closest_attackable_enemy.position.towards( unit.position, -1) actions.extend([unit(ability, position)]) return actions
def battle_decision(self, unit): actions = [] closest_attackable_enemy = get_closest_attackable_enemy(self, unit) if closest_attackable_enemy: current_distance = unit.position.distance_to(closest_attackable_enemy) larger_sight_range = get_larger_sight_range(unit, closest_attackable_enemy) if current_distance <= larger_sight_range and unit.can_attack: actions += micro_units(self, unit, closest_attackable_enemy, current_distance) elif current_distance > larger_sight_range: actions += attack_or_regroup(self, unit, closest_attackable_enemy, larger_sight_range) else: actions += [ unit(AbilityId.ATTACK_ATTACK, self.enemy_start_locations[0]) ] return actions
async def decide_action(self): t0 = time.process_time() actions = [] for unit in self.units_and_structures: if unit.type_id == UnitTypeId.ADEPT: action = adept(self, unit) actions += action if not action: actions += battle_decision(self, unit) continue if unit.type_id == UnitTypeId.ADEPTPHASESHIFT: actions += adept_phase_shift(self, unit) continue if unit.type_id == UnitTypeId.HIGHTEMPLAR: action = high_templar(self, unit) actions += action if not action: actions += battle_decision(self, unit) if unit.type_id == UnitTypeId.OBSERVER: actions += observer(self, unit) continue if unit.type_id == UnitTypeId.OBSERVERSIEGEMODE: actions += observer_siege_mode(self, unit) continue if unit.type_id == UnitTypeId.SENTRY: actions += battle_decision(self, unit) if unit.can_attack: actions += [] if hasattr(unit, 'is_retreating'): actions += sentry(self, unit) continue if unit.type_id == UnitTypeId.STALKER: actions += battle_decision(self, unit) continue if unit.type_id == UnitTypeId.WARPPRISM: actions += warp_prism(self, unit) continue if unit.type_id == UnitTypeId.ZEALOT: actions += battle_decision(self, unit) continue if unit.type_id == UnitTypeId.BARRACKS: actions += barracks(self, unit) continue if unit.type_id == UnitTypeId.BARRACKSFLYING: actions += await barracks_flying(self, unit) continue if unit.type_id == UnitTypeId.BUNKER: actions += bunker(self, unit) continue if unit.type_id == UnitTypeId.HELLION: actions += hellion(self, unit) actions += battle_decision(self, unit) continue if unit.type_id == UnitTypeId.MARINE: actions += battle_decision(self, unit) actions += marine(self, unit) continue if unit.type_id == UnitTypeId.ORBITALCOMMAND: actions += orbital_command(self, unit) continue if unit.type_id == UnitTypeId.REAPER: actions += battle_decision(self, unit) if hasattr(unit, 'is_retreating'): actions += reaper(self, unit) continue if unit.type_id == UnitTypeId.SUPPLYDEPOT: actions += supply_depot(self, unit) continue if unit.type_id == UnitTypeId.WIDOWMINE: actions += widow_mine(self, unit) continue if unit.type_id == UnitTypeId.WIDOWMINEBURROWED: actions += widow_mine_burrowed(self, unit) continue if unit.type_id == UnitTypeId.BANELING: actions += baneling(self, unit) continue if unit.type_id == UnitTypeId.BANELINGBURROWED: actions += baneling_burrowed(self, unit) continue if unit.type_id == UnitTypeId.BROODLING: actions += attack(self, unit) continue if unit.type_id == UnitTypeId.DRONE: actions += drone(self, unit) continue if unit.type_id == UnitTypeId.QUEEN: if not hasattr(unit, 'reserved_for_task') or not unit.reserved_for_task: action = await queen(self, unit) actions += action if not action: actions += battle_decision(self, unit) continue if unit.type_id == UnitTypeId.ROACH: actions += battle_decision(self, unit) continue if unit.type_id == UnitTypeId.RAVAGER: actions += ravager(self, unit) actions += battle_decision(self, unit) continue if unit.type_id == UnitTypeId.SPINECRAWLER: actions += spine_crawler(self, unit) continue if unit.type_id == UnitTypeId.SPINECRAWLERUPROOTED: actions += await spine_crawler_uprooted(self, unit) continue if unit.type_id == UnitTypeId.SPORECRAWLER: actions += spore_crawler(self, unit) continue if unit.type_id == UnitTypeId.SPORECRAWLERUPROOTED: actions += spore_crawler_uprooted(self, unit) continue if unit.type_id == UnitTypeId.ZERGLING: actions += battle_decision(self, unit) if hasattr(unit, 'is_retreating'): actions += zergling(self, unit) continue if unit.can_attack: if self.all_enemy_units_and_structures: closest_attackable_enemy = get_closest_attackable_enemy( self, unit) if closest_attackable_enemy: current_distance = unit.position.distance_to( closest_attackable_enemy) larger_sight_range = get_larger_sight_range( unit, closest_attackable_enemy) if not unit.type_id == race_worker[self.race]: if not hasattr(unit, 'reserved_for_task' ) or not unit.reserved_for_task: if current_distance <= larger_sight_range and unit.can_attack: actions += micro_units( self, unit, closest_attackable_enemy, current_distance) if current_distance > larger_sight_range: actions += attack_or_regroup( self, unit, closest_attackable_enemy, larger_sight_range) else: true_ground_range = unit.ground_range + unit.radius + closest_attackable_enemy.radius true_enemy_ground_range = closest_attackable_enemy.ground_range + closest_attackable_enemy.radius + unit.radius larger_ground_range = true_ground_range if true_ground_range > true_enemy_ground_range else true_enemy_ground_range if current_distance <= larger_ground_range and unit.can_attack: actions += micro_units(self, unit, closest_attackable_enemy, current_distance) if current_distance < larger_sight_range and current_distance > larger_ground_range: actions += attack_or_regroup( self, unit, closest_attackable_enemy, larger_sight_range) else: if not unit.type_id == race_worker[self.race]: if not hasattr(unit, 'reserved_for_task' ) or not unit.reserved_for_task: actions += attack(self, unit) else: if not unit.type_id == race_worker[self.race]: if not hasattr( unit, 'reserved_for_task') or not unit.reserved_for_task: actions += attack(self, unit) else: if unit.movement_speed: enemy_in_range = closest_enemy_in_range(self, unit) if enemy_in_range: larger_sight_range = get_larger_sight_range( unit, enemy_in_range) actions += retreat(self, unit, enemy_in_range, larger_sight_range) else: if not unit.is_ready: if closest_enemy_in_range(self, unit): actions += [unit(AbilityId.CANCEL)] else: if closest_enemy_in_range(self, unit): actions += [unit(AbilityId.LIFT_COMMANDCENTER)] if self.iteration % 32 == 0: print('decide_action time', time.process_time() - t0) return actions
def hellion(self, unit): closest_attackable_enemy = get_closest_attackable_enemy(self, unit) if closest_attackable_enemy and closest_attackable_enemy.type_id == UnitTypeId.OVERLORD: return [] return []