Exemplo n.º 1
0
def run():
    puzzle = Puzzle()
    args = ArgParser().parse()

    if args.file and args.size:
        puzzle.common_error(
            "flag --file and --size must be specify separately")

    if args.size and (args.size < 2 or args.size == 0):
        puzzle.critical_error("size should be >= 2")

    if args.file:
        puzzle.read(args.file)
        puzzle.validate()
    else:
        if args.size:
            puzzle.size = args.size

    puzzle.get_heuristic_type(args.htype)
    puzzle.generate(args.file)
    puzzle.print()
    node = puzzle.solver()
    puzzle.count_moves(node, args.path)
    print('\nSolution is:')
    puzzle.print(node=node)
    puzzle.output_required()
Exemplo n.º 2
0
def test_3x3_7():
    puzzle = Puzzle()
    htype = "m"
    file = f"{testpath}test_3x3_7.txt"
    puzzle.read(file)
    puzzle.validate()
    puzzle.get_heuristic_type(htype)
    puzzle.generate(file)
    node = puzzle.solver()
    assert node.grid == node.solved_puzzle
Exemplo n.º 3
0
def test_error_empty():
    puzzle = Puzzle()
    file = f"{testpath}test_error_empty.txt"
    with pytest.raises(SystemExit):
        puzzle.read(file)
        puzzle.validate()