Skip to content

Commit

Permalink
Merge pull request #167 from AresSC2/fix/fleeing-probes-and-prod-cont…
Browse files Browse the repository at this point in the history
…roller

fix: fleeing probes and production controller fix
  • Loading branch information
raspersc2 authored Aug 26, 2024
2 parents 5e8c692 + 5df3685 commit 474da3b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
16 changes: 11 additions & 5 deletions src/ares/behaviors/macro/mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import numpy as np
from loguru import logger
from sc2.data import Race
from sc2.ids.ability_id import AbilityId
from sc2.ids.unit_typeid import UnitTypeId as UnitID
from sc2.position import Point2
Expand Down Expand Up @@ -111,6 +112,7 @@ def execute(self, ai: "AresBot", config: dict, mediator: ManagerMediator) -> boo
# for each mineral tag, get the position in front of the mineral
min_target: dict[int, Point2] = mediator.get_mineral_target_dict
main_enemy_ground_threats: Optional[Units] = None
race: Race = ai.race
if self.self_defence_active:
main_enemy_ground_threats = mediator.get_main_ground_threats_near_townhall

Expand Down Expand Up @@ -153,13 +155,18 @@ def execute(self, ai: "AresBot", config: dict, mediator: ManagerMediator) -> boo
mediator.remove_gas_building(gas_building_tag=resource_tag)
continue

perc_health: float = (
worker.health_percentage
if race != Race.Protoss
else worker.shield_health_percentage
)
# keeping worker safe is first priority
if self.keep_safe and (
# lib zone / nukes etc
not pos_safe(grid=avoidance_grid, position=worker_position)
# retreat based on self.flee_at_health_perc value
or (
worker.health_percentage <= health_perc
perc_health <= health_perc
and not pos_safe(grid=grid, position=worker_position)
)
):
Expand All @@ -171,15 +178,14 @@ def execute(self, ai: "AresBot", config: dict, mediator: ManagerMediator) -> boo
resource_position,
dist_to_resource,
)
continue

if main_enemy_ground_threats and self._worker_attacking_enemy(
elif main_enemy_ground_threats and self._worker_attacking_enemy(
ai, dist_to_resource, worker
):
continue
pass

# do we have record of this worker? If so mine from the relevant resource
if ai.townhalls and (assigned_mineral_patch or assigned_gas_building):
elif ai.townhalls and (assigned_mineral_patch or assigned_gas_building):
# we are far away, path to min field to avoid enemies
if dist_to_resource > 6.0 and not worker.is_carrying_resource:
worker.move(
Expand Down
6 changes: 6 additions & 0 deletions src/ares/behaviors/macro/production_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ def execute(self, ai: "AresBot", config: dict, mediator: ManagerMediator) -> boo
existing_structures: list[Unit] = []
for structure_type in train_from:
existing_structures.extend(structure_dict[structure_type])
# target proportion is low, don't add extra pending
if target_proportion <= 0.15 and (
any([ai.structure_pending(type_id) for type_id in train_from])
):
continue

divide_by: int = 420 if unit_type_id in GATEWAY_UNITS else 760
if len(existing_structures) >= int(collection_rate / divide_by):
continue
Expand Down
7 changes: 6 additions & 1 deletion src/ares/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,17 @@ class UnitRole(str, Enum):
"DROP_UNITS_ATTACKING" # units dropped off, that now need to attack
)
DROP_UNITS_TO_LOAD = "DROP_UNITS_TO_LOAD" # units that require picking up
# reserved roles for flanking
FLANK_GROUP_ONE = "FLANK_GROUP_ONE"
FLANK_GROUP_TWO = "FLANK_GROUP_TWO"
FLANK_GROUP_THREE = "FLANK_GROUP_THREE"
GATHERING = "GATHERING" # workers that are mining
HARASSING = "HARASSING" # units that are harassing
HARASSING_ADEPT = "HARASSING_ADEPT"
HARASSING_BANSHEE = "HARASSING_BANSHEE"
HARASSING_ORACLE = "HARASSING_ORACLE"
HARASSING_PHOENIX = "HARASSING_PHOENIX"
HARASSING_REAPER = "HARASSING_REAPER"
HARASSING_LINGS = "HARASSING_LINGS"
IDLE = "IDLE" # not doing anything
MAP_CONTROL = "MAP_CONTROL" # units controlling the map (lings/hellions?)
MORPHING = "MORPHING" # units currently morphing
Expand Down

0 comments on commit 474da3b

Please sign in to comment.