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
|
import subprocess
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from games import GAMES_PATH
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
DATA_FILE = Path('endgame-data.json')
|
DATA_FILE = Path('endgame-data.json')
|
||||||
|
|
||||||
|
@ -14,10 +16,10 @@ with open(DATA_FILE, 'r') as f:
|
||||||
DATA: Dict = json.loads(f.read())
|
DATA: Dict = json.loads(f.read())
|
||||||
|
|
||||||
|
|
||||||
def analyze_game(game_id: int):
|
def analyze_game(filename: str):
|
||||||
max_draw_pile_size = 15
|
max_draw_pile_size = 15
|
||||||
try:
|
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
|
raw_output = result.stdout
|
||||||
except subprocess.TimeoutExpired as time_err:
|
except subprocess.TimeoutExpired as time_err:
|
||||||
raw_output = time_err.stdout
|
raw_output = time_err.stdout
|
||||||
|
@ -38,10 +40,10 @@ def analyze_game(game_id: int):
|
||||||
return probabilities
|
return probabilities
|
||||||
|
|
||||||
|
|
||||||
def full_analyze_game(game_id: int):
|
def full_analyze_game(filename: str):
|
||||||
max_draw_pile_size = 10
|
max_draw_pile_size = 10
|
||||||
try:
|
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
|
raw_output = result.stdout
|
||||||
except subprocess.TimeoutExpired as time_err:
|
except subprocess.TimeoutExpired as time_err:
|
||||||
raw_output = time_err.stdout
|
raw_output = time_err.stdout
|
||||||
|
@ -68,25 +70,27 @@ def full_analyze_game(game_id: int):
|
||||||
return probabilities
|
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)
|
cached = DATA.get('all', {}).get(str(game_id), None)
|
||||||
if cached is not None:
|
if cached is not None:
|
||||||
return cached
|
return cached
|
||||||
result = full_analyze_game(game_id)
|
result = full_analyze_game(str(GAMES_PATH / str(game_id)) + '-cheat' if cheat else '')
|
||||||
if 'all' not in DATA.keys():
|
key = 'all' if not cheat else 'all-cheat'
|
||||||
DATA['all'] = {}
|
if key not in DATA.keys():
|
||||||
DATA['all'][game_id] = result
|
DATA[key] = {}
|
||||||
|
DATA[key][game_id] = result
|
||||||
save_cache()
|
save_cache()
|
||||||
return result
|
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)
|
cached = DATA.get('normal', {}).get(str(game_id), None)
|
||||||
if cached is not None:
|
if cached is not None:
|
||||||
return cached
|
return cached
|
||||||
result = analyze_game(game_id)
|
result = analyze_game(str(GAMES_PATH / str(game_id)) + '-cheat' if cheat else '')
|
||||||
if 'normal' not in DATA.keys():
|
key = 'normal' if not cheat else 'normal-cheat'
|
||||||
DATA['normal'] = {}
|
if key not in DATA.keys():
|
||||||
DATA['normal'][game_id] = result
|
DATA[key] = {}
|
||||||
|
DATA[key][game_id] = result
|
||||||
save_cache()
|
save_cache()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ from hanabi.live.site_api import get
|
||||||
from bdr import describe_game
|
from bdr import describe_game
|
||||||
from endgames import analyze_game_cached, full_analyze_game_cached
|
from endgames import analyze_game_cached, full_analyze_game_cached
|
||||||
from games import get_game_json
|
from games import get_game_json
|
||||||
|
from bots import run_cheating_strategy
|
||||||
|
|
||||||
# Init db connection
|
# Init db connection
|
||||||
global_db_connection_manager.read_config()
|
global_db_connection_manager.read_config()
|
||||||
|
|
Loading…
Reference in a new issue