forked from Dentosal/python-sc2
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproxy_rax.py
More file actions
63 lines (51 loc) · 2.36 KB
/
proxy_rax.py
File metadata and controls
63 lines (51 loc) · 2.36 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import random
import sc2
from sc2 import Race, Difficulty
from sc2.constants import *
from sc2.player import Bot, Computer
from sc2.helpers import ControlGroup
class ProxyRaxBot(sc2.BotAI):
def __init__(self):
self.attack_groups = set()
async def on_step(self, iteration):
cc = self.units(COMMANDCENTER)
if not cc.exists:
target = self.known_enemy_structures.random_or(self.enemy_start_locations[0]).position
for unit in self.workers | self.units(MARINE):
await self.do(unit.attack(target))
return
else:
cc = cc.first
if self.units(MARINE).idle.amount > 15 and iteration % 50 == 1:
cg = ControlGroup(self.units(MARINE).idle)
self.attack_groups.add(cg)
if self.can_afford(SCV) and self.workers.amount < 16 and cc.noqueue:
await self.do(cc.train(SCV))
elif self.supply_left < (2 if self.units(BARRACKS).amount < 3 else 4):
if self.can_afford(SUPPLYDEPOT) and self.already_pending(SUPPLYDEPOT) < 2:
await self.build(SUPPLYDEPOT, near=cc.position.towards(self.game_info.map_center, 5))
elif self.units(BARRACKS).amount < 3 or (self.minerals > 400 and self.units(BARRACKS).amount < 5):
if self.can_afford(BARRACKS):
p = self.game_info.map_center.towards(self.enemy_start_locations[0], 25)
await self.build(BARRACKS, near=p)
for rax in self.units(BARRACKS).ready.noqueue:
if not self.can_afford(MARINE):
break
await self.do(rax.train(MARINE))
for scv in self.units(SCV).idle:
await self.do(scv.gather(self.state.mineral_field.closest_to(cc)))
for ac in list(self.attack_groups):
alive_units = ac.select_units(self.units)
if alive_units.exists and alive_units.idle.exists:
target = self.known_enemy_structures.random_or(self.enemy_start_locations[0]).position
for marine in ac.select_units(self.units):
await self.do(marine.attack(target))
else:
self.attack_groups.remove(ac)
def main():
sc2.run_game(sc2.maps.get("Sequencer LE"), [
Bot(Race.Terran, ProxyRaxBot()),
Computer(Race.Zerg, Difficulty.Hard)
], realtime=False)
if __name__ == '__main__':
main()