From cf9a81979a39231ae203e79cdd2d363ef32feb92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sun, 14 Jan 2024 13:48:49 +0100 Subject: [PATCH] generate game pages also for games with no endgame analysis --- src/render_site.py | 50 +++++++++++++++++++++++---------------------- templates/game.html | 7 +++++++ 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/render_site.py b/src/render_site.py index 46be44a..973e0d4 100644 --- a/src/render_site.py +++ b/src/render_site.py @@ -784,37 +784,39 @@ def convert_endgame_action(endgame_action: endgames.EndgameAction, game: hanabi. def get_endgame_page_data(): cur = conn_manager.get_new_cursor() cur.execute( - "SELECT game_id " + "SELECT games.id, termination_reason " "FROM games " "LEFT OUTER JOIN endgames_analyzed " " ON endgames_analyzed.game_id = games.id " - "WHERE termination_reason IS NOT NULL" ) ret = {} - for (game_id, ) in cur.fetchall(): - ret[game_id] = [] - instance, actions, _ = games_db_interface.load_game_parts(game_id) - game = hanabi.hanab_game.GameState(instance) + for (game_id, termination_reason) in cur.fetchall(): + if termination_reason is not None: + ret[game_id] = [] + instance, actions, _ = games_db_interface.load_game_parts(game_id) + game = hanabi.hanab_game.GameState(instance) - endgame_actions = endgames.load_endgame_actions(game_id) - while len(endgame_actions) > 0: - # Move to current turn and update game - cur_turn = endgame_actions[0].turn - # Note the -1 here since turns on hanab.live start to count at 1 - while len(game.actions) < cur_turn - 1: - action, *actions = actions - game.make_action(action) - assert len(actions) > 0 + endgame_actions = endgames.load_endgame_actions(game_id) + while len(endgame_actions) > 0: + # Move to current turn and update game + cur_turn = endgame_actions[0].turn + # Note the -1 here since turns on hanab.live start to count at 1 + while len(game.actions) < cur_turn - 1: + action, *actions = actions + game.make_action(action) + assert len(actions) > 0 - actions_this_turn: List[endgames.EndgameAction] = [] - while len(endgame_actions) > 0 and endgame_actions[0].turn == cur_turn: - action, *endgame_actions = endgame_actions - actions_this_turn.append(action) - actions_this_turn.sort(key=lambda a: -a.win_rate) - best_action, *other_actions = [convert_endgame_action(a, game, actions[0]) for a in actions_this_turn] - ret[game_id].append( - (cur_turn, best_action, other_actions) - ) + actions_this_turn: List[endgames.EndgameAction] = [] + while len(endgame_actions) > 0 and endgame_actions[0].turn == cur_turn: + action, *endgame_actions = endgame_actions + actions_this_turn.append(action) + actions_this_turn.sort(key=lambda a: -a.win_rate) + best_action, *other_actions = [convert_endgame_action(a, game, actions[0]) for a in actions_this_turn] + ret[game_id].append( + (cur_turn, best_action, other_actions) + ) + else: + ret[game_id] = None return ret diff --git a/templates/game.html b/templates/game.html index 38a34e2..fe04892 100644 --- a/templates/game.html +++ b/templates/game.html @@ -36,6 +36,7 @@

Endgame Analysis table

+ {% if data %} @@ -59,6 +60,12 @@ {% endfor %} {% endfor %}
Turn
+ {% else %} + Currently, there is no endgame analysis available for this game. Since the computation is resource extensive, + this might take a while, also depending on how many other games have been played recently. +
+ Come back later to check again. + {% endif %}