LambdaHack-0.2.10: A roguelike game engine in early and active development

Safe HaskellNone

Game.LambdaHack.Common.Random

Contents

Description

Representation of probabilities and random computations.

Synopsis

The Rng monad

type Rnd a = State StdGen a

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 a

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

random :: Random a => Rnd a

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

oneOf :: [a] -> Rnd a

Get any element of a list with equal probability.

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

Gen an element according to a frequency distribution.

cast :: Int -> Rnd Int

Cast a single die.

Casting dice

data RollDice

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

castDice :: RollDice -> Rnd Int

Cast dice and sum the results.

maxDice :: RollDice -> Int

Maximal value of dice.

minDice :: RollDice -> Int

Minimal value of dice.

meanDice :: RollDice -> Rational

Mean value of dice.

Casting 2D coordinates

data RollDiceXY

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

Constructors

RollDiceXY !(RollDice, RollDice) 

Instances

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

Cast the two sets of dice.

Casting dependent on depth

type RollDeep = (RollDice, RollDice)

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 Int

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

chanceDeep :: Int -> Int -> RollDeep -> Rnd Bool

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

intToDeep :: Int -> RollDeep

Generate a RollDeep that always gives a constant integer.

maxDeep :: RollDeep -> Int

Maximal value of scaled dice.

Fractional chance

type Chance = Rational

Fractional chance.

chance :: Chance -> Rnd Bool

Give True, with probability determined by the fraction.

Run using the IO RNG

rndToIO :: Rnd a -> IO a