Build a list of actions in distribute_workers
With short step time limits, doing all these actions one by one with
`do` is too slow. This attempt tries to fix it by building a single list
of actions and executing them all at once with `do_actions`.
@@ -175,9 +175,11 @@ class BotAI(object):
expansion_locations = self.expansion_locations
owned_expansions = self.owned_expansions
worker_pool = []
+ actions = []
+
for idle_worker in self.workers.idle:
mf = self.state.mineral_field.closest_to(idle_worker)
- await self.do(idle_worker.gather(mf))
+ actions.append(idle_worker.gather(mf))
for location, townhall in owned_expansions.items():
workers = self.workers.closer_than(20, location)
@@ -205,10 +207,10 @@ class BotAI(object):
if worker_pool:
w = worker_pool.pop()
if len(w.orders) == 1 and w.orders[0].ability.id in [AbilityId.HARVEST_RETURN]:
- await self.do(w.move(g))
- await self.do(w.return_resource(queue=True))
+ actions.push(w.move(g))
+ actions.push(w.return_resource(queue=True))
else:
- await self.do(w.gather(g))
+ actions.push(w.gather(g))
for location, townhall in owned_expansions.items():
actual = townhall.assigned_harvesters
@@ -220,11 +222,13 @@ class BotAI(object):
w = worker_pool.pop()
mf = self.state.mineral_field.closest_to(townhall)
if len(w.orders) == 1 and w.orders[0].ability.id in [AbilityId.HARVEST_RETURN]:
- await self.do(w.move(townhall))
- await self.do(w.return_resource(queue=True))
- await self.do(w.gather(mf, queue=True))
+ actions.push(w.move(townhall))
+ actions.push(w.return_resource(queue=True))
+ actions.push(w.gather(mf, queue=True))
else:
- await self.do(w.gather(mf))
+ actions.push(w.gather(mf))
+
+ await self.do_actions(actions)
@property
def owned_expansions(self):
