From b65c4fe43fe49592f9763c1b86085a5d2fb9d098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 10 Nov 2023 12:00:40 +0100 Subject: [PATCH] analyze game loss reasons --- bdr.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/bdr.py b/bdr.py index b19c512..1e8e9bc 100644 --- a/bdr.py +++ b/bdr.py @@ -1,28 +1,45 @@ -from typing import List, Dict +from typing import List, Dict, Tuple from hanabi.hanab_game import Action, ActionType from hanabi.live.hanab_live import HanabLiveInstance, parse_json_game, HanabLiveGameState -def get_bdrs(instance: HanabLiveInstance, actions: List[Action]) -> List[int]: +def analyze_game(instance: HanabLiveInstance, actions: List[Action]) -> Tuple[List[int], str]: bdrs = [] + termination = '' game = HanabLiveGameState(instance) for action in actions: if action.type == ActionType.Discard: discard = instance.deck[action.target] if not game.is_trash(discard): + if game.is_critical(discard): + termination = 'Discard crit' + break 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) + if action.type == ActionType.Play: + play = instance.deck[action.target] + if (not game.is_playable(play)) and game.is_critical(play): + termination = 'Bomb crit' + print('Bombed crit {}'.format(play)) + print(game.deck[game.progress:], game.stacks) game.make_action(action) - return bdrs + 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 -def describe_game(game_json: Dict): +def describe_game(game_json: Dict) -> Tuple[List[int], str]: instance, actions = parse_json_game(game_json) - bdrs = get_bdrs(instance, actions) - return bdrs + bdrs, termination = analyze_game(instance, actions) + return bdrs, termination