From f0263ab25007866b20772230d814a83e1e4c3202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sat, 11 Nov 2023 14:02:44 +0100 Subject: [PATCH] adjust endgame analysis to new cli interface --- endgames.py | 25 +++++++++++++++++-------- get_sheet.py | 2 ++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/endgames.py b/endgames.py index 54b790b..19438fb 100644 --- a/endgames.py +++ b/endgames.py @@ -16,15 +16,24 @@ with open(DATA_FILE, 'r') as f: def analyze_game(game_id: int): probabilities = {} - for deck_size in range(1, 16): - try: - result = subprocess.run(['./endgame-analyzer', '-g', str(game_id), '-d', str(deck_size), '-i', '0'], stdout=subprocess.PIPE, timeout=30) - except subprocess.TimeoutExpired: + raw_output = None + try: + result = subprocess.run(['./endgame-analyzer', '-g', str(game_id), '-d', '16', '--interactive', '0', '--quiet', '-r'], stdout=subprocess.PIPE, timeout=30) + raw_output = result.stdout + except subprocess.TimeoutExpired as time_err: + raw_output = time_err.stdout + output = raw_output.decode('utf-8') + + # Check if the game was just over before reaching the specified draw pile size + if re.match("This given draw pile size \(.*\) cannot be obtained with the specified replay.", output): + for i in range(0,16): + probabilities[str(i)] = 0 return probabilities - output = result.stdout.decode('utf-8') - m = re.search('Probability with optimal play: .*/.* ~ ([0-9.]+)', output) - if m: - probabilities[str(deck_size)] = m.group(1) + + # Now, parse all results that we obtained (unclear how many depending on whether we ran into the timeout) + for m in re.finditer('Probability with ([0-9]+) cards left in the deck: .*/.* ~ ([0-9.]+)', output): + probabilities[str(m.group(1))] = m.group(2) + return probabilities diff --git a/get_sheet.py b/get_sheet.py index cb129a4..ca95634 100644 --- a/get_sheet.py +++ b/get_sheet.py @@ -210,6 +210,8 @@ if __name__ == "__main__": val = lookup_val(endgame.get(str(deck_size), {}), clue_modifier) if val is not None: row[str(deck_size)] = val + else: + print("No results found for game {} and deck size {}: {}".format(game_id, deck_size, endgame.get(str(deck_size)))) writer.writerow(row) print('processed file {}'.format(filename))