-
Notifications
You must be signed in to change notification settings - Fork 5
/
run_all_maps.py
47 lines (39 loc) · 1.13 KB
/
run_all_maps.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
import subprocess
import re
import csv
# file to write to for csv
myfile = open('match_results.csv', 'wb')
wr = csv.writer(myfile, delimiter=',', quoting=csv.QUOTE_ALL)
games = 0
wins = {}
p = subprocess.Popen(['ant', 'file'], shell=True, stdout=subprocess.PIPE)
current_map = 0
for line in iter(p.stdout.readline, ''):
# check if somebody won
m1 = re.search("[A-Za-z0-9]+ vs\. [A-Za-z0-9]+ on ([A-Za-z0-9]+)", line)
if m1:
# a game has started
current_map = m1.groups()[0]
m2 = re.search("([A-Za-z0-9]+) \([A|B]\) wins", line)
if m2:
# somebody won
games += 1
winner = m2.groups()[0]
if winner in wins:
wins[winner] += 1
else:
wins[winner] = 1
print 'Games completed: %d, map: %s, winner: %s' % (games, current_map, winner)
# write to csv
wr.writerow([games, current_map, winner])
myfile.flush()
print wins
print ''
print ''
print '----------'
print ''
print 'Wins (out of %s games):' % games
for winner in wins:
print winner + ': ' + str(wins[winner])
p.stdout.close()
myfile.close()