Game Development Reference
In-Depth Information
// Make sure the utility is a minimum of zero.
if ( Utility < 0 ) Utility = 0;
return Utility;
}
Then, in the function SelectGoal() , by calling that function with the appro-
priate values, we can determine which of the two approaches is going to yield the
greatest utility. Note that for clarity, we have declared a type, GOAL_TYPE , which
enumerates which of the two goals we are returning as our decision.
typedef enum {
GOAL_A,
GOAL_B
} GOAL_TYPE;
GOAL_TYPE MyGame::SelectGoal( int ValA, int ValB,
int TimeA, int TimeB, int TimeAB,
float Decay )
{
// Process the utilities of going to goal A first then goal B
// and going to goal B first then A.
float UtilityAB; // Utility of going to goal A first
float UtilityBA; // Utility of going to goal B first
// Get utility of going to A then B
UtilityAB = GoalUtility( ValA, TimeA, Decay )
+ GoalUtility( ValB, ( TimeA + TimeAB ), Decay );
// Get utility of going to B then A
UtilityBA = GoalUtility( ValB, TimeB, Decay )
+ GoalUtility( ValA, ( TimeB + TimeAB ), Decay );
// Compare the two utilities to determine which is preferable
if ( UtilityAB > UtilityBA ) {
Search WWH ::




Custom Search