Minesweeper
Use clues on the gameboard to deduce locations of mines. Correctly reveal all non-mine squares to win.
Screenshots
Install
gem install minesweeprb
Run
minesweeprb
Rules
A gameboard is composed of a number of squares laid out in a rectangle.
A square holds either a Clue or a Mine
Clue Square
A Clue Square will contain a number representing the numbers of mines that border itself. If the Clue Square has no neighboring mines then it will be blank.
For example, a Clue Square containing a "1" will have exactly one mine in one of the spaces that borders itself. There is a mine in exactly one of the ◼ squares.
◼ ◼ ◼
◼ 1 ◼
◼ ◼ ◼
There are no mines surrounding an empty square. Note: Revealing an empty square will reveal all neighboring Clue Squares automatically. For example revealing the square where '▣' is placed (B2) could result in the gameboard looking something like:
◼ ◼ ◼ ◼ ◼ ◻ ◻ 1 ◼ ◼
◼ ▣ ◼ ◼ ◼ ◻ ◻ 1 ◼ ◼
◼ ◼ ◼ ◼ ◼ → 1 2 2 ◼ ◼
◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼
◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼ ◼
where '◻' is an empty Clue Square.
In the example below, there are exactly three mines surrounding the "3" square. Because the "3" Clue Square only has three unrevealed spaces bordering itself, it is correct to assume that there is mine in each space.
3 ◼ ◼ 3 ✖ ◼
◼ ◼ ◼ → ✖ ✖ ◼
◼ ◼ ◼ ◼ ◼ ◼
Mine Square
Mine Squares should not be revealed. If you believe you have found the location of a Mine then you can flag that square to prevent accidentally revealing it.
Gameboard
A gameboard contains a Width, Height, and Number of Mines.
The first move is always safe which means a gameboard's Mines are not placed until the first square is revealed.
Since the first move is always safe, a gameboard is only valid if the number of mines is less than the total number of squares. A valid gameboard must have more than one square. (i.e., 0 < # of Mines < Width * Height)
How To Play
Reveal squares you believe do not contain a Mine.
Your first move will never reveal a Mine.
If you reveal a square that contains a Mine, the game will end.
How To Win
Reveal all Clue Squares without revealing a Mine.
ASCII Reference
- Flags
✖ ⍰
- Square
◼
- Clues
◻ ➊ ➋ ➌ ➍ ➎ ➏ ➐ ➑
- Mine
☀
TODO
Extract Gameboard- Simplify logic
-
Repaint only what's necessarySeparate squares and timer into separate window?
Implement timer- Add Leaderboard
Add custom games (set width, height, and number of mines)- Add peek mode, undo, or lives to help users learn
- restarting a game brings back to prompt instead of generating a new board of the same dimensions
- Splash screen