LambdaHack-0.11.0.1: A game engine library for tactical squad ASCII roguelike dungeon crawlers

Safe Haskell | None
Language | Haskell2010

Game.LambdaHack.Core.Dice

Contents

- Frequency distribution for casting dice scaled with level depth
- Dice for rolling a pair of integer parameters representing coordinates.

Description

Representation of dice scaled with current level depth.

Synopsis

- data Dice
- newtype AbsDepth = AbsDepth Int
- castDice :: 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)

# Frequency distribution for casting dice scaled with level depth

data Dice Source #

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

Instances details

Num Dice Source # |
Instance details Defined in Game.LambdaHack.Core.Dice Methods (+) :: Dice -> Dice -> Dice Source # (-) :: Dice -> Dice -> Dice Source # (*) :: Dice -> Dice -> Dice Source # negate :: Dice -> Dice Source # abs :: Dice -> Dice Source # signum :: Dice -> Dice Source # fromInteger :: Integer -> Dice Source #
Show Dice Source # |
Instance details Defined in Game.LambdaHack.Core.Dice Methods showsPrec :: Int -> Dice -> ShowS Source # show :: Dice -> String Source # showList :: [Dice] -> ShowS Source #
Eq Dice Source # |
Instance details Defined in Game.LambdaHack.Core.Dice Methods (==) :: Dice -> Dice -> Bool Source # (/=) :: Dice -> Dice -> Bool Source #

newtype AbsDepth Source #

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.

Constructors

AbsDepth Int |

#### Instances

Instances details

Binary AbsDepth Source # |
Instance details Defined in Game.LambdaHack.Core.Dice Methods put :: AbsDepth -> Put Source # get :: Get AbsDepth Source # putList :: [AbsDepth] -> Put Source #
Show AbsDepth Source # |
Instance details Defined in Game.LambdaHack.Core.Dice Methods showsPrec :: Int -> AbsDepth -> ShowS Source # show :: AbsDepth -> String Source # showList :: [AbsDepth] -> ShowS Source #
Eq AbsDepth Source # |
Instance details Defined in Game.LambdaHack.Core.Dice Methods (==) :: AbsDepth -> AbsDepth -> Bool Source # (/=) :: AbsDepth -> AbsDepth -> Bool Source #
Ord AbsDepth Source # |
Instance details Defined in Game.LambdaHack.Core.Dice Methods compare :: AbsDepth -> AbsDepth -> Ordering Source # (<) :: AbsDepth -> AbsDepth -> Bool Source # (<=) :: AbsDepth -> AbsDepth -> Bool Source # (>) :: AbsDepth -> AbsDepth -> Bool Source # (>=) :: AbsDepth -> AbsDepth -> Bool Source # max :: AbsDepth -> AbsDepth -> AbsDepth Source # min :: AbsDepth -> AbsDepth -> AbsDepth Source #

castDice :: 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 `dL` 1` is `1` even at the lowest level, but so is the value of `1 `dL` depth`.

The implementation calls RNG as many times as there are dice rolls, which is costly, so content should prefer to cast 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 `d` 2` rolls 2-sided die one time.

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 second argument, rolled the given number of times. E.g., `1 `z` 1` always rolls zero.

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

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

intToDice :: Int -> Dice Source #

minDice :: Dice -> Dice -> Dice Source #

maxDice :: Dice -> Dice -> Dice Source #

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.

supDice :: Dice -> Int Source #

Maximal value of dice. The scaled part taken assuming median level.

infDice :: Dice -> Int Source #

Minimal value of dice. The scaled part taken assuming median level.

meanDice :: Dice -> Double Source #

Mean value of dice. The scaled part taken assuming median level, but not taking into account rounding up, and so too low, especially for dice small compared to depth. To fix this, depth would need to be taken as argument.

reduceDice :: Dice -> Maybe Int Source #

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

data DiceXY Source #

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

Constructors

DiceXY Dice Dice |

#### Instances

Instances details

Show DiceXY Source # |
Instance details Defined in Game.LambdaHack.Core.Dice Methods showsPrec :: Int -> DiceXY -> ShowS Source # show :: DiceXY -> String Source # showList :: [DiceXY] -> ShowS Source #

supDiceXY :: DiceXY -> (Int, Int) Source #

Maximal value of DiceXY.

infDiceXY :: DiceXY -> (Int, Int) Source #

Minimal value of DiceXY.