samples/13_path_finding_algorithms/05_dijkstra/app/main.rb
# Returns a list of adjacent cells
# Used to determine what the next cells to be added to the frontier are
Returns a list of adjacent cells
Used to determine what the next cells to be added to the frontier are
Returns a list of adjacent cells Used to determine what the next cells to be added to the frontier are
def adjacent_neighbors(cell)
    neighbors = []
    neighbors << [cell.x    , cell.y - 1] unless cell.y == 0
    neighbors << [cell.x - 1, cell.y    ] unless cell.x == 0
    neighbors << [cell.x    , cell.y + 1] unless cell.y == grid.height - 1
    neighbors << [cell.x + 1, cell.y    ] unless cell.x == grid.width - 1
    neighbors = neighbors.sort_by { |neighbor_x, neighbor_y|  proximity_to_star(neighbor_x, neighbor_y) }
    neighbors
  end
def adjacent_neighbors ( cell ) neighbors = [ ] neighbors << [ cell . x , cell . y - 1 ] unless cell . y == 0 neighbors << [ cell . x - 1 , cell . y ] unless cell . x == 0 neighbors << [ cell . x , cell . y + 1 ] unless cell . y == grid . height - 1 neighbors << [ cell . x + 1 , cell . y ] unless cell . x == grid . width - 1 neighbors = neighbors . sort_by { | neighbor_x , neighbor_y | proximity_to_star ( neighbor_x , neighbor_y ) } neighbors end
Returns a list of adjacent cells
Used to determine what the next cells to be added to the frontier are
Returns a list of adjacent cells Used to determine what the next cells to be added to the frontier are
# Gets all the valid neighbors into the array # From southern neighbor, clockwise # Sorts the neighbors so the rendered path is a zigzag path # Cells in a diagonal direction are given priority # Comment this line to see the difference
cell