Game Development Reference
In-Depth Information
P UTTING I TIN C ODE
To accommodate the above discussion, the changes that we make to our code are
relatively minor. First, we must change the struct that we use for the target infor-
mation to hold an edge value.
struct sTARGET_INFO
{
CDude* pDude;
CWeapon* pWeapon;
double Score;
USHORT Edge;
bool operator<( const sTARGET_INFO& j ) {return Score < j.Score;}
};
Next, we need to add a function that calculates the edges. Because we need to
have the scores completely filled out to determine weights and edges, the process of
calculating this information cannot begin until we have finished scoring all the tar-
gets. BuildEdges() also uses the functions SumScores() and ScoreToWeight() .
void CAgent::BuildEdges(USHORT NumBuckets)
{
double TotalScore = SumScores( NumBuckets );
mvTargets[0].Edge = ScoreToWeight( mvTargets[0].Score, TotalScore );
for ( USHORT i = 1; i < NumBuckets; i++ ) {
mvTargets[i].Edge = mvTargets[i-1].Edge +
ScoreToWeight( mvTargets[i].Score, TotalScore );
} // end for
}
double CAgent::SumScores(USHORT NumBuckets)
{
double TotalScore = 0;
Search WWH ::




Custom Search