Adjust regex parsing, remove prints
This commit is contained in:
parent
49142ba4f5
commit
c829cd1afd
2 changed files with 15 additions and 14 deletions
25
endgames.py
25
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():
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue