Game Development Reference
In-Depth Information
of the figures, including the cost of building the tower itself, we find that the deter-
rent factor alone is enough to justify building the tower.
Of course, a major disclaimer over all of this is that the numbers we have se-
lected for the likelihood of attack may not be accurate. A change of even 5% on one
of those figures could make a significant change in the decision about whether or
not a tower is worth building. Additionally, we may want to vary what our esti-
mates are of the damage that would result from the differently sized forces. What's
more, we may have more than those two sets of attack probabilities that we want to
use. For example, we may want to have different assumptions based on where the
barracks is in relation to enemy territory or other buildings that we have already
constructed. We may even want to create a separate function that determines those
factors for us in a different part of the AI code.
P UTTING I TIN C ODE
Thankfully, if we wanted to include this very specific decision into our game, we
could package everything we have done into a few small functions that simply re-
turn whether or not, based on our estimates, building a tower to cover our barracks
has a utility value that makes it worthwhile.
In this case, rather than holding the odds of there being a large or small attack
in external variables that we access from the utility functions, we actually pass the
variables into those utility functions. That way, we can send it whatever we want. Of
course, that means our base function BuildTower() needs to have all the values
passed in as well so it can distribute those values appropriately. Therefore, we will
change BuildTower() to ask for the four odds values that represent the likelihood
of a small or large attack depending on the presence of the tower. (Note that the
odds of no attack is simply the percentage left over after the odds of the small and
large attacks; you will see the function call for this in the code below but not the
very simple function itself.)
float MyGame::UtilityTower( float OddsLargeAttack, float OddsSmallAttack )
{
// Returns the utility value of purchasing the tower using
// alternate attack odds
float Utility;
float NoAttack = OddsNoAttack(OddsLargeAttack, OddsSmallAttack);
Search WWH ::




Custom Search