5
5
import time
6
6
from optparse import OptionParser
7
7
8
- from engine import run_game
9
8
from ants import Ants
10
9
10
+ # get engine from worker dir
11
+ sys .path .append ("../worker" )
12
+ from engine import run_game
13
+
11
14
def main (argv ):
12
15
usage = "Usage: %prog [options] map bot1 bot2\n \n You must specify a map file."
13
16
parser = OptionParser (usage = usage )
@@ -26,6 +29,9 @@ def main(argv):
26
29
# it will also contain the bot input/output logs, if requested
27
30
parser .add_option ("-o" , "--output_dir" , dest = "output_dir" ,
28
31
help = "Directory to dump replay files to." )
32
+ parser .add_option ("-j" , "--output_json" , dest = "output_json" ,
33
+ action = "store_true" , default = False ,
34
+ help = "Return json result from engine." )
29
35
parser .add_option ("-I" , "--log_input" , dest = "log_input" ,
30
36
action = "store_true" , default = False ,
31
37
help = "Log input streams sent to bots" )
@@ -87,6 +93,7 @@ def main(argv):
87
93
"map_file" : opts .map ,
88
94
"turns" : opts .turns ,
89
95
"output_dir" : opts .output_dir ,
96
+ "output_json" : opts .output_json ,
90
97
"log_input" : opts .log_input ,
91
98
"log_output" : opts .log_output ,
92
99
"serial" : opts .serial ,
@@ -102,7 +109,9 @@ def main(argv):
102
109
(game .num_players , len (bots )))
103
110
break
104
111
print ('playgame round %s' % round )
105
- run_game (game , bots , engine_options , round )
112
+ result = run_game (game , bots , engine_options , round )
113
+ if opts .output_json :
114
+ print result
106
115
107
116
except Exception :
108
117
traceback .print_exc ()
0 commit comments