forked from BurnySc2/python-sc2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch_replay.py
46 lines (38 loc) · 1.59 KB
/
watch_replay.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
import os
import logging
import platform
from pathlib import Path
from sc2.observer_ai import ObserverAI
from sc2 import run_replay
logger = logging.getLogger(__name__)
class ObserverBot(ObserverAI):
"""
A replay bot that can run replays.
Check sc2/observer_ai.py for more available functions
"""
async def on_start(self):
print("Replay on_start() was called")
async def on_step(self, iteration: int):
print(f"Replay iteration: {iteration}")
if __name__ == "__main__":
my_observer_ai = ObserverBot()
# Enter replay name here
# The replay should be either in this folder and you can give it a relative path, or change it to the absolute path
replay_name = "WorkerRush.SC2Replay"
if platform.system() == "Linux":
home_replay_folder = Path.home() / "Documents" / "StarCraft II" / "Replays"
replay_path = home_replay_folder / replay_name
if not replay_path.is_file():
logger.warning(f"You are on linux, please put the replay in directory {home_replay_folder}")
raise FileNotFoundError
replay_path = str(replay_path)
elif os.path.isabs(replay_name):
replay_path = replay_name
else:
# Convert relative path to absolute path, assuming this replay is in this folder
folder_path = os.path.dirname(__file__)
replay_path = os.path.join(folder_path, replay_name)
assert os.path.isfile(
replay_path
), f"Run worker_rush.py in the same folder first to generate a replay. Then run watch_replay.py again."
run_replay(my_observer_ai, replay_path=replay_path)