From 7f1df756b28010c529e092c04c7fe04c150de404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 10 Nov 2023 10:59:35 +0100 Subject: [PATCH] add file to analyze bdrs --- bdr.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 bdr.py diff --git a/bdr.py b/bdr.py new file mode 100644 index 0000000..b19c512 --- /dev/null +++ b/bdr.py @@ -0,0 +1,28 @@ +from typing import List, Dict + +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]: + bdrs = [] + game = HanabLiveGameState(instance) + for action in actions: + if action.type == ActionType.Discard: + discard = instance.deck[action.target] + if not game.is_trash(discard): + 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) + game.make_action(action) + return bdrs + + +def describe_game(game_json: Dict): + instance, actions = parse_json_game(game_json) + bdrs = get_bdrs(instance, actions) + return bdrs +