forked from gwillem/rgkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
executable file
·62 lines (49 loc) · 1.82 KB
/
Copy pathrun.py
File metadata and controls
executable file
·62 lines (49 loc) · 1.82 KB
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
#!/usr/bin/env python2
import os
import ast
import argparse
###
import game
import render
from settings import settings
parser = argparse.ArgumentParser(description="Robot game execution script.")
parser.add_argument("usercode1",
help="File containing first robot class definition.")
parser.add_argument("usercode2",
help="File containing second robot class definition.")
parser.add_argument("-m", "--map", help="User-specified map file.",
default='maps/default.py')
parser.add_argument("-H", "--headless", action="store_true",
default=False,
help="Disable rendering game output.")
parser.add_argument("-c", "--count", type=int,
default=1,
help="Game count, default: 1")
def make_player(fname):
with open(fname) as player_code:
return game.Player(player_code.read())
def play(players, print_info=True):
g = game.Game(*players, record_turns=True)
for i in xrange(settings.max_turns):
if print_info:
print (' running turn %d ' % (g.turns + 1)).center(70, '-')
g.run_turn()
if print_info:
render.Render(g, game.settings)
print g.history
return g.get_scores()
if __name__ == '__main__':
args = parser.parse_args()
map_name = os.path.join(args.map)
map_data = ast.literal_eval(open(map_name).read())
game.init_settings(map_data)
players = [make_player(args.usercode1),
make_player(args.usercode2)]
scores = []
for i in xrange(args.count):
scores.append(play(players, not args.headless))
print scores[-1]
if args.count > 1:
p1won = sum(p1 > p2 for p1, p2 in scores)
p2won = sum(p2 > p1 for p1, p2 in scores)
print [p1won, p2won, args.count - p1won - p2won]