-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrunner.py
204 lines (170 loc) · 4.82 KB
/
runner.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import itertools
import os
import random
import subprocess
import platform
import argparse
from typing import List, Optional
STOP_FILE: str = "runner-stop.txt"
maps = [
# AiArena season 2
"DeathAuraLE",
"EternalEmpireLE",
"EverDreamLE",
"GoldenWallLE",
"IceandChromeLE",
"PillarsofgoldLE",
"SubmarineLE",
]
# region opponents
zerg_opponents = [
"randomzerg",
"ai.zerg.vision",
"ai.zerg.insane",
]
terran_opponents = [
"randomterran",
"ai.terran.vision",
"ai.terran.insane",
]
protoss_opponents = [
"randomprotoss",
"ai.protoss.vision",
"ai.protoss.insane",
]
other_opponents = [
# "ai",
"meepmeep",
"workerrush",
]
ai_opponents = [
"ai.protoss.vision",
"ai.protoss.insane",
"ai.terran.vision",
"ai.terran.insane",
"ai.zerg.vision",
"ai.zerg.insane",
]
dummies = [
# Protoss
"4gate",
"adept",
"cannonrush",
"disruptor",
"dt",
"robo",
"stalker",
"voidray",
"zealot",
"tempest",
# Zerg
"12pool",
"200roach",
"hydra",
"lings",
"macro",
"mutalisk",
"workerrush",
"lurker",
"roachburrow",
# Terran
"banshee",
"bc",
"bio",
"cyclone",
"marine",
"oldrusty",
"tank",
"terranturtle",
"saferaven",
]
# endregion
def main():
parser = argparse.ArgumentParser(description="Run bot games")
parser.add_argument("-p1", help=f"Bot name.", default="harvester")
parser.add_argument("-p2", help=f"Bot 2 name.")
parser.add_argument(
"-dr", "--dry-run", help="Print commands to execute but do not launch any games.", action="store_true"
)
parser.add_argument("-z", "--zerg", help="Use only Zerg opponents.", action="store_true")
parser.add_argument("-t", "--terran", help="Use only Terran opponents.", action="store_true")
parser.add_argument("-to", "--timeout", help="Timeout in seconds.")
parser.add_argument("-p", "--protoss", help="Use only Protoss opponents.", action="store_true")
parser.add_argument(
"-r", "--rounds", help="Number of rounds to play with each map and opponent combination", type=int, default=1000
)
parser.add_argument("--noai", help="remove in-game AI from the enemy list", action="store_true")
parser.add_argument("--port", help="starting port to use, i.e. 10 would result in ports 10-17 being used to play.")
args = parser.parse_args()
run_games(args)
def run_games(args):
players: List[str] = args.p1.split(",")
dry_run: bool = args.dry_run
if args.timeout:
timeout: Optional[int] = int(args.timeout)
else:
timeout = None
if dry_run:
rounds: int = 1
print(f"Dry run detected. Using {rounds} rounds.")
else:
rounds: int = args.rounds
if args.p2:
if args.p2 == "dummies":
opponents: List[str] = dummies
else:
opponents: List[str] = args.p2.split(",")
else:
opponents: List[str] = get_opponents(args)
all_games = list(itertools.product(players, opponents, maps))
random.shuffle(all_games)
if os.path.isfile(STOP_FILE):
os.remove(STOP_FILE)
for i in range(0, rounds):
for game in all_games:
if os.path.isfile(STOP_FILE):
print(f"Exiting runner... {STOP_FILE} found.")
exit(0)
player1 = game[0]
opponent = game[1]
map_name = game[2]
if platform.system() == "Linux":
cmd = "python3.7"
else:
cmd = "python"
full_command = f"{cmd} run_custom.py --map {map_name} -p1 {player1} -p2 {opponent} --release -raw"
if args.port:
full_command += f" --port {args.port}"
if dry_run:
print(full_command)
else:
print("starting process")
print(full_command)
try:
subprocess.call(full_command.split(" "), timeout=timeout)
except:
print("An timeout exception occurred")
print("process ended")
def get_opponents(args) -> List[str]:
only_zerg: bool = args.zerg
only_terran: bool = args.terran
only_protoss: bool = args.protoss
opponents: List = list()
if only_zerg:
opponents.extend(zerg_opponents)
elif only_terran:
opponents.extend(terran_opponents)
elif only_protoss:
opponents.extend(protoss_opponents)
else:
opponents.extend(zerg_opponents)
opponents.extend(terran_opponents)
opponents.extend(protoss_opponents)
opponents.extend(other_opponents)
if args.noai:
for opponent in ai_opponents:
if opponent in opponents:
opponents.remove(opponent)
return opponents
if __name__ == "__main__":
main()