

1) ‘#’ (HASH) represents an unrevealed mine.
2) ‘.’ (DOT) represents an unrevealed empty cell.
3) ‘_’ (UNDERSCORE) represents a revealed blank cell that has no neighbouring mines.
4) Digits (‘1’ to ‘8’) represents the number of neighbouring mines corresponding to the current cell.
5) ‘*’ (ASTERISK) represents a revealed mine.
1) If the revealed cell contains a mine (‘#’), then the game is over - change it to ‘*’.
2) If the revealed cell is empty ('.') with no neighbouring mines revealed, then change it to revealed blank ('_'), and all of its neighbouring unrevealed cells should be revealed recursively.
3) If the revealed cell is empty ('.') with at least one neighbouring mine revealed, then change it to a digit ('1' to '8') representing the number of neighbouring mines.
1) Two cells are neighbours if they share a corner or an edge, i.e., cells corresponding above, below, left, right, and all four diagonals.
2) For simplicity, ignore the rules which are not mentioned in this problem. For example, when the game is over, you don't need to reveal all the unrevealed mines.
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains two single-spaced integers, ‘M’ and ‘N’, representing the number of rows and columns of the matrix, respectively.
The next ‘M’ line contains ‘N’ single-spaced elements.
The last line of each test case contains two single-spaced integers, ‘x’ and ‘y’, representing the row and column indices of the click position, respectively.
For each test case, return the updated game board when no more cells can be revealed.
The output of each test case will be printed in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= M, N <= 50
0 <= x <= M - 1
0 <= y <= N - 1
data ∈ {‘#’, ‘*’, ‘.’, ‘_’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’}
Where ‘data’ is the value of the elements of the matrix, "gameBoard".
The click position will correspond to an unrevealed cell ('#' or '.'), which also means the input board contains at least one clickable cell.
The input board is not provided at a stage when the game is over (some mines have been revealed).
Time Limit: 1 sec
The idea is to use the DFS algorithm to perform the traversal on the board.
As defined in the rules, if the click position represents a mine ‘#’, we will mark it ‘*’ and stop the traversal. Otherwise, if the click position represents an empty cell, then we will traverse according to neighboring mines.
So, if the current cell (i.e., click position) is surrounded by neighboring mines, we will update the current cell by the number of neighboring mines. If not, then the current cell will be updated by ‘_’, and we will continue our search for its eight neighboring cells.
Algorithm:
Description of ‘revealAndUpdate’ function
This function will take five parameters :
void revealAndUpdate('GAMEBOARD', ‘M’, ‘N’, ‘X’, ‘Y’):
Description of ‘countNeighbouringMines’ function
This function will take five parameters :
void countNeighbouringMines(GAMEBOARD, ‘M’, ‘N’, ‘X’, ‘Y’):
The idea is to use the BFS algorithm for traversing and updating the board.
First, we will check whether the cell at the given click position is mine or not. If yes, then we will return the board after updating the cell at click position by ‘*’. Otherwise, we will perform the BFS on the given board using a queue and update the cells as per the mentioned rules.
Algorithm: