Minesweeper game implemented using Haskell with Cabal. This is a mini-project that I made for the 'EMURGO Cardano Developer Associate' course.
The game consists of a board of selectable cells, where some of the cells contain hidden mines. The objective is to clear the board without detonating any mines.
For a quick overview, check the Google Minesweeper online.
Workflow
- Make Config
- Ask for player name
- Ask for difficulty
- Make Game
- Make board
- Generate random positions for mines
- Make cell
- Calculate adjacent mines for each cell
- Make board
- Run Game
- Check game state
- If Lost or Won, then
- Uncover board
- Show board -> Game ends
- If On, then
- Show board
- Ask for position
- Update board
- Update game state
- Run game (loop)
- If Lost or Won, then
- Check game state
Example
Easy board (5x5)
Covered board Uncovered board
1 2 3 4 5 1 2 3 4 5
1 - | - | - | - | - | 1 | | 1 | 1 | 1 |
------------------------------ ------------------------------
2 - | - | - | - | - | 2 | | 1 | * | 1 |
------------------------------ ------------------------------
3 - | - | - | - | - | 3 | 1 | 1 | 2 | 1 |
------------------------------ ------------------------------
4 - | - | - | - | - | 4 | 1 | * | 1 | |
------------------------------ ------------------------------
5 - | - | - | - | - | 5 | 1 | 1 | 1 | - |
------------------------------ ------------------------------
Legend
Display | Description | Cell state |
---|---|---|
'-' | Covered cell | Mine or [0,8] |
'*' | Uncovered mine cell | Mine |
' ' | Uncovered empty cell with no surrounding mines | 0 |
[1,8] | Uncovered empty cell with N surrounding mines | [1,8] |
- Clone this repo
- Open a cmd shell
- Run
cabal update && cabal install --only-dependencies
Instead of setting up Haskell/Cabal in your local system, you can make use of this Haskell - Official Image as your development environment.
- Clone this repo
- Open a cmd shell
- Run:
# Creates a container using the haskell:latest official image # Mounts the repo folder into the '/app' folder inside the container # Opens a bash terminal inside de container docker run --name <container name> -it -v <repo absolute path>:/app haskell:latest /bin/bash # Example: # docker run --name minesweeper-game -it -v H:\haskell-minesweeper:/app haskell:latest /bin/bash
- Inside the container terminal, run
cd /app
to move to the repo folder - Run
cabal update && cabal install --only-dependencies
All done! Your docker container is ready. Run cabal run
to play the game.
Read Usage > Docker section to know how to start the container once exited.
- Run
cabal run
to play the game
- Run
docker start minesweeper-game
to start the container - Run
docker exec -ti minesweeper-game /bin/bash
to enter into the container - Once inside, run
cd /app
- Run
cabal run
Some useful commands:
- Run
cabal repl --build-depends random
to load therandom
lib into ghci - Run
cabal build
to build the game