samples/13_path_finding_algorithms/08_a_star/app/main.rb
def a_star_calc_path
    # Start from the target
    endpoint = grid.target
    # And the cell it came from
    next_endpoint = a_star.came_from[endpoint]

    while endpoint and next_endpoint
      # Draw a path between these two cells and store it
      path = get_path_between(endpoint, next_endpoint)
      a_star.path << path
      # And get the next pair of cells
      endpoint = next_endpoint
      next_endpoint = a_star.came_from[endpoint]
      # Continue till there are no more cells
    end
  end
# Calculates the path between the target and star for the a_star search
# Only called when the a_star search finds the target
Calculates the path between the target and star for the a_star search
Only called when the a_star search finds the target
Calculates the path between the target and star for the a_star search Only called when the a_star search finds the target
def a_star_calc_path
    endpoint = grid.target
    next_endpoint = a_star.came_from[endpoint]
    while endpoint and next_endpoint
      path = get_path_between(endpoint, next_endpoint)
      a_star.path << path
      endpoint = next_endpoint
      next_endpoint = a_star.came_from[endpoint]
    end
  end
def a_star_calc_path endpoint = grid . target next_endpoint = a_star . came_from [ endpoint ] while endpoint and next_endpoint path = get_path_between ( endpoint , next_endpoint ) a_star . path << path endpoint = next_endpoint next_endpoint = a_star . came_from [ endpoint ] end end
Calculates the path between the target and star for the a_star search
Only called when the a_star search finds the target
Calculates the path between the target and star for the a_star search Only called when the a_star search finds the target
# Start from the target # And the cell it came from # Draw a path between these two cells and store it # And get the next pair of cells # Continue till there are no more cells