LambdaHack- A roguelike game engine in early and active development

Safe HaskellNone




Representation of probabilities and random computations.


The Rng monad

type Rnd a = State StdGen aSource

The monad of computations with random generator state. The lazy state monad is OK here: the state is small and regularly forced.

Random operations

randomR :: Random a => (a, a) -> Rnd aSource

Get a random object within a range with a uniform distribution.

random :: Random a => Rnd aSource

Get a random object of a given type with a uniform distribution.

oneOf :: [a] -> Rnd aSource

Get any element of a list with equal probability.

frequency :: Show a => Frequency a -> Rnd aSource

Gen an element according to a frequency distribution.

cast :: Int -> Rnd IntSource

Cast a single die.

Casting dice

data RollDice Source

Dice: 1d7, 3d3, 1d0, etc. RollDice a b represents a rolls of b-sided die.

castDice :: RollDice -> Rnd IntSource

Cast dice and sum the results.

maxDice :: RollDice -> IntSource

Maximal value of dice.

minDice :: RollDice -> IntSource

Minimal value of dice.

meanDice :: RollDice -> RationalSource

Mean value of dice.

Casting 2D coordinates

data RollDiceXY Source

Dice for rolling a pair of integer parameters pertaining to, respectively, the X and Y cartesian 2D coordinates.


castDiceXY :: RollDiceXY -> Rnd (Int, Int)Source

Cast the two sets of dice.

maxDiceXY :: RollDiceXY -> (Int, Int)Source

Maximal value of RollDiceXY.

minDiceXY :: RollDiceXY -> (Int, Int)Source

Minimal value of RollDiceXY.

meanDiceXY :: RollDiceXY -> (Rational, Rational)Source

Mean value of RollDiceXY.

Casting dependent on depth

data RollDeep Source

Dice for parameters scaled with current level depth. To the result of rolling the first set of dice we add the second, scaled in proportion to current depth divided by maximal dungeon depth.


castDeep :: Int -> Int -> RollDeep -> Rnd IntSource

Cast dice scaled with current level depth. Note that at the first level, the scaled dice are always ignored.

chanceDeep :: Int -> Int -> RollDeep -> Rnd BoolSource

Cast dice scaled with current level depth and return True if the results if greater than 50.

intToDeep :: Int -> RollDeepSource

Generate a RollDeep that always gives a constant integer.

maxDeep :: RollDeep -> IntSource

Maximal value of scaled dice.

Fractional chance

type Chance = RationalSource

Fractional chance.

chance :: Chance -> Rnd BoolSource

Give True, with probability determined by the fraction.

Run using the IO RNG

rndToIO :: Rnd a -> IO aSource