Game Development Reference
In-Depth Information
At any point in our game, we could call the BuildTower() function, and it
would process whatever values we had in place for the necessary variables and yield
a Boolean value as to whether the expected utility of building the tower was greater
than the expected utility of not building it… that is, is it worth it to build a tower
over our barracks or not?
Again, using the values from the original example:
// Set the appropriate values
mBarracksPrice = 500;
mTowerPrice = 150;
mSmallDamageTower = 100;
mSmallDamageNoTower = 250;
mLargeDamageTower = 250;
mOddsLargeAttack = 0.2f;
mOddsSmallAttack = 0.5f;
The code to make the decision would simply look like:
bool ShouldWeBuildTower;
// So, should we build the tower
// given the values set above?
ShouldWeBuildTower = BuildTower();
When Changing Changes the Changers
There is one thing that we have not yet considered in this calculation that may be
of interest in our utility functions. It is possible (if not likely) that simply building
a tower next to the barracks may change the probability that it will be attacked at
all. An undefended building is an almost irresistible target for even small forces to
take on. On the other hand, the presence of the defensive structure provides a
deterrent—especially to those lighter squads. To reflect this, we may want to work
with two layers of probability of attack—one that reflects an undefended barracks
and one that takes into account the fact that enemies may more carefully consider
attacking a building with a tower hovering nearby. Needless to say, the complexity
of our calculations goes up significantly at this point.
To see this effect in action, we need to define two different sets of expectations
for the likelihood of attack based on the presence of the tower. First, let's assume
that without a tower present, we can expect:
Search WWH ::




Custom Search