import subprocess from games import get_game_json, GAMES_PATH def run_strategy(game_id: int, strategy: str): if strategy not in ['cheat', 'info', 'random']: print('Strategy has to be one of cheat, info or random') return get_game_json(game_id) result = subprocess.run(['./rust_hanabi', '--file', str((GAMES_PATH / str(game_id))), '--json-output', '%-' + strategy, '--strategy', strategy]) if result.returncode != 0: print('Failed to run game {} with cheating stratgey'.format(game_id)) def ensure_bot_game_exists(game_id: int, strategy: str): filename = GAMES_PATH / '{}-{}'.format(game_id, strategy) if not filename.exists(): run_strategy(game_id, strategy)