Skip to content
DrInfy edited this page Aug 30, 2021 · 2 revisions

There are two ways to extend plans and acts that your bot can use. Either override an existing one or simply create your own.

Example of balancing gas mining with an extended DistributeWorkers method

class AutoDistributeBalance(DistributeWorkers):
    async def execute(self) -> bool:
        self.adjust_gas_balance()
        return await super().execute()

    def adjust_gas_balance(self):
        if (
            self.ai.vespene < 50
            and self.ai.minerals > 200
            and self.ai.state.score.collection_rate_vespene == 0
            and self.cache.own(UnitTypeId.CYBERNETICSCORE).ready.amount > 0
        ):
            self.aggressive_gas_fill = True
            self.min_gas = 1
        elif self.ai.vespene < 100 and self.ai.minerals > 600:
            self.aggressive_gas_fill = True
            self.min_gas = 1
        elif len(self.ai.workers) < 12 and self.ai.vespene > 400 and self.ai.minerals < 50:
            self.max_gas = 0
        elif self.max_gas == 0 and self.ai.minerals > 200 and self.ai.vespene < 150:
            self.max_gas = None

Completely new acts need to override __init__, execute and you might also want override start for any real initialization logic with the game data and managers initialized.

class ExampleAct(ActBase):
    previous_units_manager: IPreviousUnitsManager

    def __init__(self):
        super().__init__()

    async def start(self, knowledge: "Knowledge"):
        await super().start(knowledge)
        # Get your managers here
        self.previous_units_manager = knowledge.get_required_manager(IPreviousUnitsManager)

    async def execute(self) -> bool:
        # Execute your logic here
        ...
Clone this wiki locally