5
5
from sets import Set
6
6
except ImportError :
7
7
Set = set
8
- from PIL .Image import open as PIL_open
9
- from PIL .Image import ANTIALIAS
8
+ try :
9
+ # required for CreepTracker, but CreepTracker is optional
10
+ from PIL .Image import open as PIL_open
11
+ from PIL .Image import ANTIALIAS
12
+ except ImportError :
13
+ pass
10
14
try :
11
15
from StringIO import StringIO
12
16
except ImportError :
@@ -43,7 +47,7 @@ def handleUnitDiedEvent(self, event, replay):
43
47
except Exception as e :
44
48
print ("Whoa! {}" .format (e ))
45
49
pass
46
-
50
+
47
51
48
52
def handleUnitInitEvent (self ,event ,replay ):
49
53
try :
@@ -53,7 +57,7 @@ def handleUnitInitEvent(self,event,replay):
53
57
except Exception as e :
54
58
print ("Whoa! {}" .format (e ))
55
59
pass
56
-
60
+
57
61
def handleUnitBornEvent (self ,event ,replay ):
58
62
try :
59
63
if event .unit_type_name == "Hatchery" :
@@ -81,14 +85,14 @@ def handleEndGame(self, event, replay):
81
85
pass
82
86
83
87
84
- ## The class used to used to calculate the creep spread
88
+ ## The class used to used to calculate the creep spread
85
89
class creep_tracker ():
86
90
def __init__ (self ,replay ):
87
91
#if the debug option is selected, minimaps will be printed to a file
88
- ##and a stringIO containing the minimap image will be saved for
89
- ##every minite in the game and the minimap with creep highlighted
92
+ ##and a stringIO containing the minimap image will be saved for
93
+ ##every minite in the game and the minimap with creep highlighted
90
94
## will be printed out.
91
- self .debug = replay .opt . debug
95
+ self .debug = replay .opt [ ' debug' ]
92
96
##This list contains creep spread area for each player
93
97
self .creep_spread_by_minute = dict ()
94
98
## this list contains a minimap highlighted with creep spread for each player
@@ -125,7 +129,7 @@ def __init__(self,replay):
125
129
# resize height to MAPHEIGHT, and compute new width that
126
130
# would preserve aspect ratio
127
131
self .map_width = int (cropsize [0 ] * (float (self .map_height ) / cropsize [1 ]))
128
- self .mapSize = self .map_height * self .map_width
132
+ self .mapSize = self .map_height * self .map_width
129
133
130
134
## the following parameters are only needed if minimaps have to be printed
131
135
# minimapSize = ( self.map_width,int(self.map_height) )
@@ -138,10 +142,10 @@ def __init__(self,replay):
138
142
imageCenter = [(self .map_width / 2 ), self .map_height / 2 ]
139
143
# this is the scaling factor to go from the SC2 coordinate
140
144
# system to pixel coordinates
141
- self .image_scale = float (self .map_height ) / cropsize [1 ]
145
+ self .image_scale = float (self .map_height ) / cropsize [1 ]
142
146
self .transX = imageCenter [0 ] + self .image_scale * (mapCenter [0 ])
143
147
self .transY = imageCenter [1 ] + self .image_scale * (mapCenter [1 ])
144
-
148
+
145
149
def radius_to_map_positions (self ,radius ):
146
150
## this function converts all radius into map coordinates
147
151
## centred around the origin that the creep can exist
@@ -180,7 +184,7 @@ def add_to_list(self,player_id,unit_id,unit_location,unit_type,event_time):
180
184
def remove_from_list (self ,unit_id ,time_frame ):
181
185
## This function searches is given a unit ID for every unit who died
182
186
## the unit id will be searched in cgu_gen_units for matches
183
- ## if there are any, that unit will be removed from active CGUs
187
+ ## if there are any, that unit will be removed from active CGUs
184
188
## and appended as a new time frame
185
189
for player_id in self .creep_gen_units :
186
190
length_cgu_list = len (self .creep_gen_units [player_id ])
@@ -194,7 +198,7 @@ def remove_from_list(self,unit_id,time_frame):
194
198
self .creep_gen_units_times [player_id ].append (time_frame )
195
199
196
200
def cgu_gen_times_to_chunks (self ,cgu_time_list ):
197
- ## this function returns the index and value of every cgu time
201
+ ## this function returns the index and value of every cgu time
198
202
maximum_cgu_time = max (cgu_time_list )
199
203
for i in range (0 , maximum_cgu_time ):
200
204
a = list (filter (lambda x_y : x_y [1 ]// 60 == i , enumerate (cgu_time_list )))
@@ -211,7 +215,7 @@ def cgu_in_min_to_cgu_units(self,player_id,cgu_in_minutes):
211
215
cgu_units .append (self .creep_gen_units [player_id ][index ])
212
216
cgu_max_in_minute = max (cgu_units ,key = len )
213
217
yield cgu_max_in_minute
214
-
218
+
215
219
def reduce_cgu_per_minute (self ,player_id ):
216
220
#the creep_gen_units_lists contains every single time frame
217
221
#where a CGU is added,
@@ -224,7 +228,7 @@ def reduce_cgu_per_minute(self,player_id):
224
228
self .creep_gen_units_times [player_id ] = list (minutes )
225
229
226
230
def get_creep_spread_area (self ,player_id ):
227
- ## iterates through all cgus and and calculate the area
231
+ ## iterates through all cgus and and calculate the area
228
232
for index ,cgu_per_player in enumerate (self .creep_gen_units [player_id ]):
229
233
# convert cgu list into centre of circles and radius
230
234
cgu_radius = map (lambda x : (x [1 ], self .unit_name_to_radius [x [2 ]]),\
@@ -234,7 +238,7 @@ def get_creep_spread_area(self,player_id):
234
238
creep_area_positions = self .cgu_radius_to_map_positions (cgu_radius ,self .radius_to_coordinates )
235
239
cgu_event_time = self .creep_gen_units_times [player_id ][index ]
236
240
cgu_event_time_str = str (int (cgu_event_time // 60 ))+ ":" + str (cgu_event_time % 60 )
237
- if self .debug :
241
+ if self .debug :
238
242
self .print_image (creep_area_positions ,player_id ,cgu_event_time_str )
239
243
creep_area = len (creep_area_positions )
240
244
self .creep_spread_by_minute [player_id ][cgu_event_time ]= \
@@ -251,7 +255,7 @@ def cgu_radius_to_map_positions(self,cgu_radius,radius_to_coordinates):
251
255
point = cgu [0 ]
252
256
radius = cgu [1 ]
253
257
## subtract all radius_to_coordinates with centre of
254
- ## cgu radius to change centre of circle
258
+ ## cgu radius to change centre of circle
255
259
cgu_map_position = map ( lambda x :(x [0 ]+ point [0 ],x [1 ]+ point [1 ])\
256
260
,self .radius_to_coordinates [radius ])
257
261
total_points_on_map = total_points_on_map | Set (cgu_map_position )
0 commit comments