Fix (one?) cause of AI regression w/ new attack_prediction code:

take into account healing defender will receive from village (as old code did).
This commit is contained in:
Rusty Russell 2006-05-25 12:35:21 +00:00
parent 88cae46da6
commit 8b50f26df7
3 changed files with 5 additions and 5 deletions

View file

@ -416,7 +416,7 @@ void ai::attack_analysis::analyze(const gamemap& map, unit_map& units,
avg_damage_inflicted = defend_it->second.hitpoints() - defend_it->second.max_hitpoints();
} else {
chance_to_kill = prev_def->hp_dist[0];
avg_damage_inflicted = defend_it->second.hitpoints() - prev_def->average_hp();
avg_damage_inflicted = defend_it->second.hitpoints() - prev_def->average_hp(map.gives_healing(defend_it->first));
}
delete prev_def;

View file

@ -622,13 +622,13 @@ void combatant::fight(combatant &opp)
opp.untouched = opp.hp_dist[opp.u_.hp];
}
double combatant::average_hp() const
double combatant::average_hp(unsigned int healing) const
{
double total = 0;
double total = hp_dist[0];
// Since sum of probabilities is 1.0, we can just tally weights.
for (unsigned int i = 0; i < hp_dist.size(); i++) {
total += hp_dist[i] * i;
total += hp_dist[i] * minimum<unsigned int>(i + healing, u_.max_hp);
}
return total;
}

View file

@ -30,7 +30,7 @@ struct combatant
double slowed;
// What's the average hp (weighted average of hp_dist).
double average_hp() const;
double average_hp(unsigned int healing = 0) const;
private:
// We must adjust for swarm after every combat.