load endgame actions from db

This commit is contained in:
Maximilian Keßler 2024-01-13 14:32:48 +01:00
parent 5c6c8a6b14
commit bfe83d4f43
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -131,6 +131,26 @@ def store_endgame_actions(game_id: int, endgame_actions: List[EndgameAction]) ->
conn.commit() 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: def parse_match(action: Dict) -> EndgameAction:
turn = action["turn"] turn = action["turn"]
action_type = parse_action_type(action["type"]) action_type = parse_action_type(action["type"])