diff --git a/check_game.py b/check_game.py index e8c922f..8e82436 100644 --- a/check_game.py +++ b/check_game.py @@ -1,9 +1,9 @@ import copy -from typing import Tuple, Optional +from typing import Tuple -from database.database import conn +from database import conn from compress import decompress_deck, decompress_actions, link -from hanabi import Action, GameState +from hanabi import GameState from hanab_live import HanabLiveInstance, HanabLiveGameState from sat import solve_sat from log_setup import logger @@ -33,29 +33,29 @@ def check_game(game_id: int) -> Tuple[int, GameState]: instance = HanabLiveInstance(deck, num_players, variant_id=variant_id) + # check if the instance is already won if instance.max_score == score: game = HanabLiveGameState(instance) for action in actions: game.make_action(action) # instance has been won, nothing to compute here return len(actions) + 1, game - - # store lower and upper bounds of numbers of turns after which we know the game was feasible / infeasible - solvable_turn = 0 - unsolvable_turn = len(actions) # first, check if the instance itself is feasible: game = HanabLiveGameState(instance) solvable, solution = solve_sat(game) if not solvable: - logger.debug("Returning: Instance {} is not feasible.") return 0, solution logger.verbose("Instance {} is feasible after 0 turns: {}".format(game_id, link(solution))) + # store lower and upper bounds of numbers of turns after which we know the game was feasible / infeasible + solvable_turn = 0 + unsolvable_turn = len(actions) + while unsolvable_turn - solvable_turn > 1: try_turn = (unsolvable_turn + solvable_turn) // 2 try_game = copy.deepcopy(game) - assert(len(try_game.actions) == solvable_turn) + assert len(try_game.actions) == solvable_turn for a in range(solvable_turn, try_turn): try_game.make_action(actions[a]) logger.debug("Checking if instance {} is feasible after {} turns.".format(game_id, try_turn)) @@ -70,5 +70,5 @@ def check_game(game_id: int) -> Tuple[int, GameState]: unsolvable_turn = try_turn logger.verbose("Instance {} is not feasible after {} turns.".format(game_id, unsolvable_turn)) - assert unsolvable_turn - 1 == solvable_turn, "Programming error" + assert unsolvable_turn - 1 == solvable_turn return unsolvable_turn, solution