Skip to content

Commit

Permalink
support for bot micro map
Browse files Browse the repository at this point in the history
  • Loading branch information
Aki Vänttinen committed Sep 26, 2023
1 parent 47c157a commit 7f40701
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 19 deletions.
7 changes: 4 additions & 3 deletions sharpy/combat/protoss/micro_sentries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 13 additions & 0 deletions sharpy/knowledges/knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 7 additions & 6 deletions sharpy/managers/core/building_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 9 additions & 6 deletions sharpy/managers/core/gather_point_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions sharpy/managers/core/pathing_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion sharpy/managers/core/zone_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion sharpy/managers/extensions/game_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7f40701

Please sign in to comment.