edit: This is getting down voted but it's not been made clear what data structure I should be using instead of a list of coordinates. Unfortunately my data comes as a flat list and it needs to be distributed with in an outwards clockwise spiral. Then run a BFS on that to work out islands. I used coordinates which is what the C++ code tutorial seem to do (I have zero C++ experience though) but seems that was a bad route to take in Haskell
I'm trying to accumulate a list of touching land cells grouped by islands.
Looking at the image bellow I'd expect 5 islands and each with the cells on that island. [[Cell]]
.
My input is currently a flat list of cells ordered in a clockwise spiral (red dotted line) and a number of the population of the cell. 0
making it sea and any >= 1
is the population.
data Cell = Cell
{ cellLoc :: (Int, Int)
, cellpop :: Int -- 0 sea, >= 1 population of land
}
startingCellList :: [Cell]
startingCellList =
[(Cell (1,0) 0)
,(Cell (1,-1) 0)
,(Cell (0,-1) 0)
,(Cell (-1,-1) 4)
]
The cellLoc
gives me coordinates of cell in an X Y plane with (0,0)
being at the centre of the grid. Am I right in thinking I can use the those coordinates to run my BSF?
Or do I need to rethink the use of coordinates to achieving my grid?
I've also found this great example but I'm not grasping it's use of vertexes and how or if I can relate it to using coordinates.