Package 'minesweeper'

Title: Play Minesweeper
Description: Play and record games of minesweeper using a graphics device that supports event handling. Replay recorded games and save GIF animations of them. Based on classic minesweeper as detailed by Crow P. (1997) <https://minesweepergame.com/math/a-mathematical-introduction-to-the-game-of-minesweeper-1997.pdf>.
Authors: Harry Thompson [aut, cre, cph]
Maintainer: Harry Thompson <[email protected]>
License: MIT + file LICENSE
Version: 1.0.1
Built: 2024-11-25 15:25:14 UTC
Source: CRAN

Help Index


Start a Minesweeper Game

Description

Play minesweeper interactively in the current graphics device.

Usage

play_minesweeper(
  difficulty = c("expert", "intermediate", "beginner"),
  nrow = NULL,
  ncol = NULL,
  mine_count = NULL,
  mine_density = NULL,
  os_type = c("guess", "unix", "windows")
)

Arguments

difficulty

establishes default dimensions and mine count

nrow, ncol

dimensions of the minesweeper board

mine_count

number of mines to sweep

mine_density

proportion of cells that conceal a mine

os_type

used to interpret button argument of event handlers

Details

Expert difficulty is 16x30 with 99 mines, intermediate 16x16 with 40 mines, and beginner 9x9 with 10 mines.

The current graphics device must support event handling (see grDevices::getGraphicsEvent()). If onIdle is not supported, the timer will only update on mouse events.

Value

Object of class "minesweeper_recording" to pass to replay_minesweeper() or save_minesweeper_gif(), invisibly.

Controls

  • Left click an empty square to reveal it.

  • Right click an empty square to flag it.

  • Middle click a number to reveal its adjacent squares.

  • Press r to reset the board.

  • Press q to quit.

Examples

x11() # Unix-specific example
recording <- play_minesweeper()
dev.off()

Replay a Minesweeper Recording

Description

Replay a recorded game of minesweeper in the current graphics device.

Usage

replay_minesweeper(recording)

Arguments

recording

object of class "minesweeper_recording" returned by play_minesweeper()

Value

recording, invisibly.

Examples

x11() # Unix-specific example
recording <- play_minesweeper()
replay_minesweeper(recording)
dev.off()

Save a Minesweeper Recording to GIF

Description

Save a recorded game of minesweeper to a GIF file.

Usage

save_minesweeper_gif(
  recording,
  gif_file = "animation.gif",
  width = 800,
  height = 600,
  delay = 1,
  loop = TRUE,
  progress = TRUE,
  ...
)

Arguments

recording

object of class "minesweeper_recording" returned by play_minesweeper()

gif_file

output gif file

width

gif width in pixels

height

gif height in pixel

delay

time to show each image in seconds

loop

if the gif should be repeated. Set to FALSE to only play once, or a number to indicate how many times to repeat after the first.

progress

print some verbose status output

...

other graphical parameters passed to png

Details

Reduce the delay for greater temporal resolution.

Value

The file path of the GIF file.

Examples

x11() # Unix-specific example
recording <- play_minesweeper()
save_minesweeper_gif(recording)
dev.off()