forked from BurnySc2/python-sc2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
48 lines (37 loc) · 1.66 KB
/
controller.py
File metadata and controls
48 lines (37 loc) · 1.66 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
44
45
46
47
48
import logging
from s2clientprotocol import sc2api_pb2 as sc_pb
from .player import Computer
from .protocol import Protocol
logger = logging.getLogger(__name__)
class Controller(Protocol):
def __init__(self, ws, process):
super().__init__(ws)
self.__process = process
@property
def running(self):
return self.__process._process is not None
async def create_game(self, game_map, players, realtime, random_seed=None):
assert isinstance(realtime, bool)
req = sc_pb.RequestCreateGame(local_map=sc_pb.LocalMap(map_path=str(game_map.relative_path)), realtime=realtime)
if random_seed is not None:
req.random_seed = random_seed
for player in players:
p = req.player_setup.add()
p.type = player.type.value
if isinstance(player, Computer):
p.race = player.race.value
p.difficulty = player.difficulty.value
p.ai_build = player.ai_build.value
logger.info("Creating new game")
logger.info(f"Map: {game_map.name}")
logger.info(f"Players: {', '.join(str(p) for p in players)}")
result = await self._execute(create_game=req)
return result
async def start_replay(self, replay_path, realtime, observed_id=0): # Added
ifopts = sc_pb.InterfaceOptions(
raw=True, score=True, show_cloaked=True, raw_affects_selection=False, raw_crop_to_playable_area=False
)
req = sc_pb.RequestStartReplay(
replay_path=replay_path, observed_player_id=observed_id, options=ifopts)
result = await self._execute(start_replay=req)
return result