forked from Hanabi/hanabi-league
Add retrieval methods for actions and decks
This commit is contained in:
parent
157342b6c8
commit
072d450fe6
2 changed files with 34 additions and 0 deletions
|
@ -269,6 +269,10 @@ def detailed_fetch_game(game_id: int) -> bool:
|
|||
games_db_interface.store_deck_for_seed(seed, instance.deck)
|
||||
games_db_interface.store_actions(game_id, actions)
|
||||
logger.debug("Fetched all game details of game {}.".format(game_id))
|
||||
|
||||
# Do some sanity checks that loading the stored data did not change it
|
||||
assert actions == games_db_interface.load_actions(game_id)
|
||||
assert instance.deck == games_db_interface.load_deck(seed)
|
||||
return True
|
||||
|
||||
|
||||
|
|
|
@ -40,3 +40,33 @@ def store_deck_for_seed(seed: str, deck: List[hanabi.hanab_game.DeckCard]):
|
|||
vals
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
|
||||
def load_actions(game_id: int) -> List[hanabi.hanab_game.Action]:
|
||||
cur = conn_manager.get_new_cursor()
|
||||
cur.execute("SELECT type, target, value FROM game_actions "
|
||||
"WHERE game_id = %s "
|
||||
"ORDER BY turn ASC",
|
||||
(game_id,))
|
||||
actions = []
|
||||
for action_type, target, value in cur.fetchall():
|
||||
actions.append(
|
||||
hanabi.hanab_game.Action(hanabi.hanab_game.ActionType(action_type), target, value)
|
||||
)
|
||||
return actions
|
||||
|
||||
|
||||
def load_deck(seed: str) -> List[hanabi.hanab_game.DeckCard]:
|
||||
cur = conn_manager.get_new_cursor()
|
||||
cur.execute("SELECT card_index, suit_index, rank FROM seeds "
|
||||
"WHERE seed = %s "
|
||||
"ORDER BY card_index ASC",
|
||||
(seed,)
|
||||
)
|
||||
deck = []
|
||||
for index, (card_index, suit_index, rank) in enumerate(cur.fetchall()):
|
||||
assert index == card_index
|
||||
deck.append(
|
||||
hanabi.hanab_game.DeckCard(suit_index, rank, card_index)
|
||||
)
|
||||
return deck
|
||||
|
|
Loading…
Reference in a new issue