-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathcontroller.py
More file actions
37 lines (29 loc) · 1.21 KB
/
controller.py
File metadata and controls
37 lines (29 loc) · 1.21 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
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