forked from BurnySc2/python-sc2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_external.py
42 lines (29 loc) · 1.23 KB
/
run_external.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
import argparse
import sys
import asyncio
import sc2
from sc2 import Race
from sc2.player import Bot
from zerg.zerg_rush import ZergRushBot
""" DEPRECATED - use external_bot.py or competitive/run.py instead """
def main(is_host, pc):
if args.portconfig:
portconfig = sc2.portconfig.Portconfig.from_json(pc)
else:
assert args.host, "Must be host if portconfig is not given"
portconfig = sc2.portconfig.Portconfig()
print(portconfig.as_json)
player_config = [Bot(Race.Zerg, None), Bot(Race.Zerg, None)]
player_config[0 if is_host else 1].ai = ZergRushBot()
if is_host:
g = sc2.main._host_game(sc2.maps.get("Abyssal Reef LE"), player_config, realtime=False, portconfig=portconfig)
else:
g = sc2.main._join_game(player_config, realtime=False, portconfig=portconfig)
result = asyncio.get_event_loop().run_until_complete(g)
print(result)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Run an external game")
parser.add_argument("--host", action="store_true", help="host a game")
parser.add_argument("portconfig", type=str, nargs="?", help="port configuration as json")
args = parser.parse_args()
main(args.host, args.portconfig)