-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.py
67 lines (56 loc) · 2.09 KB
/
cli.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
66
67
import argparse
import agents
def list_agents():
for a in agents.__all__:
print(a)
def _get_args():
"""Parse arguments from the command line and return them."""
parser = argparse.ArgumentParser(description=__doc__)
# add the argument for the Super Mario Bros environment to run
parser.add_argument('--rom', '-r',
type=str,
help='The path to the ROM to play.'
)
# add the argument for the mode of execution as either human or random
parser.add_argument('--mode', '-m',
type=str,
default='human',
choices=['human', 'random'],
help='The execution mode for the emulation.',
)
# add the argument for the number of steps to take in random mode
parser.add_argument('--steps', '-s',
type=int,
default=500,
help='The number of random steps to take.',
)
# name of agent
parser.add_argument('--agentName', '-a',
type=str,
default='RandomAgent',
help='The name of the agent to be used'
)
# agent configuration file path
parser.add_argument('--agentConfig', '-ac',
type=str,
help='The location of an agent configuration file'
)
# list agents
parser.add_argument('--agentList', '-al',
action='store_true',
help='Print all agent names'
)
return parser.parse_args()
def main():
args = _get_args()
if args.agentList:
list_agents()
return
if args.agentName:
agentName = args.agentName
if agentName in agents.__all__:
mod = getattr(agents, agentName)
AC = getattr(mod, agentName)
AC(args)
else:
raise Exception("Invalid agent name: " + agentName)