Game Development Reference
In-Depth Information
FIGURE 12.4 The histogram in Figure 12.3 rearranged to show the data
generated by the InitVector() function. The terminology of the
response curve data structure is labeled.
USHORT CDistribution::GetResult()
{
// The number of buckets in the disribution
USHORT NumBuckets = mvDistribution.size();
// The maximum roll is the edge of the last bucket
USHORT MaxRoll = mvDistribution[NumBuckets - 1].Edge;
// The random number we are looking for
USHORT Target = DiceRoller.SingleDie( MaxRoll, false );
// Bucket indexes
USHORT iHigh = mvDistribution.size() - 1;
USHORT iLow = 0;
USHORT iGuess;
bool found = false;
while ( !found ) {
// Guess is halfway between the low and high indexes
Search WWH ::




Custom Search