AS3 - This broke my brain, help!

Hi Guys,

I’m stuck with some game logic and just cant figure it out, can someone please help???

Scenario:

The game consists of matching pieces of the same type and removing them from screen, sort of like a “Match 3” game, but instead of 3 you can match more than 3 of the pieces as long as they connect and of the same type.

The game grid is saved in an array which stores row and column position.
I need to go through the array and verify if the pieces are together and if more than 3 are connected then they will be removed from the screen.

Examples:

X’s should be removed

0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 X 0 0 0 0 0
0 X 0 0 0 0 0
0 X X X X 0 0


0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 X X 0 0 0 0
0 0 X X X 0 0
0 0 0 0 0 0 0

I have tried several different ways but I’m burned out, cant think no more

Attached is the test FLA I’m using to figure out the logic.

Usage: Compile and the click on the squares, after the 4th in a row the pieces return to their original state.
But if you have 3 in a row, and then 2 in a row on another column or row the 5 will disappear and only when connected they should disappear.

I hope I’m clear,

Please help, I’m desperate!

Thanks!!!