Choose the Next Minesweeper Action
Problem statement
Choose one next action for a Minesweeper bot from the currently visible board. A revealed number counts mines in its at most eight neighboring cells, including diagonals. Do not include the numbered cell itself.
For this bounded practice exercise, board[r][c] is -1 for an unknown cell, -2 for an already flagged known mine, or a number from 0 through 8 for a revealed safe cell. Flags are assumed correct. Hidden mine locations are not supplied.
Explicit probability model
Assume every assignment of mine or safe to the unknown cells is initially equally likely. Retain exactly the assignments consistent with every visible number and existing flag, then treat those remaining assignments as equally likely. No global mine count is given. The input is guaranteed to admit at least one consistent assignment.
One-step action contract
- If no unknown cell remains, return
[2, -1, -1]forDONE. - If any unknown cell is a mine in every consistent assignment, return
[1, row, col]forFLAG, choosing the first such cell in row-major order. - Otherwise return
[0, row, col]forREVEALat the unknown cell with the lowest mine probability across all consistent assignments. Break ties by row-major order.
Coordinates are zero-based. Return only the action; do not mutate the board or simulate a reveal. The prior, board encoding, flag priority, tie rule and finite one-step scope are authored practice definitions. Minimum immediate reveal risk under this model does not claim a globally optimal strategy for winning a complete game.
Function
nextMinesweeperAction(board: int[][]) → int[]Examples
Example 1
board = [[0,-1],[-1,-1]]return = [0,0,1]All three unknown neighbors are safe in every consistent assignment; reveal the first in row-major order.
Example 2
board = [[1,-1]]return = [1,0,1]The single unknown neighbor must be a mine; return FLAG at row0column1.
Example 3
board = [[-1,-1]]return = [0,0,0]Both unknown cells have mine probability one-half under the explicit prior; reveal row0column0 by the tie rule.
Constraints
- The rectangular board has from
1through4rows and columns. - There are at most
15unknown cells. - Every entry is
-2,-1, or an integer from0through8. - Every revealed number is consistent with at least one assignment to all unknown cells, treating existing flags as mines.
- Use all visible clues together; assignments outside the board do not exist.