Portability | portable |
---|---|
Stability | experimental |
Maintainer | Bertram Felgenhauer <int-e@gmx.de> |
This module is part of Haskell PGMS.
It provides types and a monad for implementing and running Minesweeper strategies. It's the core of PGMS.
- data Config = Config {}
- validConfig :: Config -> Bool
- beginner :: Config
- intermediate :: Config
- expert :: Config
- data Pos = Pos {}
- data Cell
- data Board = Board {}
- type View = Array Pos Cell
- neighbours :: Config -> Pos -> [Pos]
- data StrategyM a
- data Strategy = Strategy {}
- defaultStrategy :: Strategy
- move :: Pos -> StrategyM Int
- move_ :: Pos -> StrategyM ()
- mark :: Pos -> StrategyM ()
- getView :: StrategyM View
- getConfig :: StrategyM Config
- traceMine :: String -> StrategyM ()
- data Result a
- = Won
- | Unfinished a
- | Lost
- playGame :: Config -> StdGen -> StrategyM a -> (Result a, Board)
- data Play a where
- playGameP :: Config -> StdGen -> StrategyM a -> Prompt Play (Result a, Board)
Minesweeper configurations
Description of a mine sweeper configuration (or difficulty).
validConfig :: Config -> BoolSource
Check validity of a config.
The width and height must be at least 2, and the number of mines must be between 1 and the number of cells on the board, minus 1.
Default config: 16x16 with 40 mines
Minesweeper boards
A point in 2D space with integer coordinates.
Used to adress cells on a Minesweeper board, and also to describe board sizes.
A cell on a Minesweeper board.
A complete Minesweeper board, including hidden state.
neighbours :: Config -> Pos -> [Pos]Source
Find the neighbouring cells of a given cell.
The Config
parameter is used to find the boundaries of the board.
Minesweeper strategies
A strategy with some meta-information.
It's advisable to define your own strategies in terms of defaultStrategy
so that future additions to that record don't break your code.
defaultStrategy :: StrategySource
Default values for Strategy
.
myStrategy :: Strategy myStrategy = defaultStrategy { sName = "Hiho", sRun = \_ -> return "I don't want to play anymore, see you!" }
move :: Pos -> StrategyM IntSource
Reveal a cell. Returns the number of mines in the neighbourhood.
Note: Revealing a cell with a mine beneath will lose the game.
mark :: Pos -> StrategyM ()Source
Mark a cell.
Note: Marking a cell without a mine beneath will lose the game. This is a deviation from standard Minesweeper.
getConfig :: StrategyM ConfigSource
Get the current board's config.
Note: the config will never change throughout a game.
traceMine :: String -> StrategyM ()Source
Provide a debug message.
These will be displayed in the status line in the GUI or on the terminal when running the command line version in verbose mode.
Running Minesweeper games
A game result.
Won | The game was won. |
Unfinished a | The strategy implementation finished before the game was over. |
Lost | The game was lost. |
UI interface
These are actions for the MonadPrompt
monad.