Skip to content

Commit

Permalink
Merge pull request #4 from Dentosal/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
tweakimp authored Feb 25, 2019
2 parents f05437c + 377e049 commit 41b74af
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions sc2/bot_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ def expansion_locations(self) -> Dict[Point2, Units]:
""" Returns dict with the correct expansion position Point2 key, resources (mineral field, vespene geyser) as value """
return centers

def _correct_zerg_supply(self):
""" The client incorrectly rounds zerg supply down instead of up (see
https://github.com/Blizzard/s2client-proto/issues/123), so self.supply_used
and friends return the wrong value when there are an odd number of zerglings
and banelings. This function corrects the bad values. """
# TODO: remove when Blizzard/sc2client-proto#123 gets fixed.
correction = self.units({UnitTypeId.ZERGLING, UnitTypeId.ZERGLINGBURROWED,
UnitTypeId.BANELING, UnitTypeId.BANELINGBURROWED,
UnitTypeId.BANELINGCOCOON}).amount % 2
self.supply_used += correction
self.supply_army += correction
self.supply_left -= correction

async def get_available_abilities(
self, units: Union[List[Unit], Units], ignore_resource_requirements=False
) -> List[List[AbilityId]]:
Expand Down Expand Up @@ -652,6 +665,11 @@ def _prepare_step(self, state):
self.supply_cap: Union[float, int] = state.common.food_cap
self.supply_used: Union[float, int] = state.common.food_used
self.supply_left: Union[float, int] = self.supply_cap - self.supply_used

# Workaround Zerg supply rounding bug
if self.race == Race.Zerg:
self._correct_zerg_supply()

self.idle_worker_count: int = state.common.idle_worker_count
self.army_count: int = state.common.army_count
self.warp_gate_count: int = state.common.warp_gate_count
Expand Down

0 comments on commit 41b74af

Please sign in to comment.