From 600212ec15b8024d64f854c317032904fc8b4dd4 Mon Sep 17 00:00:00 2001 From: SoupCatcher Date: Fri, 22 Feb 2019 07:32:25 +0100 Subject: [PATCH] Workaround for zerg supply rounding bug https://github.com/Blizzard/s2client-proto/issues/123 --- sc2/bot_ai.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sc2/bot_ai.py b/sc2/bot_ai.py index 6c21b706..a6b352e4 100644 --- a/sc2/bot_ai.py +++ b/sc2/bot_ai.py @@ -137,6 +137,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]]: """ Returns available abilities of one or more units. Right know only checks cooldown, energy cost, and whether the ability has been researched. Example usage: @@ -588,6 +601,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