Question

I know that the title of this topic might be confusing, but I didn't know how to explain it in a single sentence! I'll try to be more clear, I have a 2d array of boolean values, every value states if that particular position (or block) is alive or not.

Let's make an example:

1 1 1 1
1 1 1 1
1 1 1 1
1 1 1 1

This array contains 16 "alive" blocks, now I can "kill" some blocks, changing their state from 1 to 0. What I would like to do is to know if after a "kill", the group splits in two or more separate groups, for example:

1 1 0 1
1 1 0 1
0 1 0 1
1 1 1 1

This shape is still "intact", since the group of 0 is not cutting any of the 1 groups, but in this case:

1 1 0 1
1 1 0 1
0 0 0 1
1 1 1 1

Now I've killed the only bit who was keeping all the 1 together, the shape has been divided in two smaller groups! I've tried checking the neighbours of the last killed bit but then I can't be sure of other possible connection of the shape. I've also tried a pathfinding algorithm but this operation should be very fast and a pathfinding is too complex. How can I achieve this?

Was it helpful?

Solution

Pick any of the alive blocks and do a flood-fill and then check if it got to all the other live blocks.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top