@@ -87,6 +87,12 @@ def main(argv):
87
87
parser .add_option ('--secure_jail' , dest = 'secure_jail' ,
88
88
action = 'store_true' , default = False ,
89
89
help = 'Use the secure jail for each bot (*nix only)' )
90
+ parser .add_option ('--fill' , dest = 'fill' ,
91
+ action = 'store_true' , default = False ,
92
+ help = 'Fill up extra player starts with last bot specified' )
93
+ parser .add_option ('-p' , '--position' , dest = 'position' ,
94
+ default = 0 , type = 'int' ,
95
+ help = 'Player position for first bot specified' )
90
96
91
97
# ants specific game options
92
98
parser .add_option ("--attack" , dest = "attack" ,
@@ -112,6 +118,8 @@ def main(argv):
112
118
# the log directory will contain
113
119
# the replay or stream file used by the visualizer, if requested
114
120
# the bot input/output/error logs, if requested
121
+ parser .add_option ("-g" , "--game" , dest = "game_id" , default = 0 , type = 'int' ,
122
+ help = "game id to start at when numbering log files" )
115
123
parser .add_option ("-l" , "--log_dir" , dest = "log_dir" , default = None ,
116
124
help = "Directory to dump replay files to." )
117
125
parser .add_option ('-R' , '--log_replay' , dest = 'log_replay' ,
@@ -156,7 +164,7 @@ def main(argv):
156
164
if opts .log_dir :
157
165
prof_file = os .path .join (opts .log_dir , prof_file )
158
166
# cProfile needs to be explitly told about out local and global context
159
- print ("Running profile and outputting to %s" % (prof_file ,), file = sys .stderr )
167
+ print ("Running profile and outputting to {0}" . format (prof_file ,), file = sys .stderr )
160
168
cProfile .runctx ("run_rounds(opts,args)" , globals (), locals (), prof_file )
161
169
else :
162
170
# only use psyco if we are not profiling
@@ -203,6 +211,7 @@ def run_rounds(opts,args):
203
211
random .seed (opts .seed )
204
212
for round in range (opts .rounds ):
205
213
# initialize game
214
+ game_id = round + opts .game_id
206
215
with open (opts .map , 'r' ) as map_file :
207
216
game_options ['map' ] = map_file .read ()
208
217
#opts['map'] = map_file.read()
@@ -223,25 +232,37 @@ def get_cmd_wd(cmd):
223
232
return wd , ' ' .join (new_cmd )
224
233
bots = [get_cmd_wd (arg ) for arg in args ]
225
234
bot_count = len (bots )
235
+ # insure correct number of bots, or fill in remaining positions
226
236
if game .num_players != len (bots ):
227
- print ("Incorrect number of bots for map. Need %s, got %s" %
228
- (game .num_players , len (bots )), file = sys .stderr )
229
- for arg in args :
230
- print ("Bot Cmd: %s" % arg , file = sys .stderr )
231
- break
237
+ if game .num_players > len (bots ) and opts .fill :
238
+ extra = game .num_players - len (bots )
239
+ for _ in range (extra ):
240
+ bots .append (bots [- 1 ])
241
+ else :
242
+ print ("Incorrect number of bots for map. Need {0}, got {1}"
243
+ .format (game .num_players , len (bots )), file = sys .stderr )
244
+ for arg in args :
245
+ print ("Bot Cmd: {0}" .format (arg ), file = sys .stderr )
246
+ break
247
+ # move position of first bot specified
248
+ if opts .position > 0 and opts .position <= len (bots ):
249
+ first_bot = bots [0 ]
250
+ bots = bots [1 :]
251
+ bots .insert (opts .position , first_bot )
252
+
232
253
# initialize file descriptors
233
254
if opts .log_dir and not os .path .exists (opts .log_dir ):
234
255
os .mkdir (opts .log_dir )
235
- if not opts .log_replay and not opts .log_stream :
256
+ if not opts .log_replay and not opts .log_stream and ( opts . log_dir or opts . log_stdout ) :
236
257
opts .log_replay = True
237
258
replay_path = None # used for visualizer launch
238
259
239
260
if opts .log_replay :
240
261
if opts .log_dir :
241
- replay_path = os .path .join (opts .log_dir , '%s .replay' % round )
262
+ replay_path = os .path .join (opts .log_dir , '{0} .replay' . format ( game_id ) )
242
263
engine_options ['replay_log' ] = open (replay_path , 'w' )
243
264
if opts .log_stdout :
244
- if engine_options ['replay_log' ]:
265
+ if 'replay_log' in engine_options and engine_options ['replay_log' ]:
245
266
engine_options ['replay_log' ] = Tee (sys .stdout , engine_options ['replay_log' ])
246
267
else :
247
268
engine_options ['replay_log' ] = sys .stdout
@@ -250,7 +271,7 @@ def get_cmd_wd(cmd):
250
271
251
272
if opts .log_stream :
252
273
if opts .log_dir :
253
- engine_options ['stream_log' ] = open (os .path .join (opts .log_dir , '%s .stream' % round ), 'w' )
274
+ engine_options ['stream_log' ] = open (os .path .join (opts .log_dir , '{0} .stream' . format ( game_id ) ), 'w' )
254
275
if opts .log_stdout :
255
276
if engine_options ['stream_log' ]:
256
277
engine_options ['stream_log' ] = Tee (sys .stdout , engine_options ['stream_log' ])
@@ -260,25 +281,25 @@ def get_cmd_wd(cmd):
260
281
engine_options ['stream_log' ] = None
261
282
262
283
if opts .log_input and opts .log_dir :
263
- engine_options ['input_logs' ] = [open (os .path .join (opts .log_dir , '%s .bot%s .input' % ( round , i )), 'w' )
284
+ engine_options ['input_logs' ] = [open (os .path .join (opts .log_dir , '{0} .bot{1} .input' . format ( game_id , i )), 'w' )
264
285
for i in range (bot_count )]
265
286
else :
266
287
engine_options ['input_logs' ] = None
267
288
if opts .log_output and opts .log_dir :
268
- engine_options ['output_logs' ] = [open (os .path .join (opts .log_dir , '%s .bot%s .output' % ( round , i )), 'w' )
289
+ engine_options ['output_logs' ] = [open (os .path .join (opts .log_dir , '{0} .bot{1} .output' . format ( game_id , i )), 'w' )
269
290
for i in range (bot_count )]
270
291
else :
271
292
engine_options ['output_logs' ] = None
272
293
if opts .log_error and opts .log_dir :
273
294
if opts .log_stderr :
274
295
if opts .log_stdout :
275
- engine_options ['error_logs' ] = [Tee (Comment (sys .stderr ), open (os .path .join (opts .log_dir , '%s .bot%s .error' % ( round , i )), 'w' ))
296
+ engine_options ['error_logs' ] = [Tee (Comment (sys .stderr ), open (os .path .join (opts .log_dir , '{0} .bot{1} .error' . format ( game_id , i )), 'w' ))
276
297
for i in range (bot_count )]
277
298
else :
278
- engine_options ['error_logs' ] = [Tee (sys .stderr , open (os .path .join (opts .log_dir , '%s .bot%s .error' % ( round , i )), 'w' ))
299
+ engine_options ['error_logs' ] = [Tee (sys .stderr , open (os .path .join (opts .log_dir , '{0} .bot{1} .error' . format ( game_id , i )), 'w' ))
279
300
for i in range (bot_count )]
280
301
else :
281
- engine_options ['error_logs' ] = [open (os .path .join (opts .log_dir , '%s .bot%s .error' % ( round , i )), 'w' )
302
+ engine_options ['error_logs' ] = [open (os .path .join (opts .log_dir , '{0} .bot{1} .error' . format ( game_id , i )), 'w' )
282
303
for i in range (bot_count )]
283
304
elif opts .log_stderr :
284
305
if opts .log_stdout :
@@ -294,9 +315,11 @@ def get_cmd_wd(cmd):
294
315
else :
295
316
engine_options ['verbose_log' ] = sys .stdout
296
317
297
- engine_options ['gameid ' ] = round
318
+ engine_options ['game_id ' ] = game_id
298
319
if opts .rounds > 1 :
299
- print ('# playgame round %s' % round )
320
+ print ('# playgame round {0}, game id {1}' .format (round , game_id ))
321
+
322
+ # intercept replay log so we can add player names
300
323
result = run_game (game , bots , engine_options )
301
324
# close file descriptors
302
325
if engine_options ['stream_log' ]:
0 commit comments