Adjust regex parsing, remove prints

This commit is contained in:
Maximilian Keßler 2023-11-20 12:27:09 +01:00
parent 49142ba4f5
commit c829cd1afd
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 15 additions and 14 deletions

View file

@ -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) # Now, parse all results that we obtained (unclear how many depending on whether we ran into the timeout)
probabilities = {} probabilities = {}
# Check if the game was just over before reaching the specified draw pile size 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)
for m in re.finditer(r'The given draw pile size \(([0-9]+)\) cannot be obtained with the specified replay.', output): if m:
if m.group(1) == str(max_draw_pile_size): won = '100' if m.group(2) == '25' else 0
return {str(size): 0 for size in range(1, max_draw_pile_size + 1)} for draw_pile_size in range(1, int(m.group(1)) + 1):
else: probabilities[str(draw_pile_size)] = won
probabilities[str(m.group(1))] = 0
for m in re.finditer('Probability with ([0-9]+) cards left in deck: .*/.* ~ ([0-9.]+)', output): for m in re.finditer('Probability with ([0-9]+) cards left in deck: .*/.* ~ ([0-9.]+)', output):
probabilities[str(m.group(1))] = m.group(2) probabilities[str(m.group(1))] = m.group(2)
@ -52,11 +51,15 @@ def full_analyze_game(game_id: int):
zero_dict = { zero_dict = {
(('+' if clue_modifier >= 0 else '') + str(clue_modifier)): 0 for clue_modifier in range(-8, 9) (('+' 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): hundred_dict = {
if m.group(1) == str(max_draw_pile_size): (('+' if clue_modifier >= 0 else '') + str(clue_modifier)): 100 for clue_modifier in range(-8, 9)
return {str(size): zero_dict for size in range(1, max_draw_pile_size + 1)} }
else:
probabilities[str(m.group(1))] = zero_dict 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): 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(): if m.group(1) not in probabilities.keys():

View file

@ -109,7 +109,6 @@ def analyze_endgames(games):
print('Analysing endgames of game {}'.format(game_id)) print('Analysing endgames of game {}'.format(game_id))
result = analyze_game_cached(game_id) result = analyze_game_cached(game_id)
retval[game_id] = result retval[game_id] = result
print(result)
return retval return retval
def full_analyze_endgames(games): def full_analyze_endgames(games):
@ -118,7 +117,6 @@ def full_analyze_endgames(games):
print('Analysing all endgames of game {}'.format(game_id)) print('Analysing all endgames of game {}'.format(game_id))
result = full_analyze_game_cached(game_id) result = full_analyze_game_cached(game_id)
retval[game_id] = result retval[game_id] = result
print(result)
return retval return retval
@ -206,7 +204,7 @@ if __name__ == "__main__":
with open(filename, 'a') as f: with open(filename, 'a') as f:
writer = csv.DictWriter(f, fieldnames=fieldnames) writer = csv.DictWriter(f, fieldnames=fieldnames)
for game_id, endgame in sorted(all_endgames.items()): for game_id, endgame in sorted(all_endgames.items()):
print(endgame) # print(endgame)
row = {'Game ID': game_id} row = {'Game ID': game_id}
for deck_size in range(1, 11): for deck_size in range(1, 11):
val = lookup_val(endgame.get(str(deck_size), {}), clue_modifier) val = lookup_val(endgame.get(str(deck_size), {}), clue_modifier)