samples/13_path_finding_algorithms/08_a_star/app/main.rb
def greedy_calc_path
    # Start from the target
    endpoint = grid.target
    # And the cell it came from
    next_endpoint = greedy.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)
      greedy.path << path
      # And get the next pair of cells
      endpoint = next_endpoint
      next_endpoint = greedy.came_from[endpoint]
      # Continue till there are no more cells
    end
  end
# Calculates the path between the target and star for the greedy search
# Only called when the greedy search finds the target
Calculates the path between the target and star for the greedy search
Only called when the greedy search finds the target
Calculates the path between the target and star for the greedy search Only called when the greedy search finds the target
def greedy_calc_path
    endpoint = grid.target
    next_endpoint = greedy.came_from[endpoint]
    while endpoint and next_endpoint
      path = get_path_between(endpoint, next_endpoint)
      greedy.path << path
      endpoint = next_endpoint
      next_endpoint = greedy.came_from[endpoint]
    end
  end
def greedy_calc_path endpoint = grid . target next_endpoint = greedy . came_from [ endpoint ] while endpoint and next_endpoint path = get_path_between ( endpoint , next_endpoint ) greedy . path << path endpoint = next_endpoint next_endpoint = greedy . came_from [ endpoint ] end end
Calculates the path between the target and star for the greedy search
Only called when the greedy search finds the target
Calculates the path between the target and star for the greedy search Only called when the greedy 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