Arduino freezing or resetting - looping functions

Hello,
I have got Arduino UNO and 2,8" TFT breakout board. I wrote a simple Minesweeper game and I have got this code

void openCell(int x, int y)
{
  if (x >= 0 && x < board_w && y >= 0 && y < board_h) {
    if (state[x][y] != OPEN) { // if the cell is not open, open it
      state[x][y] = OPEN;
      drawCell(x, y); // draw the opened cell
      if (mines[x][y] != MINE && mines[x][y] == 0) {//open the cells surrounding
        openCell(x - 1, y - 1); 
        openCell(x, y - 1);
        openCell(x + 1, y - 1);
        openCell(x - 1, y);
        openCell(x + 1, y);
        openCell(x - 1, y + 1);
        openCell(x, y + 1);
        openCell(x + 1, y + 1);
      }
    }
  }
  delay(2); // for the slow opening effect
}

for opening the cells in game. When I open the cell, and the surrounding cells are opening, Arduino freezes or resets (goes back to void setup() and the variables are removed). I think it's the problem with code looping... and what should I do? Can You help me solving this problem?

Thanks in advance.
kuba2k2

Just how many stack frames do you think you can get into 2KB?

Use a breadth-first traversal and check for your queue overflowing, depth-first isn't the way
to do flood-fill.