Game Development Reference
In-Depth Information
// Check for correct guess
if ( InBucket( iGuess, Target ) ) {
return iGuess;
} // end if
// If not correct...
if ( Target > mvTargets[iGuess].Edge ) {
// guess is too low, change the bottom boundary
iLow = iGuess;
} else {
// guess is too high, change the top boundary
iHigh = iGuess;
} // end if
} // end while
// Code should never get here!
assert( 0 && “Code fell through while loop!�);
return 0;
}
GetResult() returns the index of the target record that we are randomly se-
lecting. We have now replaced the evenly distributed random target selection with
a selection process that proportionally weighs the relative scores of those targets.
We are now relieved of the problem of not knowing how those top eight selec-
tions are distributed ahead of time. They can be similar or widely disparate, and our
algorithm would account for it. We could also change the number of buckets we are
searching. If the number of possible target selections was larger or smaller, the 25%
of them that we are allowing for consideration would grow or shrink, respectively.
Even if we changed our minds and decided that we wanted to consider more or less
than 25%, our algorithm would score, weigh, and select from among the choices.
Search WWH ::




Custom Search