From c829cd1afd309b4b71d16fae10d45cd8a539d741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Mon, 20 Nov 2023 12:27:09 +0100 Subject: [PATCH] Adjust regex parsing, remove prints --- endgames.py | 25 ++++++++++++++----------- get_sheet.py | 4 +--- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/endgames.py b/endgames.py index b03fd1b..8d33a95 100644 --- a/endgames.py +++ b/endgames.py @@ -26,12 +26,11 @@ def analyze_game(game_id: int): # Now, parse all results that we obtained (unclear how many depending on whether we ran into the timeout) probabilities = {} - # Check if the game was just over before reaching the specified draw pile size - for m in re.finditer(r'The given draw pile size \(([0-9]+)\) cannot be obtained with the specified replay.', output): - if m.group(1) == str(max_draw_pile_size): - return {str(size): 0 for size in range(1, max_draw_pile_size + 1)} - else: - probabilities[str(m.group(1))] = 0 + m = re.search(r"Specified draw pile size of ([0-9]+) cannot be reached with specified replay\.\nReplay ends at turn [0-9]+ with score of ([0-9]+)\.", output, re.M) + if m: + won = '100' if m.group(2) == '25' else 0 + for draw_pile_size in range(1, int(m.group(1)) + 1): + probabilities[str(draw_pile_size)] = won for m in re.finditer('Probability with ([0-9]+) cards left in deck: .*/.* ~ ([0-9.]+)', output): probabilities[str(m.group(1))] = m.group(2) @@ -52,11 +51,15 @@ def full_analyze_game(game_id: int): zero_dict = { (('+' if clue_modifier >= 0 else '') + str(clue_modifier)): 0 for clue_modifier in range(-8, 9) } - for m in re.finditer(r'The given draw pile size \(([0-9]+)\) cannot be obtained with the specified replay.', output): - if m.group(1) == str(max_draw_pile_size): - return {str(size): zero_dict for size in range(1, max_draw_pile_size + 1)} - else: - probabilities[str(m.group(1))] = zero_dict + hundred_dict = { + (('+' if clue_modifier >= 0 else '') + str(clue_modifier)): 100 for clue_modifier in range(-8, 9) + } + + m = re.search(r"Specified draw pile size of ([0-9]+) cannot be reached with specified replay\.\nReplay ends at turn [0-9]+ with score of ([0-9]+)\.", output, re.M) + if m: + won = hundred_dict if m.group(2) == '25' else zero_dict + for draw_pile_size in range(1, int(m.group(1)) + 1): + probabilities[str(draw_pile_size)] = won for m in re.finditer('Probability with ([0-9]+) cards left in deck and [0-8] clues \((.[0-8])\).*: .*/.* ~ ([0-9.]*)', output): if m.group(1) not in probabilities.keys(): diff --git a/get_sheet.py b/get_sheet.py index ed5f236..03f8b9e 100644 --- a/get_sheet.py +++ b/get_sheet.py @@ -109,7 +109,6 @@ def analyze_endgames(games): print('Analysing endgames of game {}'.format(game_id)) result = analyze_game_cached(game_id) retval[game_id] = result - print(result) return retval def full_analyze_endgames(games): @@ -118,7 +117,6 @@ def full_analyze_endgames(games): print('Analysing all endgames of game {}'.format(game_id)) result = full_analyze_game_cached(game_id) retval[game_id] = result - print(result) return retval @@ -206,7 +204,7 @@ if __name__ == "__main__": with open(filename, 'a') as f: writer = csv.DictWriter(f, fieldnames=fieldnames) for game_id, endgame in sorted(all_endgames.items()): - print(endgame) + # print(endgame) row = {'Game ID': game_id} for deck_size in range(1, 11): val = lookup_val(endgame.get(str(deck_size), {}), clue_modifier)