Last active
December 21, 2015 18:59
-
-
Save jaz303/6351216 to your computer and use it in GitHub Desktop.
simple bfs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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