Use clues on the gameboard to deduce locations of mines. Correctly reveal all non-mine squares to win.
gem install minesweeprb
minesweeprb
A gameboard is composed of a number of squares laid out in a rectangle.
A square holds either a Clue or a Mine
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 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.
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)
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.
Reveal all Clue Squares without revealing a Mine.
- Flags
✖ ⍰
- Square
◼
- Clues
◻ ➊ ➋ ➌ ➍ ➎ ➏ ➐ ➑
- Mine
☀
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