From 722838243f278a6261251d80b71bb7c5da8b91c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 7 Jul 2023 14:32:11 +0200 Subject: [PATCH] make starting_player a property of instances, not games --- hanabi/hanab_game.py | 8 +++++--- hanabi/live/check_game.py | 11 ++++++++--- hanabi/live/download_data.py | 6 +++--- hanabi/live/hanab_live.py | 4 ++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/hanabi/hanab_game.py b/hanabi/hanab_game.py index c4ec23a..9ea8bba 100644 --- a/hanabi/hanab_game.py +++ b/hanabi/hanab_game.py @@ -116,7 +116,8 @@ class HanabiInstance: clue_starved: bool = False, # if true, discarding and playing fives only gives back half a clue fives_give_clue: bool = True, # if false, then playing a five will not change the clue count deck_plays: bool = False, - all_or_nothing: bool = False + all_or_nothing: bool = False, + starting_player: int = 0 # defines index of player that starts the game ): # defining properties self.deck = deck @@ -128,6 +129,7 @@ class HanabiInstance: self.deck_plays = deck_plays, self.all_or_nothing = all_or_nothing assert not self.all_or_nothing, "All or nothing not implemented" + self.starting_player = starting_player # normalize deck indices for (idx, card) in enumerate(self.deck): @@ -170,7 +172,7 @@ class HanabiInstance: class GameState: - def __init__(self, instance: HanabiInstance, starting_player: int = 0): + def __init__(self, instance: HanabiInstance): # will not be modified self.instance = instance @@ -181,7 +183,7 @@ class GameState: self.stacks = [0 for i in range(0, self.instance.num_suits)] self.strikes = 0 self.clues = 8 - self.turn = starting_player + self.turn = self.instance.starting_player self.pace = self.instance.initial_pace self.remaining_extra_turns = self.instance.num_players + 1 self.trash = [] diff --git a/hanabi/live/check_game.py b/hanabi/live/check_game.py index 2efbb4f..dbfd2a5 100644 --- a/hanabi/live/check_game.py +++ b/hanabi/live/check_game.py @@ -19,7 +19,7 @@ from hanabi.solvers import sat def check_game(game_id: int) -> Tuple[int, hanab_game.GameState]: logger.debug("Analysing game {}".format(game_id)) with database.conn.cursor() as cur: - cur.execute("SELECT games.num_players, deck, actions, score, games.variant_id FROM games " + cur.execute("SELECT games.num_players, deck, actions, score, games.variant_id, starting_player FROM games " "INNER JOIN seeds ON seeds.seed = games.seed " "WHERE games.id = (%s)", (game_id,) @@ -27,11 +27,16 @@ def check_game(game_id: int) -> Tuple[int, hanab_game.GameState]: res = cur.fetchone() if res is None: raise ValueError("No game associated with id {} in database.".format(game_id)) - (num_players, compressed_deck, compressed_actions, score, variant_id) = res + (num_players, compressed_deck, compressed_actions, score, variant_id, starting_player) = res deck = compress.decompress_deck(compressed_deck) actions = compress.decompress_actions(compressed_actions) - instance = hanab_live.HanabLiveInstance(deck, num_players, variant_id=variant_id) + instance = hanab_live.HanabLiveInstance( + deck, + num_players, + variant_id=variant_id, + starting_player=starting_player + ) # check if the instance is already won if instance.max_score == score: diff --git a/hanabi/live/download_data.py b/hanabi/live/download_data.py index 0076933..b7b9835 100644 --- a/hanabi/live/download_data.py +++ b/hanabi/live/download_data.py @@ -118,9 +118,9 @@ def detailed_export_game( deck_plays=deck_plays, one_less_card=one_less_card, one_extra_card=one_extra_card, - all_or_nothing=all_or_nothing - ), - starting_player + all_or_nothing=all_or_nothing, + starting_player=starting_player + ) ) for action in actions: game.make_action(action) diff --git a/hanabi/live/hanab_live.py b/hanabi/live/hanab_live.py index 1c1a3e5..e1e2904 100644 --- a/hanabi/live/hanab_live.py +++ b/hanabi/live/hanab_live.py @@ -41,8 +41,8 @@ class HanabLiveInstance(hanab_game.HanabiInstance): class HanabLiveGameState(hanab_game.GameState): - def __init__(self, instance: HanabLiveInstance, starting_player: int = 0): - super().__init__(instance, starting_player) + def __init__(self, instance: HanabLiveInstance): + super().__init__(instance) self.instance: HanabLiveInstance = instance def make_action(self, action):