Game Development Reference
In-Depth Information
using array indexes 1 through 3.) Likewise, if we were going to be dropping the
highest, we would use the first three positions (indexes 0 through 2). We accom-
plish this by setting
iFirstDie
and
iLastDie
accordingly based on the
switch
statement.
The last portion of the function simply iterates through the vector between
iFirstDie
and
iLastDie
and adds the results together as if they were the only dice.
As an example of calling this function, the “4d6, drop the lowest� call would be
passed as:
RollTotal = MultipleDie( 3, 6, true, SKEW_LEFT, 1 );
Reading this in English: “roll 3d6, zero-based, skewed to the left by one die.�
Note that on the Web site at
http://www.courseptr.com/downloads,
this func-
tion has the third, fourth, and fifth parameters set with defaults as follows:
unsigned short MultipleDie(
unsigned short NumDie,
unsigned short NumSides,
bool ZeroBased = true,
SKEW_TYPE SkewDirection = SKEW_NONE,
unsigned short SkewCount = 0 );
Therefore, by not passing those parameters, we can use this same function even
if we do not want to skew the distribution.
Shifting the Curve
Looking back at the D&D example in Figures 11.6 and 11.12, we will notice that the
lower bound is 3. This is an artifact of using three dice with the numbers one
through six on their faces. Mathematically, it is impossible to generate the number
two by rolling three dice constructed in that fashion. Likewise, we arrived at the
maximum of 18 in the same way. There is no way to achieve a 19 with these three,
standard-issue dice.
There
are
ways at arriving at numbers such as these, however. If we decide that
we like the
shape
of the curve generated by 3d6—namely the range of 16 and standard
deviation of about 3, we can pick that shape up and move it to many other places.
For example, by using the formula (3d6 - 10) we could generate the numbers -7 to
+8. The resulting curve would share the same probability characteristics as our