Class Dice

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class Dice

Summary
Using Dice
Format
Examples
Public Properties
Public Methods
Dice()
Dice(formula)
Dice(no_dice, no_sides, offset, multiplier)
inline int getNoDice() const
inline int getNoSides() const
inline int getOffset() const
inline int getMultiplier() const
inline void setNoDice(n)
inline void setNoSides(n)
inline void setOffset(n)
inline void setMultiplier(n)
inline Dice& clear()
inline bool valid() const
int roll() const
int rollAvoidLow() const
inline int min() const
inline int max() const
inline int average() const
inline bool varies() const
inline bool fixed() const
string toString() const
Private Properties

#include <Dice.h >

Summary

A data structure to represent one or more dice, and roll random numbers based on those dice.

Using Dice

Dice play central roll in this game.  When rolled by the computer, they must be specified in an understandable format.

Format

Dice follow this general format:

[qty]dsides[+offset][xmultiplier]

where

Term

Description

qty

Optional. An integer that specifies the number of dice to roll.

sides

The number of sides on the dice.

offset

Optional.  How much to add to the result of the dice roll.

multiplier

Optional.  How much to multiply the dice roll by.  Multiplication is applied last, even after offset.


Examples

+4

-4, 4

%d, %d+5

d4, 1d4, 2d4, 2d4+3, d20+4

d4x10, 1d4x10, 2d4x10, 2d4x10+3, d20+4

d0+5

Public Properties

static Dice NullDie

Preconfigured combination: Null die, d0

static Dice TwoSided

Preconfigured combination: d2

static Dice FourSided

Preconfigured combination: d4

static Dice SixSided

Preconfigured combination: d6

static Dice EightSided

Preconfigured combination: d8

static Dice TenSided

Preconfigured combination: d10

static Dice TwelveSided

Preconfigured combination: d12

static Dice TwentySided

Preconfigured combination: d20

static Dice PercentileDice

Preconfigured combination: %d or d100

static Dice OneDieThree

Preconfigured combination: d3

static Dice TwoDieFour

Preconfigured combination: 2d4

static Dice TwoDieSix

Preconfigured combination: 2d6

static Dice TwoDieEight

Preconfigured combination: 2d8

static Dice TwoDieTen

Preconfigured combination: 2d10

static Dice ThreeDieSix

Preconfigured combination: 3d6

static Dice ThreeDieEight

Preconfigured combination: 3d8

static Dice ThreeDieTen

Preconfigured combination: 3d10

static Dice FourDieEight

Preconfigured combination: 4d8

static Dice FourDieTen

Preconfigured combination: 4d10

static Dice FiveDieFour

Preconfigured combination: 5d4

static Dice FiveDieSix

Preconfigured combination: 5d6

static Dice FiveDieEight

Preconfigured combination: 5d8

static Dice FiveDieTen

Preconfigured combination: 5d10

static Dice TenDieFour

Preconfigured combination: 10d4

static Dice TenDieSix

Preconfigured combination: 10d6

static Dice TenDieEight

Preconfigured combination: 10d8

static Dice TwentyDieFour

Preconfigured combination: 20d4

static Dice TwentyDieSix

Preconfigured combination: 20d6


Public Methods

Dice()

Construct empty dice

Dice(formula)

string formula

the formulation, following this syntax: <#dice >d <#sides >[+ <offset >][x <multiplier >]


Construct dice based upon a string formula, such as 2d6 for (2) six-sided dice.

Dice(no_dice, no_sides, offset, multiplier)

int no_dice

number of dice

int no_sides

number of sides per die

int offset

number to add to the rolled dice

Default value: 0

int multiplier

Default value: 1


Construct dice

@param multipler - number to multiply the result by

inline int getNoDice() const

Get the number of dice

Return value: number of dice

inline int getNoSides() const

Get the number of sides per die

Return value: number of sides

inline int getOffset() const

Get the offset to add to a roll

Return value: offset to add

inline int getMultiplier() const

Get the result multiplier

Return value: multiplier

inline void setNoDice(n)

int n

number of dice


Set the number of dice.

inline void setNoSides(n)

int n

number of sides


Set the number of sides.

inline void setOffset(n)

int n

offset


Set the offset.

inline void setMultiplier(n)

int n

result multiplier


Set the result multiplier.

inline Dice& clear()

Clear the dice back to 0 dice of 0 sides with 0 offset and multiplier of 1

Return value: the updated instance

inline bool valid() const

Check if dice combination is valid

Return value: true if combination is valid (1+ sides, 1+ dice or offset >0), false if invalid

int roll() const

Using the dice configuration, roll a random number.

Note that 3d6 means roll three independent d6 values and add them together.

int rollAvoidLow() const

Roll the dice, but if the result is low, reroll, but exclude the topmost.

This is a sympathy roll to avoid rolling the lowest 20% of the dice range.

Note, the limitation on the sympathy: if the first roll was low, then the

official roll cannot be the topmost value(s) either.

Return value: resulting die roll

inline int min() const

Calculate the minimum rollable value from the dice

Return value: minimum value

inline int max() const

Calculate the maximum rollable value from the dice

Return value: minimum value

inline int average() const

Calculate the average rollable value from the dice (rounded up)

Return value: minimum value

inline bool varies() const

Check if the die roll actually varies or if it is always fixed.

Return value: true if there's at least a difference of 1 between the min() and max() rollable values, false if same

inline bool fixed() const

Check if the die roll is always fixed.

Return value: true if always same, false if there's at least a difference of 1 between the min() and max() rollable values

string toString() const

Convert the data into a string that represents the dice, e.g. its formula

Private Properties

string formula

the dice formula, e.g. 2d4+1

int no_dice

the number of dice

int no_sides

the number of sides

int offset

the amount to add to the result

int multiplier

the result multiplier