const int RED = 0;const int BLUE = 1;const int GREEN = 2;struct{ bool alive; int color;} grid[10][10];
Now we use fun old recursion[smile]. I thought up a function that uses recursion to eliminate every block of the same color that is touching the block specified. Here would be the prototype:
void Check(int x, int y, int color);
The x and y parameters specify what block to check for. So here would be the implementation:
void Check(int x, int y, int color){ // Check to see if current block should be eliminated if(grid[y][x].alive && grid[y][x].color == color) { // Eliminate block grid[y][x].alive = false; // Check all blocks touching this block Check(x - 1, y, color); Check(x + 1, y, color); Check(x, y - 1, color); Check(x, y + 1, color); }}
Now I realize that one main problem with this code is that a block that is checked will refer back to a previously checked block.
Hope someone finds this useful[smile]
Basically, you have to come up with some way to set what you have checked as "checked", and just "return" when you are checking something that has already been checked.
Its a pretty good method.