From 14b3ff33c63802a3aa5fc43371e9eae997c890c3 Mon Sep 17 00:00:00 2001 From: Islam Elnabarawy Date: Sun, 23 Jun 2019 16:24:26 -0500 Subject: [PATCH] Update host_game_aiter to accept rgb_render_config and random_seed args --- sc2/main.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sc2/main.py b/sc2/main.py index dbb679107..574a6a992 100644 --- a/sc2/main.py +++ b/sc2/main.py @@ -243,19 +243,20 @@ async def _host_game(map_settings, players, realtime, portconfig=None, save_repl return result -async def _host_game_aiter(map_settings, players, realtime, portconfig=None, save_replay_as=None, step_time_limit=None, game_time_limit=None): +async def _host_game_aiter(map_settings, players, realtime, portconfig=None, save_replay_as=None, step_time_limit=None, + game_time_limit=None, rgb_render_config=None, random_seed=None): assert players, "Can't create a game without players" assert any(isinstance(p, (Human, Bot)) for p in players) - async with SC2Process() as server: + async with SC2Process(render=rgb_render_config is not None) as server: while True: await server.ping() - client = await _setup_host_game(server, map_settings, players, realtime) + client = await _setup_host_game(server, map_settings, players, realtime, random_seed) try: - result = await _play_game(players[0], client, realtime, portconfig, step_time_limit, game_time_limit) + result = await _play_game(players[0], client, realtime, portconfig, step_time_limit, game_time_limit, rgb_render_config) if save_replay_as is not None: await client.save_replay(save_replay_as) @@ -308,3 +309,9 @@ def run_game(map_settings, players, **kwargs): _host_game(map_settings, players, **kwargs) ) return result + +def run_game_iter(*args, **kwargs): + game = _host_game_aiter(*args, **kwargs) + new_playerconfig = None + while True: + new_playerconfig = yield asyncio.get_event_loop().run_until_complete(game.asend(new_playerconfig))