From bfe83d4f438419a4487cb06d47727a60d2ab12c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sat, 13 Jan 2024 14:32:48 +0100 Subject: [PATCH] load endgame actions from db --- src/endgames.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/endgames.py b/src/endgames.py index 6743b11..b45eeaa 100644 --- a/src/endgames.py +++ b/src/endgames.py @@ -131,6 +131,26 @@ def store_endgame_actions(game_id: int, endgame_actions: List[EndgameAction]) -> conn.commit() +def load_endgame_actions(game_id: int) -> List[EndgameAction]: + cur = conn_manager.get_new_cursor() + cur.execute( + "SELECT (turn, action_type, suit_index, rank, enumerator, denominator) " + "FROM endgames " + "WHERE game_id = %s " + "ORDER BY turn ASC, action_type ASC, suit_index ASC, rank ASC", + (game_id,) + ) + ret = [] + for (turn, action_type, suit_index, rank, enumerator, denominator) in cur.fetchall(): + ret.append(EndgameAction( + turn, + hanabi.hanab_game.ActionType(action_type), + hanabi.hanab_game.DeckCard(suit_index, rank), + enumerator, denominator) + ) + return ret + + def parse_match(action: Dict) -> EndgameAction: turn = action["turn"] action_type = parse_action_type(action["type"])