Class Dice
#include <Dice.h >
A data structure to represent one or more dice, and roll random numbers based on those dice.
Dice play central roll in this game. When rolled by the computer, they must be specified in an understandable 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. |
+4
-4, 4
%d, %d+5
d4, 1d4, 2d4, 2d4+3, d20+4
d4x10, 1d4x10, 2d4x10, 2d4x10+3, d20+4
d0+5
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 |
Construct empty dice
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.
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
Get the number of dice
Return value: number of dice
Get the number of sides per die
Return value: number of sides
Get the offset to add to a roll
Return value: offset to add
Get the result multiplier
Return value: multiplier
int n |
number of dice |
Set the number of dice.
int n |
number of sides |
Set the number of sides.
int n |
offset |
Set the offset.
int n |
result multiplier |
Set the result multiplier.
Clear the dice back to 0 dice of 0 sides with 0 offset and multiplier of 1
Return value: the updated instance
Check if dice combination is valid
Return value: true if combination is valid (1+ sides, 1+ dice or offset >0), false if invalid
Using the dice configuration, roll a random number.
Note that 3d6 means roll three independent d6 values and add them together.
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
Calculate the minimum rollable value from the dice
Return value: minimum value
Calculate the maximum rollable value from the dice
Return value: minimum value
Calculate the average rollable value from the dice (rounded up)
Return value: minimum value
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
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
Convert the data into a string that represents the dice, e.g. its formula
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 |