streak-hunting-spreadsheet/bdr.py

44 lines
1.8 KiB
Python
Raw Permalink Normal View History

2023-11-10 12:00:40 +01:00
from typing import List, Dict, Tuple
2023-11-10 10:59:35 +01:00
from hanabi.hanab_game import Action, ActionType
from hanabi.live.hanab_live import HanabLiveInstance, parse_json_game, HanabLiveGameState
2023-11-10 12:00:40 +01:00
def analyze_game(instance: HanabLiveInstance, actions: List[Action]) -> Tuple[List[int], str]:
2023-11-10 10:59:35 +01:00
bdrs = []
2023-11-10 12:00:40 +01:00
termination = ''
2023-11-10 10:59:35 +01:00
game = HanabLiveGameState(instance)
for action in actions:
2023-11-11 03:47:38 +01:00
if action.type == ActionType.Discard or (action.type == ActionType.Play and not game.is_playable(instance.deck[action.target])):
2023-11-10 10:59:35 +01:00
discard = instance.deck[action.target]
if not game.is_trash(discard):
2023-11-10 12:00:40 +01:00
if game.is_critical(discard):
2023-11-20 17:49:52 +01:00
termination = 'Discard crit' if action.type == ActionType.Discard else 'Bomb crit'
2023-11-10 12:00:40 +01:00
break
2023-11-10 10:59:35 +01:00
if discard.rank != 1:
if discard in game.deck[game.progress:]:
bdrs.append(game.draw_pile_size)
else:
if game.deck[game.progress:].count(discard) == 2:
bdrs.append(game.draw_pile_size)
2023-11-10 12:00:40 +01:00
if action.type == ActionType.Play:
play = instance.deck[action.target]
if (not game.is_playable(play)) and game.is_critical(play):
termination = 'Bomb crit'
2023-11-10 10:59:35 +01:00
game.make_action(action)
2023-11-10 12:00:40 +01:00
if termination == '':
if game.strikes == 3:
termination = 'Strikeout'
elif actions[-1].type in [ActionType.EndGame, ActionType.VoteTerminate]:
termination = 'VTK'
elif game.score < 25:
termination = 'Lost Endgame'
return bdrs, termination
2023-11-10 10:59:35 +01:00
2023-11-10 12:00:40 +01:00
def describe_game(game_json: Dict) -> Tuple[List[int], str]:
2023-11-10 10:59:35 +01:00
instance, actions = parse_json_game(game_json)
2023-11-10 12:00:40 +01:00
bdrs, termination = analyze_game(instance, actions)
return bdrs, termination
2023-11-10 10:59:35 +01:00