I'm designing an engine for a game which has a 2D array like this:
0,1,1,2,0
0,1,2,1,1
1,0,1,0,2
2,1,2,0,0
2,0,1,0,0
I'm stuck at the "game over" condition as it has to check if the 1's or 2's are connected. It should declare the player with 1's as winner and return this:
1 1
1 1 1
1 1
1
1
1
I've tried using recursion by checking every position in the array and checking its neighbors in all 8 directions but the method took 45 seconds to run which is inefficient.
Does anyone have any ideas? A pseudo-code example would be appreciated (I'm a slow learner).
What you need is that:
Connected_component_labeling
This gives a pseudo code,
hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With