def main(): screen.fill(BLANK_COLOR) game_maze = maze.Maze() game_maze.draw(screen) draw_queue = [] path = AStar.a_star(game_maze.start, game_maze.end, draw_queue) if path is None: print("Path not found") exit() pygame.display.flip() wait_for_event(pygame.KEYDOWN) # draw steps progressively for cur_point in draw_queue: if not game_maze.is_start_or_end(cur_point): cur_point.draw(screen) time.sleep(STEP_SLEEP_TIME) pygame.display.flip() # draw path progressively for cur_point in path: if not game_maze.is_start_or_end(cur_point): cur_point._type = PATH cur_point.draw(screen) time.sleep(PATH_SLEEP_TIME) pygame.display.flip() # draw blank nodes with highlight color for x in range(game_maze.width): for y in range(game_maze.height): if game_maze.maze[x][y].get_type() == BLANK: game_maze.maze[x][y].set_type(HIGHLIGHT) game_maze.maze[x][y].draw(screen) pygame.display.flip() wait_for_event(pygame.QUIT)
start_state = State(configuration, white) print("\nChoose a method: ") method = input("1 - A* with h1: number of number at wrong position\n" "2 - A* with h2: sum of horizontal and vertical distances\n" "3 - A* with h3: sum (h1 + h2)\n" "4 - Depth First\n" "5 - Compare all methods\n" "Option -> ") method = int(method) print("\nRunning...") final_path = None generated_states = 0 explored_states = 0 if method == 1: final_path, generated_states, explored_states = AStar.a_star( start_state, 1) elif method == 2: final_path, generated_states, explored_states = AStar.a_star( start_state, 2) elif method == 3: final_path, generated_states, explored_states = AStar.a_star( start_state, 3) elif method == 4: final_path, generated_states, explored_states = DepthSearch8Game.depth_search( start_state) elif method == 5: final_path_h1, generated_states_h1, explored_states_h1 = AStar.a_star( start_state, 1) print("A* (h1) - Done !") final_path_h2, generated_states_h2, explored_states_h2 = AStar.a_star( start_state, 2)