Game Development Reference
In-Depth Information
if ( Target <= mvDistribution[i].Edge &&
Target > mvDistribution[i-1].Edge ) {
return true;
} else {
return false;
} // end if
}
This Boolean function checks to see if the random number Target is between
the edge of the specified bucket mvDistribution[i] and the edge of the bucket to
the left of it, mvDistribution[i-1] . We need to take care with the operators in the
two statements. Because the edge of a bucket is inclusive , we also need to test for
equality on the current bucket but not equality of the previous bucket.
It is also important that we trap for the possibility that this is the lowest bucket
(that is, i is 0). If that is the case, we cannot utilize the edge of the bucket below it
without generating an index that is out of bounds (e.g., -1). We only check to see
if Target is less than the edge of the bucket.
Going back to GetResult() , if InBucket returns false, then we know that our
current guess, iGuess , is not correct. We then test to see if our random number
( Target ) is higher than the edge of our current bucket. If it is, we move the lowest
bucket to search up to the current bucket. If Target is lower, we move the highest
bucket to search down to the current bucket.
A DJUSTING D ATA
In all of the above examples, we create the response curve at the beginning and do
not adjust it afterward. There are times, however, when we would want to adjust the
contents of the response curve. It would be inefficient for us to erase all the contents
of the existing vector and rebuild it from scratch. Depending on the change that is
made, we can use a number of approaches to modify the existing data without hav-
ing to start over.
One of the most common (and most useful) adjustments we can make to the
data in a response curve is to adjust the weights of one or more of the buckets.
When we are dealing with a 1-to-1 response curve, adjusting the data held in one
of the buckets is inconsequential. We return the data held in the bucket that we find
at the selected index.
The only difference to this approach is when we introduce the binary search.
Because we are searching for our result by the edge values rather than the indices,
we need to maintain the integrity of the edge values. With the distribution-based
Search WWH ::




Custom Search