-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_matches.py
141 lines (116 loc) · 5.37 KB
/
run_matches.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
from itertools import product
import re
import subprocess
emojiMode = True
emojiMap = {
'Won': ':heavy_check_mark:',
'Lost': ':x:',
'Tied': ':grimacing:',
'N/A': ':heavy_minus_sign:',
'Error': ':heavy_exclamation_mark:'
}
errors = []
currentBot = 'finalBot'
bots = ['beforeEarlierAnchors']
#bots = ['manaOnly', 'sprintTesting1', 'sprintTesting2', 'sprintTesting3', 'sprintTesting5', 'sprintTesting8']
botsSet = set(bots)
#maps = ['PairedProgramming', 'Rewind', 'Turtle']
#maps = ['Rewind', 'Heart', 'LightWork', 'TreasureMap', 'HotAirBalloon', 'Movepls', 'Grievance', 'IslandHopping']
#maps = ['DefaultMap', 'AllElements', 'SmallElements', 'maptestsmall']
#maps = ['DefaultMap', 'AllElements', 'SmallElements', 'maptestsmall', 'generated_captain_america', 'generated_chalice', 'generated_charge', 'generated_chessboard', 'generated_cobra', 'generated_collaboration', 'generated_colosseum', 'generated_deer', 'generated_defenseless']
# sprint 1 maps
#maps = ['ArtistRendition', 'BatSignal', 'BowAndArrow', 'Cat', 'Clown', 'Diagonal', 'Eyelands', 'Frog', 'Grievance', 'Hah', 'Jail', 'KingdomRush', 'Minefield', 'Movepls', 'Orbit', 'Pathfind', 'Pit', 'Pizza', 'Quiet', 'Rectangle', 'Scatter', 'Sun', 'Tacocat']
#maps = ['Eyelands']
# sprint 2 maps
#maps = ['BattleSuns', 'Checkmate2', 'Cornucopia', 'Crossword', 'Cube', 'Divergence', 'FourNations', 'HideAndSeek', 'Lantern', 'Lines', 'Maze', 'Pakbot', 'Piglets', 'Risk', 'Sine', 'Snowflake', 'SomethingFishy', 'Spin', 'Spiral', 'Squares', 'Star', 'Sus', 'SweetDreams', 'TicTacToe', 'USA']
# us qual maps
#maps = ['AbsoluteW', 'Buggy', 'Cave', 'Cee', 'Heart', 'HotAirBalloon', 'IslandHoppingTwo', 'LightWork', 'MassiveL', 'Potions', 'Rainbow', 'Resign', 'Sneaky', 'Target', 'Tightrope']
#maps = ['ReverseFunnel', 'Swooshy']
#maps = ['Quiet', 'Spin', 'Diagonal']
maps = ['maptestsmall']
mapsSet = set(maps)
matches = set(product(bots, maps))
numWinsMapping = {
0: 'Lost',
1: 'Tied',
2: 'Won',
}
def retrieveGameLength(output):
startIndex = output.find('wins (round ')
if startIndex == -1:
return -1
endIndex = output.find(')', startIndex)
if endIndex == -1:
return -1
return output[startIndex + len('wins(round ') + 1:endIndex]
def run_match(bot, map):
print("Running {} vs {} on {}".format(currentBot, bot, map))
try:
outputA = str(subprocess.check_output(['./gradlew', 'run', '-PteamA=' + currentBot, '-PteamB=' + bot, '-Pmaps=' + map]))
outputB = str(subprocess.check_output(['./gradlew', 'run', '-PteamA=' + bot, '-PteamB=' + currentBot, '-Pmaps=' + map]))
# for local windows testing
#outputA = str(subprocess.check_output(['gradlew', 'run', '-PteamA=' + currentBot, '-PteamB=' + bot, '-Pmaps=' + map], shell=True))
#outputB = str(subprocess.check_output(['gradlew', 'run', '-PteamA=' + bot, '-PteamB=' + currentBot, '-Pmaps=' + map], shell=True))
except subprocess.CalledProcessError as exc:
print("Status: FAIL", exc.returncode, exc.output)
return 'Error'
else:
winAString = '{} (A) wins'.format(currentBot)
winBString = '{} (B) wins'.format(currentBot)
loseAString = '{} (B) wins'.format(bot)
loseBString = '{} (A) wins'.format(bot)
resignedString = 'resigned'
numWins = 0
gameLengthA = retrieveGameLength(outputA)
gameAResigned = resignedString in outputA
gameLengthB = retrieveGameLength(outputB)
gameBResigned = resignedString in outputB
flagRegex = "FLAG{[^{}]*}"
gameAFlags = list(set(re.findall(flagRegex, outputA)))
gameBFlags = list(set(re.findall(flagRegex, outputB)))
gameAFlags = ", ".join([s[5:-1] for s in gameAFlags])
gameBFlags = ", ".join([s[5:-1] for s in gameBFlags])
if len(gameAFlags) > 0:
gameAFlags = "{{{}}}".format(gameAFlags)
if len(gameBFlags) > 0:
gameBFlags = "{{{}}}".format(gameBFlags)
gameAInfo = gameLengthA + ('*' if gameAResigned else '') + gameAFlags
gameBInfo = gameLengthB + ('*' if gameBResigned else '') + gameBFlags
if winAString in outputA:
numWins += 1
else:
if not loseAString in outputA:
return 'Error'
if winBString in outputB:
numWins += 1
else:
if not loseBString in outputB:
return 'Error'
return numWinsMapping[numWins] + ' (' + ', '.join([gameAInfo, gameBInfo]) + ')'
results = {}
# Run matches
for bot, map in matches:
# Verify match is valid
if not bot in botsSet or not map in mapsSet:
errors.append('Unable to parse bot={}, map={}'.format(bot, map))
# run run_match.py
results[(bot, map)] = run_match(bot, map)
# Construct table
table = [[results.get((bot, map), 'N/A') for bot in bots] for map in maps]
def replaceWithDictionary(s, mapping):
for a, b in mapping.items():
s = s.replace(a, b)
return s
if emojiMode:
table = [[replaceWithDictionary(item, emojiMap) for item in row] for row in table]
# Write to file
with open('matches-summary.txt', 'w') as f:
table = [[''] + bots, [':---:' for i in range(len(bots) + 1)]] + [[map] + row for map, row in zip(maps, table)]
for line in table:
f.write('| ')
f.write(' | '.join(line))
f.write(' |')
f.write('\n')
f.write('\n')
for error in errors:
f.write(error)