   Clear blocks of the same color, XNA Falling Blocks
  Hey, in this game I'm attempting to make 3 blocks of the same color 'clear' when placed onto my grid (2d array) either horizontally or vertically.  Is there an easier way to perform this check other than recursion? The only way I've been able to think of doing this thus far is to a recursive function call itself to check + 1 or -1 spot on the grid, and add all blocks meeting the correct color to a list for deletion. Is there an easier non-recursive method that I just can't think of? :S   
  Maybe I misunderstood, but why do you need recursion? Whenever a new block appears, you just check the 2 blocks to its left, top, etc.Actually, how does your recursive method works?Also, what does it mean to delete a block? Just mark it as 'empty'?Can you provide more details about how your game works?   ;  Brute force solution to detect horizontal triples:void check_horizontal(){    for (int y = 0; y < HEIGHT; ++y)    {   for (int x = 2; x < WIDTH; ++x)   {  color c = playfield[y][x];  if (c != empty && c == playfield[y][x-1] && c == playfield[y][x-2])  { playfield[y][x-2] = empty; playfield[y][x-1] = empty; playfield[y][x  ] = empty;  }   }    }}A slightly smarter solution that skips several blocks per iteration (not tested):void check_horizontal(){    for (int y = 0; y < HEIGHT; ++y)    {   for (int x = 2; x < WIDTH; )   {  // /---+---+---\---+---+---+  // |x-2|x-1| x |x+1|x+2|x+3|  // \---+---+---/---+---+---+  color c = playfield[y][x];  if (c == empty)  { x += 3;  }  else if (c != playfield[y][x-1])  { x += 2;  }  else if (c != playfield[y][x-2])  { x += 1;  }  else  { playfield[y][x-2] = empty; playfield[y][x-1] = empty; playfield[y][x  ] = empty; ++x;  }   }    }}Of course it would be much faster to only search in the neighborhood of the last block that was placed.   