Game Development Reference
In-Depth Information
data that we did a few pages back (the “33� guessers being 5% and the semi-logical
ones being only 62%), we only need to change the two relevant numbers. Our
function would now read:
void CGuesser::InitBuckets()
{
AddBucket( GUESS_33, 5 );
AddBucket( GUESS_22, 3 );
AddBucket( GUESS_RANDOM, 30 );
AddBucket( GUESS_SEMI, 62 );
}
The bucket edges would now be different than they were with the original
numbers. ( mMaxIndex still adds up to 100).
R ETRIEVING A R ESULT
Once we have our buckets set up, tossing our ball in to determine a result is a fairly
simple process. Originally, we generated our random number and then tested it
against three if statements to find out which of our four possibilities was selected.
That is not much different than what we are going to do here. Thankfully, by hold-
ing our results in vector, we can now perform this search in a loop.
GUESS_TYPE CGuesser::GetGuessType()
{
// Generate a random number between 1 and mMaxIndex
USHORT index = DieRoller.SingleDie( mMaxIndex, false );
// Count the number of buckets
USHORT NumBuckets = mvGuessTypeList.size();
// Loop through all the buckets
for ( USHORT i = 0; i < NumBuckets; i++ ) {
// See if index fits in this bucket
if ( index <= mvGuessTypeList[i].Edge ) {
return mvGuessTypeList[i].GuessType;
} // end if
Search WWH ::




Custom Search