-
Notifications
You must be signed in to change notification settings - Fork 0
/
exampleai.py
39 lines (30 loc) · 1.33 KB
/
exampleai.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
36
37
38
39
from pybw_swig import * # import all constants and classes
class ExampleAI(object):
def onConnect(self):
self.game = getGame()
def onMatchStart(self):
if self.game.isReplay:
return
self.minerals = list(self.game.minerals)
self.player = self.game.self
self.race = self.player.race
self.main_centers = [u for u in self.player.units if u.type == self.race.center]
if self.main_centers:
self.main_center = self.main_centers[0]
self.mineral_queue = []
for mineral in self.minerals:
distance_to_center = mineral.position.getDistance( self.main_center.position )
self.mineral_queue.append(( distance_to_center, mineral ))
self.mineral_queue.sort()
else:
self.main_center = None
def onMatchFrame(self):
if self.game.isReplay:
return
if self.main_center:
self.main_center.train( self.race.worker )
inactive_workers = [u for u in self.game.self.units if u.type.isWorker and u.order == PlayerGuard]
for worker in inactive_workers:
mineral = self.mineral_queue.pop(0)
worker.rightClick( mineral[1] )
self.mineral_queue.append( mineral )