-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathwatch_replay.py
More file actions
43 lines (35 loc) · 1.53 KB
/
watch_replay.py
File metadata and controls
43 lines (35 loc) · 1.53 KB
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
import platform
from pathlib import Path
from loguru import logger
from sc2.main import run_replay
from sc2.observer_ai import ObserverAI
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() # pyrefly: ignore
# 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
elif Path(replay_name).is_absolute():
replay_path = Path(replay_name)
else:
# Convert relative path to absolute path, assuming this replay is in this folder
folder_path = Path(__file__).parent
replay_path = folder_path / replay_name
assert replay_path.is_file(), (
"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=str(replay_path))