I am developing a game engine with a two-dimensional 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 am stuck in a βgameβ state because he needs to check if 1 or 2 are connected. He must declare the player with 1 winner and return him:
1 1
1 1 1
1 1
1
1
1
I tried using recursion by checking each position in the array and checking its neighbors in all 8 directions, but it took 45 seconds to complete this operation.
Does anyone have any ideas? The pseudo-code example will be appreciated (I'm a slow learner).
source
share