Minesweeper

 
 

This page links to a selection of implementations of minesweeper in Haskell. These were written in 2002, and were used as a (personal) case study for refactoring Haskell programs. The (non-graphical) versions work in Haskell 2010.


Minesweeper is a long-lived and popular computer game, with a plethora of implementations (just `google' for minesweeper). The game is played on a rectangular board divided into a number of squares; beneath some of the squares lie mines. Clicking on a mine loses the game; if there is no mine present, the square is cleared, and the number of mines on adjacent squares is shown. In fact, if the square is unoccupied then the whole mine-free region containing the square is uncovered. The player wins when all the mines are marked, and all other squares are cleared.

ASCII interface


The basic commands for the textual versions are (details below of which version implements which):

q              Quit

h              Help information

m7b         Mark position 7b

u7b          Unmark position 7b

r7b           Reveal position 7b

s7b          Show equations at 7b

a7b          Automatic turn at 7b

t7b           Transitive automatic from 7b


These commands should not be followed by a newline/carriage return.


Versions


Minesweeper.hs: simple interface: just input row and column character to uncover; to run playGrid.

Minesweeper2.hs; implements q, s, m, u, r. To play, run playGame m n where m is number of mines and n the size of the square.

Minesweeper3.hs; implements q, s, m, u, r, a, t. Play like Minesweeper2.

Minesweeper4.hs; implements q, h, s, m, u, r, a, t. Play like Minesweeper2.

Minesweeper5.hs; implements q, h, s, m, u, r, a, t. Play like Minesweeper2.

MineRandom.hs; gets random starting grid.


Graphical interface (older versions)


The graphical interface is provided using the Haskell Graphics Library and was tested (only) on Windows systems using Hugs. I would welcome feedback on other platforms.


GraphicMine.hs; basic version.

GraphicMine2.hs; adds buttons for other menu options.

GraphicMine3.hs; extends GraphicMine2 by completing options for quit, help, new game, generated randomly, automatic play, showing equations.

GraphicMine4.hs; extends GraphicMine3 by showing equations and adding temporary windows.