R/reveal.R

Defines functions reveal

reveal <- function(board, i, j, nrow, ncol) {
  if(board[[i, j]] != "-") return(board)
  if(attr(board, "mines")[[i, j]]) {
    update_smiley("X(")
    board <- update_cell(board, "M", i, j)
    board <- update_cells(board, "m", board == "-" & attr(board, "mines"))
    board <- update_cells(board, "X", board == "F" & !attr(board, "mines"))
    attr(board, "lock") <- TRUE
    return(board)
  }
  nbors <- neighbors(i, j, nrow, ncol)
  if((surrounding_mines <- sum(attr(board, "mines")[nbors])) == 0) {
    board <- update_cell(board, " ", i, j)
    return(reveal_surrounding(board, nbors, nrow, ncol))
  }
  update_cell(board, surrounding_mines, i, j)
}

Try the minesweeper package in your browser

Any scripts or data that you put into this service are public.

minesweeper documentation built on April 3, 2025, 9:29 p.m.