- Table of Contents
- Description
- Rules
- Generation of random boards
- Requirements
- Installation
- Modes
- Credits
My personal implementation of the classic Minesweeper game.
- The objective of the game is to open all cells not containing mines. If the player opens a cell containing a mine they lose the round. Note that when opening a cell there are three options to its contents:
- containing a bomb
- containing a the number of adjacent cells that contain bombs
- empty (no adjacent cells contain bombs)
- The player is capable of the 3 following actions
This will open a single cell. If the cell contains a bomb the player dies. If it contains a number then only the opened cell is opened. If is empty all adjacent cells are opened. That is empty cells can perform a Depth First Search that terminates on number cells.
This can be used to mark a cell as having a bomb. This is useful for chording as seen below.
If a given number cell has a number of flags adjacent equal to its number it can be chorded. This means all non-flagged unopened cells will be opened as if they were opened as in (1). If a flag is not properly assigned (i.e. flagging a cell that does not contain a bomb) this could lead to the player’s death.
Note that in this particular implementation mines will not be laid until the player firsts opens a cell. This is a usability measure to prevent the player from dying on their first cell opening. A random puzzle of a board with m
rows, n
columns, and k
(with k < m * n
) mines is generated by taking a list all cell coordinates ((m * n) - 1
to be exact as we exclude the player’s first choice), shuffling said list, and then placing mines on the first k
coordinates in the list. Since a shuffle of l
items can be done in O(l)
time (See the Fisher Yates algorithm) this would mean that our puzzle generation would take at most O(m * n)
.
This particular generates random boards of the following preset difficulties (EASY, MEDIUM, HARD) as well as user specified row, col, mine counts. A summary is listed in the table below
difficulty | rows | cols | mines |
---|---|---|---|
EASY | 10 | 10 | 10 |
MEDIUM | 16 | 16 | 40 |
HARD | 16 | 30 | 99 |
CUSTOM | user specified | user specified | user specified |
3.6 <=
Python<= 3.8.12
- For specific Python packages see
requirements.txt
.
- Unzip the
.zip
file. cd
into the top root directory of the unzipped file.- Install dependencies
pip install -r requirements.txt
- Run the main script
./main.py
- Follow instructions on terminal to choose TUI or GUI mode.
- Navigate to the following link: https://repl.it/@jatsang52/minesweeper#main.py
- In the repl.it terminal, install dependencies with
pip install -r requirements.txt
- After the installation completes press the
Run
button. - In the repl.it terminal choose TUI or GUI mode.
- In the repl.it terminal if you choose GUI mode make sure to choose option
1
to disable sound (repl.it doesn’t play nicely with pygame apps with sound)
- After pressing
Play
left click anywhere to start the game. - Mouse controls
control action left click open cell right click toggle flag middle click chord cell - Keyboard controls
key action q
Quit to main menu
- Follow menu directions on screen.
Number icons made by Freepik from www.flaticon.com
Bomb Icons made by Freepik from www.flaticon.com
Flag Icons made by Vectors Market from www.flaticon.com
Square Icons made by Freepik from www.flaticon.com
Emoticon Icons made by Pixel perfect from www.flaticon.com