Game Development Reference
In-Depth Information
Rather than referring to an x value as we have done previously, we now call this
variable Result . We do this because, with a probability distribution, we are going
to be selecting one of our buckets based on the probability represented by Size . We
could have also named it something like “Name,� “Selection,� “Action,� or, as in
the dentist example, “Recommendation.� What we call it will be case-specific. In
any event, it is the name of what the bucket represents. For now, Result it is.
As usual, we create a vector to hold our distribution.
typedef std::vector< sBUCKET > DIST_VECTOR;
DIST_VECTOR mvDistribution;
We then create our function, InitVector() , that fills our vector with the 10
results that we want to track the probability of.
void CDistribution::InitVector()
{
sBUCKET ThisBucket;
USHORT ThisSize;
USHORT MaxItems = 10;
for ( USHORT x = 0; x < MaxItems; x++ ) {
ThisSize = (-1 * ( x -100 ) ) + 12;
ThisBucket[x].Size = ThisSize;
If ( x == 0 ) {
// this is the first entry
ThisBucket[x].Edge = ThisSize;
} else {
ThisBucket[x].Edge = ThisBucket[x-1].Edge + ThisSize;
}
ThisBucket[x].Result = x;
mvDistribution.push_back( ThisBucket );
} // end for
}
In InitVector() , we loop through the 10 items, using the value of x in the
equation we specified above to determine the size of the bucket that we then store.
Search WWH ::




Custom Search