Skip to content

Instantly share code, notes, and snippets.

@jaz303
Last active December 21, 2015 18:59
Show Gist options
  • Select an option

  • Save jaz303/6351216 to your computer and use it in GitHub Desktop.

Select an option

Save jaz303/6351216 to your computer and use it in GitHub Desktop.
simple bfs
for cell in map do
cell.visited = false
end
biome_search_type = 'lake'
contiguous_cells = []
queue = [start_cell]
start_cell.visited = true
while queue.length > 0
cell = queue.shift
if cell.type == biome_search_type
contiguous_cells.push(cell)
for neighbour_cell in cell.neighbours
unless neighbour_cell.visited
neighbour_cell.visited = true
queue.push(neighbour_cell)
end
end
end
end
# `contiguous_cells` contains all neighbour cells with the desired biome type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment