From 7f40701877a01ab17698d6bd60811b08140d0f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aki=20V=C3=A4nttinen?= Date: Tue, 26 Sep 2023 17:34:29 +0300 Subject: [PATCH] support for bot micro map --- sharpy/combat/protoss/micro_sentries.py | 7 ++++--- sharpy/knowledges/knowledge.py | 13 +++++++++++++ sharpy/managers/core/building_solver.py | 13 +++++++------ sharpy/managers/core/gather_point_solver.py | 15 +++++++++------ sharpy/managers/core/pathing_manager.py | 4 ++-- sharpy/managers/core/zone_manager.py | 8 +++++++- sharpy/managers/extensions/game_analyzer.py | 2 +- 7 files changed, 43 insertions(+), 19 deletions(-) diff --git a/sharpy/combat/protoss/micro_sentries.py b/sharpy/combat/protoss/micro_sentries.py index f46358d4..a69e7df1 100644 --- a/sharpy/combat/protoss/micro_sentries.py +++ b/sharpy/combat/protoss/micro_sentries.py @@ -41,9 +41,10 @@ async def start(self, knowledge: "Knowledge"): await super().start(knowledge) ramp_ff_movement = 2 - ramp = self.zone_manager.expansion_zones[0].ramp - if ramp: - self.main_ramp_position = ramp.bottom_center.towards(ramp.top_center, ramp_ff_movement) + if self.zone_manager.expansion_zones: + ramp = self.zone_manager.expansion_zones[0].ramp + if ramp: + self.main_ramp_position = ramp.bottom_center.towards(ramp.top_center, ramp_ff_movement) self.building_solver = knowledge.get_manager(IBuildingSolver) def group_solve_combat(self, units: Units, current_command: Action) -> Action: diff --git a/sharpy/knowledges/knowledge.py b/sharpy/knowledges/knowledge.py index 41d520b6..c434fb90 100644 --- a/sharpy/knowledges/knowledge.py +++ b/sharpy/knowledges/knowledge.py @@ -88,6 +88,19 @@ def pre_start(self, ai: "SkeletonBot", additional_managers: Optional[List[Manage self._debug = self.config["general"].getboolean("debug") self.my_worker_type = UnitValue.get_worker_type(self.my_race) + if self.ai.start_location is None: + if self.ai.structures: + self.ai.game_info.player_start_location = self.ai.structures.center + elif self.ai.structures: + self.ai.game_info.player_start_location = self.ai.units.center + else: + self.ai.game_info.player_start_location = self.ai.game_info.map_center + + if self.ai.enemy_structures: + self.ai.game_info.start_locations = [self.ai.enemy_structures.center] + else: + self.ai.game_info.start_locations = [self.ai.game_info.map_center] + def _set_managers(self, additional_managers: Optional[List[ManagerBase]]): """ Sets managers to be updated. diff --git a/sharpy/managers/core/building_solver.py b/sharpy/managers/core/building_solver.py index c474bd3b..e7c8915d 100644 --- a/sharpy/managers/core/building_solver.py +++ b/sharpy/managers/core/building_solver.py @@ -198,14 +198,15 @@ def buildings5x5(self) -> List[Point2]: async def start(self, knowledge: "Knowledge"): await super().start(knowledge) - self.grid = BuildGrid(self.knowledge) - self.base_ramp = self.zone_manager.expansion_zones[0].ramp - self.color_zone(self.zone_manager.expansion_zones[0], ZoneArea.OwnMainZone) - self.color_zone(self.zone_manager.expansion_zones[1], ZoneArea.OwnNaturalZone) - self.color_zone(self.zone_manager.expansion_zones[2], ZoneArea.OwnThirdZone) + if (len(self.zone_manager.expansion_zones) > 1): + self.grid = BuildGrid(self.knowledge) + self.base_ramp = self.zone_manager.expansion_zones[0].ramp + self.color_zone(self.zone_manager.expansion_zones[0], ZoneArea.OwnMainZone) + self.color_zone(self.zone_manager.expansion_zones[1], ZoneArea.OwnNaturalZone) + self.color_zone(self.zone_manager.expansion_zones[2], ZoneArea.OwnThirdZone) async def update(self): - if self.knowledge.iteration == 0: + if self.knowledge.iteration == 0 and len(self.zone_manager.expansion_zones) > 0: await self.solve_grid() async def post_update(self): diff --git a/sharpy/managers/core/gather_point_solver.py b/sharpy/managers/core/gather_point_solver.py index 14250370..a0e49049 100644 --- a/sharpy/managers/core/gather_point_solver.py +++ b/sharpy/managers/core/gather_point_solver.py @@ -34,13 +34,16 @@ def set_expanding_to(self, target: Point2) -> None: async def start(self, knowledge: "Knowledge"): await super().start(knowledge) - base_ramp = self.zone_manager.expansion_zones[0].ramp - if base_ramp: - self._inital_gather_point = base_ramp.top_center.towards(base_ramp.bottom_center, -4) + if self.zone_manager.expansion_zones: + base_ramp = self.zone_manager.expansion_zones[0].ramp + if base_ramp: + self._inital_gather_point = base_ramp.top_center.towards(base_ramp.bottom_center, -4) + else: + self._inital_gather_point = self.zone_manager.expansion_zones[0].center_location.towards( + self.zone_manager.enemy_start_location, 8 + ) else: - self._inital_gather_point = self.zone_manager.expansion_zones[0].center_location.towards( - self.zone_manager.enemy_start_location, 8 - ) + self._inital_gather_point = self.ai.start_location async def update(self): if not self._gather_point_set: diff --git a/sharpy/managers/core/pathing_manager.py b/sharpy/managers/core/pathing_manager.py index 2a02a73a..2bc7ccea 100644 --- a/sharpy/managers/core/pathing_manager.py +++ b/sharpy/managers/core/pathing_manager.py @@ -40,8 +40,8 @@ async def start(self, knowledge: "Knowledge"): game_info.terrain_height.data_numpy, game_info.playable_area, ) - - self.map.calculate_connections(self.ai.start_location) # This is for checking dead warp zones + if self.ai.start_location is not None: + self.map.calculate_connections(self.ai.start_location) # This is for checking dead warp zones _data = np.fmax(path_grid.data_numpy, placement_grid.data_numpy).T self.path_finder_terrain = sc2pathlib.PathFinder(_data) diff --git a/sharpy/managers/core/zone_manager.py b/sharpy/managers/core/zone_manager.py index 6b566ac6..38597048 100644 --- a/sharpy/managers/core/zone_manager.py +++ b/sharpy/managers/core/zone_manager.py @@ -187,6 +187,9 @@ def set_pathing_zones(self): pather.map.calculate_zones(expansion_locations_list) def init_zones(self): + if len(self.ai._expansion_positions_list) == 0: + return + """Add expansion locations as zones.""" for exp_loc in self.ai.expansion_locations_list: # type: Point2 is_start_location = False @@ -388,9 +391,12 @@ def _enemy_zone_distance_to_naturals(self, zone: Zone): # region Update async def update(self): + if len(self.expansion_zones) == 0: + return + self._enemy_zones.clear() self._our_zones.clear() - if self.knowledge.iteration == 0: + if self.knowledge.iteration == 0 and self._expansion_zones: self.init_zone_pathing() self.update_own_units_zones() diff --git a/sharpy/managers/extensions/game_analyzer.py b/sharpy/managers/extensions/game_analyzer.py index 8f4c1a7a..9199e64c 100644 --- a/sharpy/managers/extensions/game_analyzer.py +++ b/sharpy/managers/extensions/game_analyzer.py @@ -97,7 +97,7 @@ async def update(self): enemy_workers = 12 else: enemy_workers = self.enemy_units_manager.enemy_worker_count - if not self.zone_manager.enemy_main_zone.is_scouted_at_least_once: + if self.zone_manager.expansion_zones and not self.zone_manager.enemy_main_zone.is_scouted_at_least_once: enemy_workers += 12 mineral_fields = 0