From 9d85dbdfcd8fa70ca2ebe8ab9ee444dd55790fd1 Mon Sep 17 00:00:00 2001 From: FredNoonienSingh Date: Sat, 11 Jan 2025 21:53:15 +0100 Subject: [PATCH] fixxed max_iter_crashes --- bot/HarstemsAunt/main.py | 36 +++++++++++++++++----------------- bot/HarstemsAunt/map_sector.py | 14 +++++++++++++ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/bot/HarstemsAunt/main.py b/bot/HarstemsAunt/main.py index 192d210..58dc8ca 100644 --- a/bot/HarstemsAunt/main.py +++ b/bot/HarstemsAunt/main.py @@ -193,6 +193,22 @@ async def on_step(self, iteration:int): for t in threads: t.join() + if not self.macro.build_order.opponent_builds_air: + if [unit for unit in self.seen_enemies if unit.is_flying and unit.can_attack]: + self.macro.build_order.opponent_builds_air = True + await self.chat_send("I see you got an AirForce, i can do that too") + + if not self.macro.build_order.opponent_has_detection: + if [unit for unit in self.seen_enemies if unit.is_flying and unit.can_attack]: + self.macro.build_order.opponent_has_detection = True + + if not self.macro.build_order.opponent_uses_cloak: + if [unit for unit in self.seen_enemies if (unit.is_cloaked and unit.can_attack) or (unit.is_burrowed and unit.can_attack)]: + self.macro.build_order.opponent_uses_cloak = True + await self.chat_send("Stop hiding and fight like a honorable ... \ + ähm... Robot?\ndo computers have honor ?") + + self.pathing.update(iteration) for j, group in enumerate(self.army_groups): @@ -272,26 +288,10 @@ async def on_enemy_unit_entered_vision(self, unit:Unit) -> None: Args: unit (Unit): Unit """ - if not unit.tag in self.seen_enemies and unit.type_id not in WORKER_IDS: - self.seen_enemies.append(unit.tag) + if not unit in self.seen_enemies and unit.type_id not in WORKER_IDS: + self.seen_enemies.append(unit) self.enemy_supply += self.calculate_supply_cost(unit.type_id) - if not self.macro.build_order.opponent_builds_air: - if unit.is_flying and unit.can_attack: - self.macro.build_order.opponent_builds_air = True - await self.chat_send("I see you got an AirForce, i can do that too") - - #TODO: #76 Fix max iter depth crashes - if not self.macro.build_order.opponent_has_detection: - if unit.is_detector: - self.macro.build_order.opponent_has_detection = True - - if not self.macro.build_order.opponent_uses_cloak: - if (unit.is_cloaked and unit.can_attack) \ - or (unit.is_burrowed and unit.can_attack): - self.macro.build_order.opponent_uses_cloak = True - await self.chat_send("Stop hiding and fight like a honorable ... \ - ähm... Robot?\ndo computers have honor ?") #TODO: #73 Implement on_enemy_unit_left_vision logic async def on_enemy_unit_left_vision(self, unit_tag:int): """ Coroutine gets called when enemy left vision diff --git a/bot/HarstemsAunt/map_sector.py b/bot/HarstemsAunt/map_sector.py index 4aa66f0..7493bbc 100644 --- a/bot/HarstemsAunt/map_sector.py +++ b/bot/HarstemsAunt/map_sector.py @@ -97,6 +97,20 @@ def in_sector(self,unit:Unit) -> bool: min_y, max_y = self.upper_left.y,self.lower_right.y return min_x <= unit.position.x <= max_x and min_y <= unit.position.y <= max_y + def find_ramps_in_sector(self, ramp: Point2) -> List[Point2]: + """ Finds the Ramp within the sector + + Args: + ramp (Point2): returns the top of the ramp + + Returns: + List[Point2]: of Top - center Point of the Ramp + """ + min_x, max_x = self.upper_left.x, self.lower_right.x + min_y, max_y = self.upper_left.y,self.lower_right.y + top_x, top_y = ramp.top_center.x, ramp.top_center.y + return min_x <= top_x <= max_x and min_y <= top_y <= max_y + def build_sector(self) -> None: """This should be implemented differently and will be reworked """ self.ramps = self.ramps_in_sector()