-
Notifications
You must be signed in to change notification settings - Fork 1
/
console.py
65 lines (51 loc) · 1.51 KB
/
console.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python2
"""
Optiness command line UI
Darren Alton
"""
import sys, getopt
# Optiness driver, which handles game and brain modules
import common
# default game and solver to use
game_mod_name, brain_mod_name = ('maze', 'sagan')
game_args, brain_args = ({}, {})
scale = 1 # we may want to make the display output bigger
output = 'output/last_run.pickle' # default value for the output pickle
def usage():
return """
todo: help. for now, here's a list of game and brain modules:
{}
{}
""".format( list(common.util.ListGames()),
list(common.util.ListBrains()) )
if __name__ == "__main__":
# parse command line arguments
try:
opts, args = getopt.getopt(sys.argv[1:], "hg:b:s:o:", ["help", "game=", "brain=", "scale=", "output="])
for o,a in opts:
if o in ('-h', '--help'):
print usage()
sys.exit(0)
elif o in ('-g', '--game'):
subargs = a.split('@')
game_mod_name = subargs[0]
for i in subargs[1:]:
key,val = i.split(':')
game_args[key] = val
elif o in ('-b', '--brain'):
subargs = a.split('@')
brain_mod_name = subargs[0]
for i in subargs[1:]:
key,val = i.split(':')
brain_args[key] = val
elif o in ('-s', '--scale'):
scale = int(a)
elif o in ('-o', '--output'):
output = a
except getopt.GetoptError, err:
print str(err), usage()
sys.exit(2)
# run optiness with parsed arguments
driver = common.Driver(game_mod_name, brain_mod_name, game_args, brain_args, scale)
driver.Run()
driver.Save(output)