Minesweeper

Minesweeper GUI with classical graphics, a persistent leaderboard, and an auto-solution engine
2.7K Downloads
Updated 20 Jun 2014

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

-------------------------------------------------------------------------------------------------------------------------------
UPDATE:
-------------------------------------------------------------------------------------------------------------------------------
The latest update adds public methods to the Minesweeper class that support external control of the GUI.
The included script AItest.m shows how to connect a custom "artificial intelligence" function to the GUI and programmatically make left/right-clicks.

CHALLENGE: Write your own AI engine to solve Minesweeper puzzles. Can you beat the speed and/or accuracy of the built-in EngineMove() method?

Feel free to share your AI code! I'd love to see your solution :)
-------------------------------------------------------------------------------------------------------------------------------

Syntax: Minesweeper();
Minesweeper(level);
Minesweeper(nRows,nCols,nMines);

Inputs: level = {'Beginner','Intermediate','Expert'}
(nRows,nCols) = (#rows,#columns)
nMines = #mines

Description: This class generates a fully-functional Minesweeper GUI with beginner, intermediate,
expert, and custom levels, a persistent leaderboard, classical graphics, hints, and an
artificial intelligence (AI) auto-solution engine.

Objective: Uncover all safe squares without touching a mine. The numbers on each square denote the
number of mines adjacent to that square.

Controls: Left-click a square to open it. Right/CMD/CTRL-click a square to flag it as a
mine. For your safety, flagged squares cannot be left-clicked. Right/CMD/CTRL-click a flag
to remove it. Once you have flagged the appropriate number of mines adjacent to a
given square, you can left-click that square to cascade open its unflagged adjacent squares.
Finally, click the smiley button to reset the board, and change the board size through the
GAME menu.

Hints: Use the HINT menu to have a safe square opened for you when you are stuck. However,
note that using a hint will disqualify your time from appearing on the leaderboard.

Auto-solution: Use the SOLVE menu to invoke auto-solution mode. You can stop the solver
at any time by clicking the red stop button. Naturally, using the auto-solver will disqualify
your time from appearing on the leaderboard.

Author: Brian Moore
brimoor@umich.edu

Cite As

Brian Moore (2024). Minesweeper (https://www.mathworks.com/matlabcentral/fileexchange/46145-minesweeper), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Minesweeper in Help Center and MATLAB Answers
Acknowledgements

Inspired: Mastermind

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.8.0.0

Improved handling of GUI children handles

1.7.0.0

Adding public methods to allow programmatic control of the GUI.

CHALLENGE: One can now easily design an external AI function to auto-solve a puzzle. Can you beat the speed and/or accuracy of the internal EngineMove() method?

1.6.0.0

Adding support for mouse right-click mine flagging (last update accidentally broke this...)

1.5.0.0

Adding close hot-keys support to auxiliary figures

1.4.0.0

Fixing description typo

1.3.0.0

Adding board reset accelerator

1.2.0.0

Fixing description typo

1.1.0.0

Fixing title typo

1.0.0.0