Safe HaskellSafe

Game.Types

Synopsis

Documentation

data BoardCoordinate #

position of a cell on the board

Constructors

BoardCoordinate

BoardCoordinate column row

Fields

data GameAction #

a move in the game played by the player

Constructors

Reveal BoardCoordinate

reveal a single cell

RevealArea BoardCoordinate

reveal all adjacent safe cells if possible

ToggleFlag BoardCoordinate

toggle flag/unsure on cell

Undo

undo last Reveal / RevealArea action

data GameState #

represents the complete and consistent state of the game in a given point in time

Constructors

GameState

GameState config Maybe previousState cellStates globalGameState

Fields

Instances
Eq GameState # 
Instance details

Defined in Game.Types

Methods

(==) :: GameState -> GameState -> Bool

(/=) :: GameState -> GameState -> Bool

undo :: GameState -> GameState #

return the previous game state to undo last reveal

if no previous state is available, the same state is returned

data GameConfig #

Board configuration for a new game

Constructors

GameConfig

GameConfig width height numMines

Fields

Instances
Eq GameConfig # 
Instance details

Defined in Game.Types

Methods

(==) :: GameConfig -> GameConfig -> Bool

(/=) :: GameConfig -> GameConfig -> Bool

totalCells :: GameConfig -> Int #

total number of cells for this GameConfig

data PlayState #

current win/lose state of the game

Constructors

Playing

game is still running

Win

the player won

Dead

the player lost

Instances
Eq PlayState # 
Instance details

Defined in Game.Types

Methods

(==) :: PlayState -> PlayState -> Bool

(/=) :: PlayState -> PlayState -> Bool

data GlobalGameState #

global states of the game calculated from all cell states

Constructors

GlobalGameState

GlobalGameState remainingMines freeCells playState

Fields

Instances
Eq GlobalGameState # 
Instance details

Defined in Game.Types

data InternalCellState #

internal (non-visible) state of a cell

Constructors

Safe

the cell does not contain a mine

Mine

the cell does contain a mine

Undefined

it is not fixed yet whether this cell will contain a mine

Instances
Eq InternalCellState # 
Instance details

Defined in Game.Types

data VisibleCellState #

state of a cell visible to the player

Constructors

Unknown

cell is still hidden

Known

cell is open (and contains a mine)

Flagged

cell was falgged by the player

Unsure

cell was flagged as unsure by the player

Labeled

cell was revealed and shows the number of adjacent mines

Fields

  • totalLabel :: Int

    total number of adjacent mines

  • countdownLabel :: Int

    remaining number of adjacent mines based on set flags

Instances
Eq VisibleCellState # 
Instance details

Defined in Game.Types

data CellState #

the state of cell on the board

Constructors

CellState

CellState internalState visibleState

Fields

Instances
Eq CellState # 
Instance details

Defined in Game.Types

Methods

(==) :: CellState -> CellState -> Bool

(/=) :: CellState -> CellState -> Bool

Semigroup CellState # 
Instance details

Defined in Game.Types

Methods

(<>) :: CellState -> CellState -> CellState

sconcat :: NonEmpty CellState -> CellState

stimes :: Integral b => b -> CellState -> CellState

Monoid CellState # 
Instance details

Defined in Game.Types

type CellStates = [[CellState]] #

rows and columns of cells representing the game board

isMine :: CellState -> Bool #

whether a cell (definitely) contains a mine

isSafe :: CellState -> Bool #

whether a cell (definitely) contains no mine

isUndefined :: CellState -> Bool #

whether the content of the cell was not fixed yet

isFlagged :: CellState -> Bool #

whether the cell was flagged by the player

isKnown :: CellState -> Bool #

whether the cell is revealed

cellFromState :: BoardCoordinate -> CellStates -> CellState #

get cell on specific coordinate from cellStates

countCells :: (CellState -> Bool) -> [CellState] -> Int #

count cells in list matching the predicate

countInState :: (CellState -> Bool) -> CellStates -> Int #

count cells in cellStates matching the predicate