add command-line flag to enable verbose printing to terminal

This commit is contained in:
Maximilian Keßler 2023-05-20 14:38:38 +02:00
parent 746b30dbeb
commit 2c874275db
Signed by: max
GPG key ID: BCC5A619923C0BA5
2 changed files with 9 additions and 4 deletions

View file

@ -51,7 +51,7 @@ def check_game(game_id: int) -> Tuple[int, GameState]:
game = HanabLiveGameState(instance) game = HanabLiveGameState(instance)
solvable, solution = solve_sat(game) solvable, solution = solve_sat(game)
if not solvable: if not solvable:
logger.debug("Returning: Instance {} is not feasible") logger.debug("Returning: Instance {} is not feasible.")
return 0, solution return 0, solution
logger.verbose("Instance {} is feasible after 0 turns: {}".format(game_id, link(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) assert(len(try_game.actions) == solvable_turn)
for a in range(solvable_turn, try_turn): for a in range(solvable_turn, try_turn):
try_game.make_action(actions[a]) 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) solvable, potential_sol = solve_sat(try_game)
if solvable: if solvable:
solution = potential_sol solution = potential_sol
game = try_game game = try_game
solvable_turn = try_turn 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: else:
unsolvable_turn = try_turn 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" assert unsolvable_turn - 1 == solvable_turn, "Programming error"
return unsolvable_turn, solution return unsolvable_turn, solution

View file

@ -58,6 +58,7 @@ def main_parser() -> argparse.ArgumentParser:
prog='hanabi_suite', prog='hanabi_suite',
description='High-level interface for analysis of hanabi instances.' 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') subparsers = parser.add_subparsers(dest='command', required=True, help='select subcommand')
add_init_subparser(subparsers) add_init_subparser(subparsers)
@ -72,6 +73,9 @@ if __name__ == "__main__":
switcher = { switcher = {
'analyze': analyze_game 'analyze': analyze_game
} }
if args.verbose:
logger_manager.set_console_level(verboselogs.VERBOSE)
method_args = dict(vars(args)) method_args = dict(vars(args))
method_args.pop('command') method_args.pop('command')
method_args.pop('verbose')
switcher[args.command](**method_args) switcher[args.command](**method_args)