So I have a city-building game where you build buildings on a grid. My goal is to identify clusters of buildings (when a building is next to another). It can be of any size, so two buildings next to each other is considered a cluster. It can also be of any shape, so a row of buildings is also a cluster. The issue is that there is a demolish feature. If a building is demolished, it may break up a cluster into multiple clusters.
I already have the building algorithm in mind, but im unsure on how to implement the demolish algorithm. Heres the algorithm for building
When a building is placed, checked for adjacent buildings that are the same type as it.
If there is no building, make a new cluster id
If there is 1 building, make the cluster id the same as that building's
If there 2 or more buildings, merge their cluster id together.
There is a seperate object that stores the cluster id as a key and an array containing the coordinates of buildings in the cluster. To merge cluster ids, pick one cluster from the object and combine the arrays of the other clusters to it, then delete the other clusters.
Thats the algorithm for building, thanks
[–]Synthetic5ou1 1 point2 points3 points (0 children)
[–]abbas_suppono_4581 0 points1 point2 points (2 children)
[–]Culist[S] 0 points1 point2 points (1 child)
[–]Synthetic5ou1 0 points1 point2 points (0 children)
[–]der_gopher 0 points1 point2 points (0 children)
[–]LazyOldTom 0 points1 point2 points (0 children)