adjust endgame analysis to new cli interface
This commit is contained in:
parent
8bd1f3bc25
commit
f0263ab250
2 changed files with 19 additions and 8 deletions
23
endgames.py
23
endgames.py
|
@ -16,15 +16,24 @@ with open(DATA_FILE, 'r') as f:
|
||||||
|
|
||||||
def analyze_game(game_id: int):
|
def analyze_game(game_id: int):
|
||||||
probabilities = {}
|
probabilities = {}
|
||||||
for deck_size in range(1, 16):
|
raw_output = None
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(['./endgame-analyzer', '-g', str(game_id), '-d', str(deck_size), '-i', '0'], stdout=subprocess.PIPE, timeout=30)
|
result = subprocess.run(['./endgame-analyzer', '-g', str(game_id), '-d', '16', '--interactive', '0', '--quiet', '-r'], stdout=subprocess.PIPE, timeout=30)
|
||||||
except subprocess.TimeoutExpired:
|
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
|
return probabilities
|
||||||
output = result.stdout.decode('utf-8')
|
|
||||||
m = re.search('Probability with optimal play: .*/.* ~ ([0-9.]+)', output)
|
# Now, parse all results that we obtained (unclear how many depending on whether we ran into the timeout)
|
||||||
if m:
|
for m in re.finditer('Probability with ([0-9]+) cards left in the deck: .*/.* ~ ([0-9.]+)', output):
|
||||||
probabilities[str(deck_size)] = m.group(1)
|
probabilities[str(m.group(1))] = m.group(2)
|
||||||
|
|
||||||
return probabilities
|
return probabilities
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -210,6 +210,8 @@ if __name__ == "__main__":
|
||||||
val = lookup_val(endgame.get(str(deck_size), {}), clue_modifier)
|
val = lookup_val(endgame.get(str(deck_size), {}), clue_modifier)
|
||||||
if val is not None:
|
if val is not None:
|
||||||
row[str(deck_size)] = val
|
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)
|
writer.writerow(row)
|
||||||
|
|
||||||
print('processed file {}'.format(filename))
|
print('processed file {}'.format(filename))
|
||||||
|
|
Loading…
Reference in a new issue