add option to analyse cheat games. read games from disk
This commit is contained in:
parent
9028c7401a
commit
6e960e4425
2 changed files with 19 additions and 14 deletions
32
endgames.py
32
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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue