-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify.py
More file actions
executable file
·58 lines (43 loc) · 1.54 KB
/
verify.py
File metadata and controls
executable file
·58 lines (43 loc) · 1.54 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
#!/usr/bin/env python
import copy
import os
import sys
import uuid
from multiprocessing import Pool
from subprocess import PIPE, Popen
seeds = ('2944993328', '2949872884', '3218539606', '3552599139', '3693640182', '1410710215')
map_sizes = tuple(str(x) for x in range(20, 55, 5))
def main(argv):
print('HAL vs v{}'.format(argv[0]))
with Pool(6) as p:
for seed in seeds:
print('Seed {}'.format(seed))
cmds = []
for size in map_sizes:
cmds.append((
['./halite',
'-s', seed,
'-d', '{} {}'.format(size, size),
'python HAL.py',
'python v{}.py'.format(argv[0])],
size))
print('\n'.join([_ for _ in p.starmap(run_game, cmds)]))
return 0
def run_game(cmd, size):
p = Popen(cmd, stdout=PIPE, stderr=PIPE, cwd=os.curdir)
stdout, stderr = p.communicate()
if stderr:
return stderr
return parse_output(stdout, size)
def parse_output(output, map_size):
if b'Player #1, HAL, came in rank #1' in output:
return '{}x{}: \u2713'.format(map_size, map_size)
elif b'Player #2, HAL, came in rank #1' in output:
return '{}x{}: \u2718'.format(map_size, map_size)
else:
file_hex = uuid.uuid4().hex
with open('{}.out'.format(file_hex), 'w') as f:
f.write(str(output))
'Invalid output. Written to {}.out'.format(file_hex)
if __name__ == '__main__':
sys.exit(main(copy.deepcopy(sys.argv[1:])))