Game Development Reference
In-Depth Information
By adding two lines, we can determine how many records we should consider
(25% of the total number) and generate a random vector index in that range. Rather
than returning the record at index 0, we are returning a random one between index
0 and (NumberToConsider - 1) .
void CAgent::SelectTarget()
{
ScoreAllTargets();
std::sort( mvTargets.begin(), mvTargets.end() );
USHORT NumberToConsider = mvTargets.size() * 0.25;
USHORT i = rand() % ( NumberToConsider - 1 );
mpCurrentTarget = mvTargets[i].pDude;
mpCurrentWeapon = mvTargets[i].pWeapon;
}
Selecting randomly may seem counterintuitive and even mildly alarming. Why,
after all the work we went through in Chapter 14 to arrive at these scores, would we
seemingly cast it all aside and go back to random selection?
The answer to this is in the lessons we learned all the way back in Chapter 5. In
the Ultimatum Game, we determined through similarly mathematical methods
that the best option for the Giver to bestow upon the Receiver was $1. That was the
most logical answer. Likewise, it was in the best interests of the Receiver to accept
that amount. (After all $1 > $0, right?) And yet, people placed in those two roles
rarely do either of those “best� actions.
We explored this further in Chapter 6 with examples such as the Pirate Game,
the Guess Two-Thirds the Average Game, and even the Monty Hall Problem. We
humans like to talk about how rational we are, but, for a variety of reasons, we usu-
ally aren't completely so. We may occasionally select the “best� answer but usually
only get close by selecting a reasonable answer.
The Payoff
That is what we accomplish by using a hybrid of our scoring system (pure rational-
ity) and random selection (inexplicable irrationality). By allowing our agent to
select from a number of reasonable- looking choices, we are effectively modeling all
Search WWH ::




Custom Search