-
Notifications
You must be signed in to change notification settings - Fork 182
/
Copy pathdistributed_workers.py
35 lines (28 loc) · 1.23 KB
/
distributed_workers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import sc2
from sc2 import run_game, maps, Race, Difficulty
from sc2.player import Bot, Computer
from sc2.constants import *
class TerranBot(sc2.BotAI):
async def on_step(self, iteration):
await self.distribute_workers()
await self.build_supply()
await self.build_workers()
await self.expand()
async def build_workers(self):
for cc in self.units(UnitTypeId.COMMANDCENTER).ready.noqueue:
if self.can_afford(UnitTypeId.SCV):
await self.do(cc.train(UnitTypeId.SCV))
async def expand(self):
if self.units(UnitTypeId.COMMANDCENTER).amount < 3 and self.can_afford(UnitTypeId.COMMANDCENTER):
await self.expand_now()
async def build_supply(self):
ccs = self.units(UnitTypeId.COMMANDCENTER).ready
if ccs.exists:
cc = ccs.first
if self.supply_left < 4 and not self.already_pending(UnitTypeId.SUPPLYDEPOT):
if self.can_afford(UnitTypeId.SUPPLYDEPOT):
await self.build(UnitTypeId.SUPPLYDEPOT, near=cc.position.towards(self.game_info.map_center, 5))
run_game(maps.get("Abyssal Reef LE"), [
Bot(Race.Terran, TerranBot()),
Computer(Race.Protoss, Difficulty.Medium)
], realtime=False)