From 6e960e442566beb041afced4e0178d4cd5457ee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Mon, 20 Nov 2023 13:26:40 +0100 Subject: [PATCH] add option to analyse cheat games. read games from disk --- endgames.py | 32 ++++++++++++++++++-------------- get_sheet.py | 1 + 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/endgames.py b/endgames.py index 8d33a95..e8aca18 100644 --- a/endgames.py +++ b/endgames.py @@ -3,6 +3,8 @@ import re import subprocess from typing import Dict +from games import GAMES_PATH + from pathlib import Path DATA_FILE = Path('endgame-data.json') @@ -14,10 +16,10 @@ with open(DATA_FILE, 'r') as f: DATA: Dict = json.loads(f.read()) -def analyze_game(game_id: int): +def analyze_game(filename: str): max_draw_pile_size = 15 try: - result = subprocess.run(['./endgame-analyzer', '-g', str(game_id), '-d', str(max_draw_pile_size), '--interactive', '0', '--quiet', '-r'], stdout=subprocess.PIPE, timeout=60*15) + result = subprocess.run(['./endgame-analyzer', '-f', filename, '-d', str(max_draw_pile_size), '--interactive', '0', '--quiet', '-r'], stdout=subprocess.PIPE, timeout=60*15) raw_output = result.stdout except subprocess.TimeoutExpired as time_err: raw_output = time_err.stdout @@ -38,10 +40,10 @@ def analyze_game(game_id: int): return probabilities -def full_analyze_game(game_id: int): +def full_analyze_game(filename: str): max_draw_pile_size = 10 try: - result = subprocess.run(['./endgame-analyzer', '-g', str(game_id), '-d', str(max_draw_pile_size), '-i', '0', '--all-clues', '-r', '--quiet'], stdout=subprocess.PIPE, timeout=180) + result = subprocess.run(['./endgame-analyzer', '-f', filename, '-d', str(max_draw_pile_size), '-i', '0', '--all-clues', '-r', '--quiet'], stdout=subprocess.PIPE, timeout=180) raw_output = result.stdout except subprocess.TimeoutExpired as time_err: raw_output = time_err.stdout @@ -68,25 +70,27 @@ def full_analyze_game(game_id: int): return probabilities -def full_analyze_game_cached(game_id: int): +def full_analyze_game_cached(game_id: int, cheat: bool = False): cached = DATA.get('all', {}).get(str(game_id), None) if cached is not None: return cached - result = full_analyze_game(game_id) - if 'all' not in DATA.keys(): - DATA['all'] = {} - DATA['all'][game_id] = result + result = full_analyze_game(str(GAMES_PATH / str(game_id)) + '-cheat' if cheat else '') + key = 'all' if not cheat else 'all-cheat' + if key not in DATA.keys(): + DATA[key] = {} + DATA[key][game_id] = result save_cache() return result -def analyze_game_cached(game_id: int): +def analyze_game_cached(game_id: int, cheat: bool = False): cached = DATA.get('normal', {}).get(str(game_id), None) if cached is not None: return cached - result = analyze_game(game_id) - if 'normal' not in DATA.keys(): - DATA['normal'] = {} - DATA['normal'][game_id] = result + result = analyze_game(str(GAMES_PATH / str(game_id)) + '-cheat' if cheat else '') + key = 'normal' if not cheat else 'normal-cheat' + if key not in DATA.keys(): + DATA[key] = {} + DATA[key][game_id] = result save_cache() return result diff --git a/get_sheet.py b/get_sheet.py index 493b396..e8ae92f 100644 --- a/get_sheet.py +++ b/get_sheet.py @@ -10,6 +10,7 @@ from hanabi.live.site_api import get from bdr import describe_game from endgames import analyze_game_cached, full_analyze_game_cached from games import get_game_json +from bots import run_cheating_strategy # Init db connection global_db_connection_manager.read_config()