add endgame parsing
This commit is contained in:
parent
d485488d1e
commit
c98e9f3c7e
1 changed files with 13 additions and 7 deletions
20
endgames.py
20
endgames.py
|
@ -23,27 +23,33 @@ def analyze_game(game_id: int):
|
||||||
return probabilities
|
return probabilities
|
||||||
output = result.stdout.decode('utf-8')
|
output = result.stdout.decode('utf-8')
|
||||||
m = re.search('Probability with optimal play: .*/.* ~ ([0-9.]+)', output)
|
m = re.search('Probability with optimal play: .*/.* ~ ([0-9.]+)', output)
|
||||||
if not m:
|
if m:
|
||||||
raise ValueError("Invalid program output: {}".format(output))
|
probabilities[str(deck_size)] = m.group(1)
|
||||||
probabilities[str(deck_size)] = m.group(1)
|
|
||||||
return probabilities
|
return probabilities
|
||||||
|
|
||||||
|
|
||||||
def full_analyze_game(game_id: int):
|
def full_analyze_game(game_id: int):
|
||||||
probabilities = {}
|
probabilities = {}
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(['./endgame-analyzer', '-g', str(game_id), '-d', str(deck_size), '-i', '0', '--all-clues', '-r'], stdout=subprocess.PIPE, timeout=180)
|
result = subprocess.run(['./endgame-analyzer', '-g', str(game_id), '-d', str(10), '-i', '0', '--all-clues', '-r', '--quiet'], stdout=subprocess.PIPE, timeout=180)
|
||||||
except subproces.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
return probabilities
|
return probabilities
|
||||||
output = result.stdout.decode('utf-8')
|
output = result.stdout.decode('utf-8')
|
||||||
for m in re.finditer('Probability with (\d+) cards left in deck and (\d) clues (+|-\d): .*/.* ~ ([0-9.]+)', output):
|
print(output)
|
||||||
probabilities[m.group(1)][m.group(3)] = m.group(4)
|
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():
|
||||||
|
probabilities[m.group(1)] = {}
|
||||||
|
probabilities[m.group(1)][m.group(2)] = m.group(3)
|
||||||
return probabilities
|
return probabilities
|
||||||
|
|
||||||
|
|
||||||
def full_analyze_game_cached(game_id: int):
|
def full_analyze_game_cached(game_id: int):
|
||||||
cached = DATA.get('all', {}).get(str(game_id), None)
|
cached = DATA.get('all', {}).get(str(game_id), None)
|
||||||
if cached is not None:
|
if cached is not None:
|
||||||
return cached
|
return cached
|
||||||
result = full_analyze_game(game_id)
|
result = full_analyze_game(game_id)
|
||||||
|
if 'all' not in DATA.keys():
|
||||||
|
DATA['all'] = {}
|
||||||
DATA['all'][game_id] = result
|
DATA['all'][game_id] = result
|
||||||
save_cache()
|
save_cache()
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in a new issue