Safe Haskell | None |
---|---|

Language | Haskell2010 |

Representation of dice scaled with current level depth.

## Synopsis

- data Dice
- newtype AbsDepth = AbsDepth Int
- castDice :: forall m. Monad m => ((Int, Int) -> m Int) -> AbsDepth -> AbsDepth -> Dice -> m Int
- d :: Int -> Int -> Dice
- dL :: Int -> Int -> Dice
- z :: Int -> Int -> Dice
- zL :: Int -> Int -> Dice
- intToDice :: Int -> Dice
- minDice :: Dice -> Dice -> Dice
- maxDice :: Dice -> Dice -> Dice
- infsupDice :: Dice -> (Int, Int)
- supDice :: Dice -> Int
- infDice :: Dice -> Int
- meanDice :: Dice -> Double
- reduceDice :: Dice -> Maybe Int
- data DiceXY = DiceXY Dice Dice
- supDiceXY :: DiceXY -> (Int, Int)
- infDiceXY :: DiceXY -> (Int, Int)
- meanDiceXY :: DiceXY -> (Double, Double)

# Frequency distribution for casting dice scaled with level depth

Multiple dice rolls, some scaled with current level depth, in which case the sum of all rolls is scaled in proportion to current depth divided by maximal dungeon depth.

The simple dice should have positive number of rolls and number of sides.

The `Num`

instance doesn't have `abs`

nor `signum`

defined,
because the functions for computing infimum, supremum and mean dice
results would be too costly.

## Instances

Absolute depth in the dungeon. When used for the maximum depth of the whole dungeon, this can be different than dungeon size, e.g., when the dungeon is branched, and it can even be different than the length of the longest branch, if levels at some depths are missing.

castDice :: forall m. Monad m => ((Int, Int) -> m Int) -> AbsDepth -> AbsDepth -> Dice -> m Int Source #

Cast dice scaled with current level depth. When scaling, we round up,
so that the value of `1 `

is 1 even at the lowest level.`dL`

1

The implementation calls RNG as many times as there are dice rolls, which is costly, so content should prefer to case fewer dice and then multiply them by a constant. If rounded results are not desired (often they are, to limit the number of distinct item varieties in inventory), another dice may be added to the result.

A different possible implementation, with dice represented as `Frequency`

,
makes only one RNG call per dice, but due to lists lengths proportional
to the maximal value of the dice, it's is intractable for 1000d1000
and problematic already for 100d100.

d :: Int -> Int -> Dice Source #

A die, rolled the given number of times. E.g., `1 `

rolls 2-sided
die one time.`d`

2

dL :: Int -> Int -> Dice Source #

A die rolled the given number of times, with the result scaled with dungeon level depth.

z :: Int -> Int -> Dice Source #

A die, starting from zero, ending at one less than the bound,
rolled the given number of times. E.g., `1 `

always rolls zero.`z`

1

zL :: Int -> Int -> Dice Source #

A die, starting from zero, ending at one less than the bound, rolled the given number of times, with the result scaled with dungeon level depth.

infsupDice :: Dice -> (Int, Int) Source #

Minimal and maximal possible value of the dice.

`divUp`

in the implementation corresponds to `ceiling`

,
applied to results of `meanDice`

elsewhere in the code,
and prevents treating 1d1-power effects (on shallow levels) as null effects.

# Dice for rolling a pair of integer parameters representing coordinates.

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

## Instances

Show DiceXY Source # | |

Generic DiceXY Source # | |

Binary DiceXY Source # | |

type Rep DiceXY Source # | |

Defined in Game.LambdaHack.Core.Dice type Rep DiceXY = D1 (MetaData "DiceXY" "Game.LambdaHack.Core.Dice" "LambdaHack-0.9.5.0-inplace" False) (C1 (MetaCons "DiceXY" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 Dice) :*: S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 Dice))) |