Click a covered board and watch the reveal spread one breadth-first ring at a time: zeros open their neighbours, numbers stop the flood (LeetCode 529). O(R × C) time and space.
About this algorithm
When you click a Minesweeper cell with no mines around it, the game opens a whole region at once: every connected blank cell plus the border of numbered cells around it. That reveal is a breadth-first search from the click over all 8 neighbours. Blank cells spread it, and numbered cells open but stop it. This is LeetCode 529.
Use this pattern when a fill should spread through some cells and halt at others that still get shown, like the numbered border here, or a paint bucket that colours a region together with its outline. It differs from the plain grid BFS page in two ways: it looks at 8 neighbours, diagonals included, instead of 4, and it has no target, so it runs until the queue is empty. A recursive DFS opens exactly the same set of cells. The queue is used here because it shows the region opening ring by ring, and it cannot overflow the call stack on a huge empty board.
If the click is on a mine, the game is lost. Otherwise put the cell in a queue and mark it as seen.
Take the front cell off the queue and count the mines among its 8 neighbours.
If the count is above 0, show the number and queue nothing. A mine is close by, so not every neighbour is safe to open.
If the count is 0, the cell opens blank and every neighbour not yet seen joins the back of the queue. None of them can be a mine, because the blank cell has no mine next to it.
The region is complete when no blank cell has anything left to add.
The page opens on an 8 by 10 board with 10 mines, clicked at row 4, column 4 (counting from 0). The click has no mines around it, so it opens blank and queues its 8 neighbours. In that first ring, (3, 3) and (3, 4) show 2 and (3, 5) shows 3, because a row of three mines sits just above at (2, 4), (2, 5) and (2, 6). Those numbers do not spread. The blank cells keep pushing outward, and the region opens in 7 rings of 1, 8, 10, 10, 8, 7 and 5 cells: 49 of the 80 cells, 27 blank and 22 numbered. The numbers form a fence, such as 1 1 2 2 3 2 1 1 along row 3, and everything behind it, all 10 mines included, stays covered. Generate New deals a fresh board.
Many versions of the game, and this page's new boards, keep the first click and its 8 neighbours free of mines, so the first click is always a 0. This page also re-deals until the click opens at least 20 cells, so every new board shows a real flood.
Time: each cell joins the queue at most once and looks at its 8 neighbours twice, once to count mines and once to queue them, a fixed amount of work per cell. Space: the seen marks cover the board, and on a mostly empty board the queue holds a long ring of cells at once.