Skip to content

Commit

Permalink
Merge pull request #161 from AresSC2/fix/worker-build-gas
Browse files Browse the repository at this point in the history
fix: worker build gas
  • Loading branch information
raspersc2 authored Jul 22, 2024
2 parents 456eeac + d6b7337 commit 0c2d0f1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
12 changes: 10 additions & 2 deletions src/ares/managers/building_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _handle_construction_orders(self) -> None:
tags_to_remove.add(worker_tag)
continue

target: Point2 = self.building_tracker[worker_tag][TARGET]
target: Union[Point2, Unit] = self.building_tracker[worker_tag][TARGET]
worker = self.ai.unit_tag_dict.get(worker_tag, None)
if not worker:
dead_tags_to_remove.add(worker_tag)
Expand Down Expand Up @@ -234,6 +234,14 @@ def _handle_construction_orders(self) -> None:

distance: float = 3.2 if structure_id in GAS_BUILDINGS else 1.0

# TODO: This is a workaround for a strange bug where the client
# returns an error when issuing a build gas command occasionally
# this seems to fix it for now
if self.ai.race == Race.Protoss and structure_id in GAS_BUILDINGS:
if self.ai.can_afford(structure_id):
worker.build_gas(target)
continue

# if terran, check for unfinished structure
existing_unfinished_structure: Optional[Unit] = None
if self.ai.race == Race.Terran and structure_id in structures_dict:
Expand Down Expand Up @@ -298,7 +306,7 @@ def _handle_construction_orders(self) -> None:
)
continue

if (
elif (
(not worker.is_constructing_scv or worker.is_idle)
and self.ai.can_afford(structure_id)
and self.ai.tech_requirement_progress(structure_id) == 1.0
Expand Down
11 changes: 0 additions & 11 deletions src/ares/managers/intel_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,17 +333,6 @@ async def update(self, iteration: int) -> None:
):
self.enemy_went_reaper = True

# check for greed
if not self.get_enemy_was_greedy and 170.0 < self.ai.time < 270.0:
# zerg expanded and no queens by certain time
if (
self.ai.enemy_race == Race.Zerg
and self.get_enemy_expanded
and len(self.manager_mediator.get_enemy_army_dict[UnitID.QUEEN]) == 0
):
logger.info(f"{self.ai.time}: Enemy greed detected")
self.get_enemy_was_greedy = True

def _check_for_enemy_rush(self):
if self.ai.enemy_race == Race.Zerg and not self.enemy_ling_rushed:
if (
Expand Down
5 changes: 4 additions & 1 deletion src/ares/managers/manager_mediator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,10 @@ def select_worker(self, **kwargs) -> Optional[Unit]:
If True we can select the persistent_builder if it's available.
only_select_persistent_builder : bool
If True, don't find an alternative worker
min_health_perc : float (optional)
min_health_perc :
Only select workers above this health percentage.
min_shield_perc :
Only select workers above this shield percentage.
Returns
-------
Expand Down
6 changes: 6 additions & 0 deletions src/ares/managers/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
cy_distance_to_squared,
cy_sorted_by_distance_to,
)
from sc2.data import Race
from sc2.position import Point2
from sc2.unit import Unit
from sc2.units import Units
Expand Down Expand Up @@ -318,6 +319,7 @@ def select_worker(
select_persistent_builder: bool = False,
only_select_persistent_builder: bool = False,
min_health_perc: float = 0.0,
min_shield_perc: float = 0.0,
) -> Optional[Unit]:
"""Select a worker.
Expand All @@ -342,6 +344,8 @@ def select_worker(
If True, don't find an alternative worker
min_health_perc :
Only select workers above this health percentage.
min_shield_perc :
Only select workers above this shield percentage.
Returns
-------
Expand Down Expand Up @@ -369,6 +373,8 @@ def select_worker(
workers: Units = self.manager_mediator.get_units_from_roles(
roles={UnitRole.GATHERING, UnitRole.IDLE}, unit_type=self.ai.worker_type
).filter(lambda u: u.health_percentage >= min_health_perc)
if self.ai.race == Race.Protoss and min_shield_perc > 0.0:
workers = workers.filter(lambda u: u.shield_percentage >= min_shield_perc)
# there is a chance we have no workers
if not workers or not target_position:
return
Expand Down

0 comments on commit 0c2d0f1

Please sign in to comment.