Game Development Reference
In-Depth Information
FIGURE 7.8 In this situation, we are assuming a greater probability of receiving
an attack. Now, the benefits provided by the tower in case of attack are
more prevalent—making the utility cost for building one much greater.
Compare this to the estimated utility of not building a tower.
Now, we find that E ( T ) > E (¬ T ). The utility of building (-297.5) is greater than
the utility we achieve by not building (-325). Based on the numbers provided, our
decision should now be to build the tower.
P UTTING I TIN C ODE
Just as we did with the computer warranty example before, the act of converting
this example to code is relatively simple. In fact, the functions and flow look strik-
ingly familiar. Again, we have one function for the utility of building a tower, one
for the utility of not building a tower, and a third that does a simple comparison of
those utilities to advise us. The numbers used for the building costs, the repair
costs, and the odds of attack can be set elsewhere in the game (which is important,
as we shall see in a moment).
float MyGame::UtilityTower()
{
// Returns the utility value of purchasing the tower.
float Utility;
Search WWH ::




Custom Search