From beecacb89723f8cadee99b7019c51e05b6891467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Mon, 20 Nov 2023 16:45:53 +0100 Subject: [PATCH] add missing file --- bots.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 bots.py diff --git a/bots.py b/bots.py new file mode 100644 index 0000000..430d8db --- /dev/null +++ b/bots.py @@ -0,0 +1,19 @@ +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)