board-games-0.1.0.6: Three games for inclusion in a web server

Game.Mastermind

Synopsis

# Documentation

data Eval Source #

Constructors

 Eval Int Int

Instances

 Source # Methods(==) :: Eval -> Eval -> Bool #(/=) :: Eval -> Eval -> Bool # Source # MethodsshowsPrec :: Int -> Eval -> ShowS #show :: Eval -> String #showList :: [Eval] -> ShowS #

evaluate :: Ord a => [a] -> [a] -> Eval Source #

Given the code and a guess, compute the evaluation.

histogram :: Ord a => [a] -> Map a Int Source #

selectFromHistogram :: Ord a => Map a Int -> [(a, Map a Int)] Source #

remainingSimple :: Ord a => Set a -> [a] -> Int -> [[Set a]] Source #

A variant of the game: It is only possible to specify number of symbols at right places.

The results of remaining and remainingSimple cannot be compared.

possibleRightPlaces :: Int -> Int -> [[Bool]] Source #

Combinatorical "choose k from n".

remaining :: (C set, Ord a) => Set a -> [a] -> Eval -> set a Source #

Given a code and an according evaluation, compute the set of possible codes.

The Game.Mastermind game consists of collecting pairs of codes and their evaluations. The searched code is in the intersection of all corresponding code sets.

partitionSizes :: Ord a => Set a -> [a] -> [(Eval, Integer)] Source #

interaction :: (T Char -> StateT state Maybe [Char]) -> state -> Set Char -> Int -> IO () Source #

randomSelect :: (RandomGen g, Monad m) => [a] -> StateT g m a Source #

minimax :: Ord b => [(a, [b])] -> a Source #

minimum of maximums using alpha-beta-pruning

randomizedAttempt :: (C set, RandomGen g, Ord a) => Int -> Set a -> set a -> StateT g Maybe [a] Source #

mixedRandomizedAttempt :: (C set, RandomGen g, Ord a) => Int -> Set a -> set a -> StateT g Maybe [a] Source #

In the beginning we simply choose a random code from the set of possible codes. In the end, when the set becomes small, then we compare different alternatives.

main :: IO () Source #