-
Notifications
You must be signed in to change notification settings - Fork 4
/
battle.py
80 lines (70 loc) · 2.22 KB
/
battle.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
68
69
70
71
72
73
74
75
76
77
78
79
80
import argparse
from battlePy.player import loadPlayerModule
from battlePy.series import Series
def unpackPlayerArg(packedArg):
"""Take a string that may or may not contain multiple space-separated tokens.
return the first token as the expected player module name, the rest as a single string
for treatment as args to the instantiated class.
"""
unpacked = packedArg.split(" ", 1)
if not unpacked:
raise ValueError("Unexpected agent arg provided: %s" % packedArg)
if len(unpacked) == 1:
# no additional args
return unpacked[0], None
else:
return unpacked[0], unpacked[1]
def main():
parser = argparse.ArgumentParser(description="BattlePyAI")
parser.add_argument(
"--p1",
action="store",
default='samples.random_player',
help="module name of agent for player 1 (eg, samples.random). See code for passing args.",
metavar="<dir.file>",
)
parser.add_argument(
"--p2",
action="store",
default='samples.rando_shotdrissian',
help="module name w agent code for player 1 (eg, samples.random)",
metavar="<dir.file>",
)
parser.add_argument(
"--vis",
action="store_true",
default=False,
help="Turn on game visualization(slow)",
)
parser.add_argument(
"--games",
type=int,
action="store",
default=1000,
help="Number of games to play.",
metavar="N",
)
parser.add_argument(
"--debug", action="store_true", default=False, help="Enable debug behavior."
)
args = parser.parse_args()
p1module, p1arg = unpackPlayerArg(args.p1)
p2module, p2arg = unpackPlayerArg(args.p2)
p1 = loadPlayerModule(p1module)
p2 = loadPlayerModule(p2module)
# each player is handed an argstring if one was found on the CLI.
# Thee class can decide what to do with it.
series = Series(
p1(argstring=p1arg),
p2(argstring=p2arg),
numberOfGames=args.games,
showVisualization=args.vis,
debug=args.debug,
visualizationInterval=0.01,
)
series.start()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass