From 2c874275db6288edfab3278184f574adee557235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sat, 20 May 2023 14:38:38 +0200 Subject: [PATCH] add command-line flag to enable verbose printing to terminal --- check_game.py | 9 +++++---- hanabi_suite.py | 4 ++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/check_game.py b/check_game.py index 1a3fb49..cad2f07 100644 --- a/check_game.py +++ b/check_game.py @@ -51,7 +51,7 @@ def check_game(game_id: int) -> Tuple[int, GameState]: game = HanabLiveGameState(instance) solvable, solution = solve_sat(game) if not solvable: - logger.debug("Returning: Instance {} is not feasible") + logger.debug("Returning: Instance {} is not feasible.") return 0, solution logger.verbose("Instance {} is feasible after 0 turns: {}".format(game_id, link(solution))) @@ -61,16 +61,17 @@ def check_game(game_id: int) -> Tuple[int, GameState]: 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 {} turs".format(game_id, try_turn)) + logger.debug("Checking if instance {} is feasible after {} turns.".format(game_id, try_turn)) solvable, potential_sol = solve_sat(try_game) if solvable: solution = potential_sol game = try_game solvable_turn = try_turn - logger.verbose("Instance {} is feasible after {} turns: {}".format(game_id, solvable_turn, link(solution))) + logger.verbose("Instance {} is feasible after {} turns: {}#{}" + .format(game_id, solvable_turn, link(solution), solvable_turn + 1)) else: unsolvable_turn = try_turn - logger.verbose("Instance {} is not feasible after {} turns".format(game_id, unsolvable_turn)) + logger.verbose("Instance {} is not feasible after {} turns.".format(game_id, unsolvable_turn)) assert unsolvable_turn - 1 == solvable_turn, "Programming error" return unsolvable_turn, solution diff --git a/hanabi_suite.py b/hanabi_suite.py index d8dc555..8ad92c1 100755 --- a/hanabi_suite.py +++ b/hanabi_suite.py @@ -58,6 +58,7 @@ def main_parser() -> argparse.ArgumentParser: prog='hanabi_suite', description='High-level interface for analysis of hanabi instances.' ) + parser.add_argument('--verbose', '-v', help='Enable verbose logging to console', action='store_true') subparsers = parser.add_subparsers(dest='command', required=True, help='select subcommand') add_init_subparser(subparsers) @@ -72,6 +73,9 @@ if __name__ == "__main__": switcher = { 'analyze': analyze_game } + if args.verbose: + logger_manager.set_console_level(verboselogs.VERBOSE) method_args = dict(vars(args)) method_args.pop('command') + method_args.pop('verbose') switcher[args.command](**method_args)