Beispiel #1
0

if __name__ == '__main__':
    input_file_name, *rest = sys.argv[1:]
    if rest:
        output_file_name = rest[0]
    else:
        output_file_name = 'output.txt'

    algorithms = {'d': dfs, 'b': bfs, 'a': partial(a_star, h=heuristic)}

    problem = formulate_maze_problem(input_file_name)
    visualizer = Visualizer(problem)
    if problem:
        os.system('clear')
        visualizer.visualize_state(problem.initial_state)
        print_possible_actions()
        option = input('Enter an option: ').lower()
        algorithm = algorithms.get(option)
        if not algorithm:
            print('Press only the first letter of the algorithm')
            sys.exit(1)
        os.system('clear')
        solution = algorithm(problem)
        if solution:
            visualizer.visualize(solution)
            output = problem.prettify(solution)
            with open(output_file_name, 'w') as f:
                print(output, file=f)
            print(output)
            print(f'Output is written to file {output_file_name}!')