コード例 #1
0
def path_print2(puzzle, min, sp_z, size_matr):
    # sp_z - список всех вершин
    count = 0
    if not Mode.BENCHMARK_MODE:
        print('Ordered sequence of states that make up the solution')
        Printer.print_endline()
    sp_path = []
    while min:
        sp_path.append(min.node)
        min = sp_z[min]
        # min = 0
    sp_path.reverse()
    # print(sp_path)

    for sp in sp_path:
        curr_move_lst = []
        if (count > 0):
            curr_move_lst = [i for i in range(len(sp)) if sp[i] != sp_prev[i]]
        sp_prev = sp
        count += 1

        if Mode.BENCHMARK_MODE:
            continue

        RESET = ""
        for i in range(len(sp)):
            color = YELLOW if i in curr_move_lst else RESET
            color = ""
            RESET = ""
            if i % size_matr == size_matr - 1:
                print(f'{color}{sp[i]:{2}}{RESET}', end='\n')
            else:
                print(f'{color}{sp[i]:{2}}{RESET}', end=' ')
        Printer.print_endline()

    if Mode.BENCHMARK_MODE:
        puzzle.path_len = count
        puzzle.path = sp_path
    else:
        print(f"Algorithm: {puzzle.sf_name}")
        print(f'Heuristic: {puzzle.hf_name}')
        print("Number of moves from initial state to solution = ", count)
        print(f"processing time = {puzzle.dt:0.6f}")
        print(f"complexity in time = {puzzle.complexity_in_time}")
        print(f"complexity in size = {puzzle.complexity_in_size}")