Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def a_star(map, start_column, start_row, goal_column, goal_row):
- """
- Algorithm to make path from start to goal by counting the weight of each point
- and make path to be more directed to goal
- :param map: Map with the lava
- :param start_column: In which column start point is
- :param start_row: In which row start point is
- :param goal_column: In which column goal point is
- :param goal_row: In which row goal point is
- :return: The path from start to goal
- :return:
- """
- start = (start_column, start_row)
- goal = (goal_column, goal_row)
- frontier = PriorityQueue()
- frontier.put((0, start))
- came_from = {}
- cost_so_far = {}
- came_from[start] = None
- cost_so_far[start] = 0
- path = []
- curr = None
- while not frontier.empty():
- _, curr = frontier.get()
- if map[curr[1]][curr[0]] == "D":
- break
- for next in neighbours(curr, map):
- if next is not None:
- if map[next[1]][next[0]] != "*":
- new_cost = cost_so_far[curr] + 1
- if next not in cost_so_far or new_cost < cost_so_far[next]:
- cost_so_far[next] = new_cost
- priority = new_cost + heuristic(goal, next)
- frontier.put((priority, next))
- came_from[next] = curr
- while curr != start:
- path.append(curr)
- curr = came_from[curr]
- path.append(start)
- path.reverse()
- visualize(path, map)
- return path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement