I am currently doing a clone of Minesweeper. I made an algorithm that, by clicking on a plate with 0 surrounding mines, shows all neighbors with 0 surrounding mines, and then all of their neighbors with 0 surrounding mines ... (recursion). This result requires only one click:

It works as it should, but it is too slow. The original Minesweeper shows these tiles instantly, but in my case they have a slight delay between the readings.
I wrote this code:
private void RevealNeighbor(int x, int y) { foreach(var neighbor in _neighbors) { try { Tile tile = _tiles[x + neighbor[0], y + neighbor[1]]; if(tile.TileType == TileType.Empty && tile.Hidden) { tile.Reveal(); if(tile.Number == 0) { RevealNeighbor(x + neighbor[0], y + neighbor[1]); } } } catch(IndexOutOfRangeException) { } } }
_neighbors - an array of arrays that has 8 position offsets for neighbors:
private readonly int[][] _neighbors = new[] { new[] {-1, -1}, new[] {0, -1}, new[] {1, -1}, new[] {1, 0}, new[] {1, 1}, new[] {0, 1}, new[] {-1, 1}, new[] {-1, 0} };
How can I do it faster?
source share