Game Development Reference
In-Depth Information
When we run our program, the buckets do not exist in the vector. We need to
set them up with the initial data. We do this by setting the data for each bucket and
pushing it onto the vector. We can isolate this process in a function such as this:
void CGuesser::AddBucket(GUESS_TYPE GuessType, USHORT Width)
{
sGUESSER_BUCKET CurrentBucket;
mMaxIndex += Width;
CurrentBucket.GuessType = GuessType;
CurrentBucket.Width = Width;
CurrentBucket.Edge = mMaxIndex;
mvGuessTypeList.push_back( CurrentBucket );
}
Notice that, despite the fact that our buckets have three members ( GuessType ,
Width , and Edge ), we only pass two variables into the AddBucket function. We
don't need to pass in Edge because it is based on the running total of the bucket
sizes that have been pushed before it. We track this with the member variable
mMaxIndex , which represents the maximum array index of the vector. When we are
finished pushing buckets into our vector, mMaxIndex will represent the combined
width of all the buckets.
To add our four guesser types to this vector, we call AddBucket() once for each
type. It doesn't matter where we get our data. For simplicity's sake, in this example,
we have hard-coded the probabilities for each of the four types.
void CGuesser::InitBuckets()
{
AddBucket( GUESS_33, 4 );
AddBucket( GUESS_22, 3 );
AddBucket( GUESS_RANDOM, 30 );
AddBucket( GUESS_SEMI, 63 );
}
In the function above, we are using the same probabilities that we used in
Chapter 11 and again in our initial example above. If we decide that we want to
change the probability values, however, our task is much simpler now than it was
when we were using the if statements. If we want to make the same change to the
Search WWH ::




Custom Search