packages feed

minesweeper-0.8.8: Configuration.hs

module Configuration 
    ( Configuration
        ( Configuration
        , size
        , mines           
        , strategy 
        , deathProbRange
        , allowedDeaths   
        , recursiveReveal 
        , undoAllowed
        , hintAllowed
        )
    , numOfSolutions
    , Strategy (..)
    , HintType (..)
    , Probability
    , configuration'
    ) where

import Core.Square
import Core.Constraints

import Control.Monad
import Data.Binary
import Data.DeriveTH
import Data.Derive.Binary

----------------------------------

data Configuration 
    = Configuration
        { size            :: Board
        , mines           :: Int
        , numOfSolutions_ :: Integer    -- cached, determined by size and mines

        , strategy        :: Strategy
        , deathProbRange  :: (Probability, Probability)  
            -- (a, b): ha p valséggel halnánk meg, akkor p>a esetén meghalunk, p<b esetén életben maradunk
       
        , allowedDeaths   :: Int
        , recursiveReveal :: Bool

        , undoAllowed     :: Bool
        , hintAllowed     :: Maybe HintType
        }
        deriving (Eq, Ord, Show)

data Strategy
    = Random
    | HighestProb
        deriving (Eq, Ord, Show, Enum)

data HintType
    = NormalHint 
    | FullHint
        deriving (Eq, Ord, Show, Enum)

type Probability 
    = Rational


---------------------------------

numOfSolutions :: Configuration -> Integer
numOfSolutions = numOfSolutions_

configuration' :: Configuration -> Configuration
configuration' c 
    = c { numOfSolutions_ = solutions $ initConstraints (size c) (mines c) }

------------------------

$( derive makeBinary ''HintType )
$( derive makeBinary ''Strategy )
$( derive makeBinary ''Configuration )