LambdaHack-0.7.0.0: A game engine library for roguelike dungeon crawlers

Safe HaskellNone
LanguageHaskell2010

Game.LambdaHack.Common.Dice

Contents

Description

Representation of dice scaled with current level depth.

Synopsis

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 minimum, maximum and mean dice results would be too costly.

Instances

Eq Dice Source # 

Methods

(==) :: Dice -> Dice -> Bool #

(/=) :: Dice -> Dice -> Bool #

Num Dice Source # 

Methods

(+) :: Dice -> Dice -> Dice #

(-) :: Dice -> Dice -> Dice #

(*) :: Dice -> Dice -> Dice #

negate :: Dice -> Dice #

abs :: Dice -> Dice #

signum :: Dice -> Dice #

fromInteger :: Integer -> Dice #

Ord Dice Source # 

Methods

compare :: Dice -> Dice -> Ordering #

(<) :: Dice -> Dice -> Bool #

(<=) :: Dice -> Dice -> Bool #

(>) :: Dice -> Dice -> Bool #

(>=) :: Dice -> Dice -> Bool #

max :: Dice -> Dice -> Dice #

min :: Dice -> Dice -> Dice #

Show Dice Source # 

Methods

showsPrec :: Int -> Dice -> ShowS #

show :: Dice -> String #

showList :: [Dice] -> ShowS #

Generic Dice Source # 

Associated Types

type Rep Dice :: * -> * #

Methods

from :: Dice -> Rep Dice x #

to :: Rep Dice x -> Dice #

Binary Dice Source # 

Methods

put :: Dice -> Put #

get :: Get Dice #

putList :: [Dice] -> Put #

NFData Dice Source # 

Methods

rnf :: Dice -> () #

Hashable Dice Source # 

Methods

hashWithSalt :: Int -> Dice -> Int #

hash :: Dice -> Int #

type Rep Dice Source # 
type Rep Dice = D1 * (MetaData "Dice" "Game.LambdaHack.Common.Dice" "LambdaHack-0.7.0.0-3XPyz9bw1i28qJIoWU6CaM" False) ((:+:) * ((:+:) * ((:+:) * (C1 * (MetaCons "DiceI" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Int))) (C1 * (MetaCons "DiceD" PrefixI False) ((:*:) * (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Int)) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Int))))) ((:+:) * (C1 * (MetaCons "DiceDL" PrefixI False) ((:*:) * (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Int)) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Int)))) (C1 * (MetaCons "DiceZ" PrefixI False) ((:*:) * (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Int)) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Int)))))) ((:+:) * ((:+:) * (C1 * (MetaCons "DiceZL" PrefixI False) ((:*:) * (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Int)) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Int)))) (C1 * (MetaCons "DicePlus" PrefixI False) ((:*:) * (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Dice)) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Dice))))) ((:+:) * (C1 * (MetaCons "DiceTimes" PrefixI False) ((:*:) * (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Dice)) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Dice)))) (C1 * (MetaCons "DiceNegate" PrefixI False) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Dice))))))

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

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

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 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 the bound, 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 the bound, rolled the given number of times, with the result scaled with dungeon level depth.

minmaxDice :: 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.

maxDice :: Dice -> Int Source #

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

minDice :: 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.

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

Show DiceXY Source # 
Generic DiceXY Source # 

Associated Types

type Rep DiceXY :: * -> * #

Methods

from :: DiceXY -> Rep DiceXY x #

to :: Rep DiceXY x -> DiceXY #

Binary DiceXY Source # 

Methods

put :: DiceXY -> Put #

get :: Get DiceXY #

putList :: [DiceXY] -> Put #

Hashable DiceXY Source # 

Methods

hashWithSalt :: Int -> DiceXY -> Int #

hash :: DiceXY -> Int #

type Rep DiceXY Source # 
type Rep DiceXY = D1 * (MetaData "DiceXY" "Game.LambdaHack.Common.Dice" "LambdaHack-0.7.0.0-3XPyz9bw1i28qJIoWU6CaM" False) (C1 * (MetaCons "DiceXY" PrefixI False) ((:*:) * (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Dice)) (S1 * (MetaSel (Nothing Symbol) NoSourceUnpackedness NoSourceStrictness DecidedStrict) (Rec0 * Dice))))

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

Maximal value of DiceXY.

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

Minimal value of DiceXY.

meanDiceXY :: DiceXY -> (Double, Double) Source #

Mean value of DiceXY.