lib/nasa_explorer_app/plateau.rb
# It does breadth-first search (BFS) to traverse the graph of grids
It does breadth-first search (BFS) to traverse the graph of grids
It does breadth - first search ( BFS ) to traverse the graph of grids
def print
      visited = {}
      grid = get_or_create_grid!(x: 0, y: 0)
      visited[grid.object_id] = 1
      queue = [grid]
      until queue.empty?
        g = queue.pop
        next unless g
        puts "#{g.x},#{g.y},#{g.object_id}"
        g.neighbours.values.each do |n|
          next if !n || visited[n.object_id]
          queue.unshift(n)
          visited[n.object_id] = 1
        end
      end
    end
def print visited = { } grid = get_or_create_grid! ( x : 0 , y : 0 ) visited [ grid . object_id ] = 1 queue = [ grid ] until queue . empty? g = queue . pop next unless g puts "#{g.x},#{g.y},#{g.object_id}" g . neighbours . values . each do | n | next if ! n || visited [ n . object_id ] queue . unshift ( n ) visited [ n . object_id ] = 1 end end end
It does breadth-first search (BFS) to traverse the graph of grids
It does breadth - first search ( BFS ) to traverse the graph of grids
# Skip if nil # Print its coordinates # Skip it if nill or already visited # Add to the queue # Mark as visited