Minesweeper is a simple one−player computer game commonly found on machines with popular operating systems such as Linux or Microsoft Windows. The object of the game is to clear an abstract minefield without detonating a mine.
The game consists of a 2 dimensional rectangular playing field (or board) where some known numbers of mines have been hidden. Initially, all of the squares on the board are "covered up" and no information is given to indicate the location of the mines. The player’s job is to either deduce or guess which board squares are clear of mines and step there to reveal a number. If successful, this number will indicate the number of mines to be found in the squares adjacent to the square with the number. Obviously, the first move of the game must be a guess because no information has been provided. Since the board is a rectangular grid, each interior square has exactly 8 neighbouring squares, edge squares have 5 neighbours, and corner squares have 3 neighbours. Therefore, the number found under any given square will be in the range of 0 to 8 (inclusive). Game play continues until the player has uncovered (or "stepped" on) each and every square that does not hide a mine, while successfully avoiding all of the mines. If the player can do this, they are considered to have won the game. However, if at any point the player attempts to uncover a square that contains a mine, the game immediately ends and the player is said to have lost.
Any suggestions and bug - fixes are welcome.
The code has been written using GUIDE.
I haven't tested this code on any other platform except R2009a (Matlab 7.8) so am not sure whether it will work for the previous versions of Matlab.
Mihir Shah (2021). Minesweeper (https://www.mathworks.com/matlabcentral/fileexchange/28228-minesweeper), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform CompatibilityWindows macOS Linux
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!