def test_correct_path(database_dir): for pid in PuzzleManager.getPuzzleIds(): p_cls = PuzzleManager.getPuzzleClass(pid) for variant in p_cls.test_variants: s_cls = PuzzleManager.getSolverClass(pid, test=True) solver = s_cls(p_cls.generateStartPosition(variant), dir_path=database_dir) puzzle = p_cls.generateStartPosition(variant) solver.solve() if puzzle.numPositions: assert puzzle.numPositions >= len( solver._remoteness ), "{} defined numPositions to be {} but solver calculated {}".format( puzzle.name, puzzle.numPositions, len(solver)) while puzzle.primitive() != PuzzleValue.SOLVABLE: assert (solver.getValue(puzzle) == PuzzleValue.SOLVABLE ), "{} not SOLVABLE".format( puzzle.toString(mode="minimal")) positions = generateMovePositions(puzzle) prev_remote = solver.getRemoteness(puzzle) b = False for pos in positions: next_remote = solver.getRemoteness(pos[1]) if (next_remote != PuzzleValue.UNSOLVABLE and next_remote < prev_remote): puzzle = pos[1] b = True if not b: raise AssertionError( "Puzzle {} has {} has no moves to reach solution". format(puzzle.__class__.name, puzzle.toString(mode="minimal")))
def puzzles(): response = [ { "gameId": puzzle_id, "name" : PuzzleManager.getPuzzleClass(puzzle_id).name, "status": check_available(puzzle_id) } for puzzle_id in PuzzleManager.getPuzzleIds() ] return format_response(response)
action="store_true", help="Solver reveals some helpful info") parser.add_argument("-a", "--auto", action="store_true", help="Puzzle plays itself") parser.add_argument("-l", "--list", action="store_true", help="Lists puzzles and their ids") args = parser.parse_args() if not PuzzleManager.hasPuzzleId(args.puzzleid): print("Possible puzzles:") print("\n".join(PuzzleManager.getPuzzleIds())) raise Exception("Puzzleid is not recorded in PuzzleList") p_cls = PuzzleManager.getPuzzleClass(args.puzzleid) puzzle = None if args.variant: puzzle = p_cls.generateStartPosition(args.variant) if args.position: puzzle = p_cls.deserialize(args.position) if not puzzle: puzzle = p_cls() if args.info or args.auto: s_cls = PuzzleManager.getSolverClass(args.puzzleid, args.variant) solver = s_cls(puzzle)
def puzzles(): response = {"puzzles": list(PuzzleManager.getPuzzleIds())} return format_response(response)