def main(): parser = argparse.ArgumentParser(description='n-puzzle') parser.add_argument('-d', '--distance-metric', help='Distance function', choices=['simple', 'manhattan', 'euclead'], default='manhattan') parser.add_argument('-v', '--verbose', help='Verbose intermediate results', action='store_true') parser.add_argument('-g', '--greedy', help='Use greedy algorithm', action='store_true') parser.add_argument('-u', '--uniform', help='Use uniform cost', action='store_true') parser.add_argument('file', help='input file') parser = parser.parse_args() try: data_parser = Parser(file_name=parser.file) node = Node(puzzle_data=data_parser.get_data(), metric=parser.distance_metric, print_inter_res=parser.verbose, greedy=parser.greedy, uniform_cost=parser.uniform) game = Game(start_node=node) game.solve() exit(0) except ValueError as error: print(error) exit(2)
def main(): try: opts, args = getopt.getopt(sys.argv[1:], "f", ["file"]) except getopt.error as msg: print(msg) print("It is necessary file :((") sys.exit(2) for arg in args: try: parser = Parser(file_name=arg) node = Node(puzzle_data=parser.get_data(), metric='simple') game = Game(start_node=node) game.solve() exit(0) except ValueError as error: print(error) exit(2) parser = Parser() node = Node(puzzle_data=parser.get_data(), metric='euclead') game = Game(start_node=node) game.solve()