made AI not retreat so much
This commit is contained in:
parent
65d1838a1f
commit
cee017f65f
2 changed files with 20 additions and 5 deletions
23
src/ai.cpp
23
src/ai.cpp
|
@ -484,11 +484,14 @@ bool ai::retreat_units(std::map<gamemap::location,paths>& possible_moves, const
|
|||
//this unit still has movement left, and is a candidate to retreat. We see the amount
|
||||
//of power of each side on the situation, and decide whether it should retreat.
|
||||
if(should_retreat(i->first,fullmove_srcdst,fullmove_dstsrc,enemy_srcdst,enemy_dstsrc)) {
|
||||
//time to retreat. Look for the place where the power balance is most in our favor
|
||||
//time to retreat. Look for the place where the power balance is most in our favor.
|
||||
//If we can't find anywhere where we like the power balance, just try to
|
||||
//get to the best defensive hex
|
||||
typedef move_map::const_iterator Itor;
|
||||
std::pair<Itor,Itor> itors = srcdst.equal_range(i->first);
|
||||
gamemap::location best_pos;
|
||||
double best_rating = -10000.0;
|
||||
gamemap::location best_pos, best_defensive;
|
||||
double best_rating = 0.0;
|
||||
int best_defensive_rating = 100;
|
||||
while(itors.first != itors.second) {
|
||||
|
||||
//we rate the power balance of a hex based on our power projection compared
|
||||
|
@ -499,14 +502,26 @@ bool ai::retreat_units(std::map<gamemap::location,paths>& possible_moves, const
|
|||
const double our_power = power_projection(hex,srcdst,dstsrc);
|
||||
const double their_power = power_projection(hex,enemy_srcdst,enemy_dstsrc) * double(defense)/100.0;
|
||||
const double rating = our_power - their_power;
|
||||
if(!best_pos.valid() || rating > best_rating) {
|
||||
if(rating > best_rating) {
|
||||
best_pos = hex;
|
||||
best_rating = rating;
|
||||
}
|
||||
|
||||
//give a bonus for getting to a village.
|
||||
const int modified_defense = defense - (map_.underlying_terrain(map_.get_terrain(hex)) == gamemap::TOWER ? 10 : 0);
|
||||
|
||||
if(modified_defense < best_defensive_rating) {
|
||||
best_defensive_rating = modified_defense;
|
||||
best_defensive = hex;
|
||||
}
|
||||
|
||||
++itors.first;
|
||||
}
|
||||
|
||||
if(!best_pos.valid()) {
|
||||
best_pos = best_defensive;
|
||||
}
|
||||
|
||||
if(best_pos.valid()) {
|
||||
std::cerr << "retreating '" << i->second.type().name() << "' " << i->first.x << "," << i->first.y << " -> " << best_pos.x << "," << best_pos.y << "\n";
|
||||
move_unit(i->first,best_pos,possible_moves);
|
||||
|
|
|
@ -391,7 +391,7 @@ double ai::attack_analysis::rating(double aggression) const
|
|||
(target_value/resources_used) -
|
||||
(1.0-aggression)*avg_damage_taken*(resources_used/target_value))/10.0;
|
||||
|
||||
value += support*0.5 - vulnerability*terrain_quality;
|
||||
value += support - vulnerability*terrain_quality;
|
||||
|
||||
value /= ((resources_used/2) + (resources_used/2)*terrain_quality);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue