Author: esr
Date: Thu Oct 23 11:03:24 2008
New Revision: 30334

URL: http://svn.gna.org/viewcvs/wesnoth?rev=30334&view=rev
Log:
More merging in of code (commented and conditioned out) from sukoo's
29531.  It's up to someone who understands AI tuning better than I do
to decid which, if any, of these pieces of code should become active.

Modified:
    trunk/src/ai.cpp
    trunk/src/ai_attack.cpp
    trunk/src/ai_move.cpp

Modified: trunk/src/ai.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai.cpp?rev=30334&r1=30333&r2=30334&view=diff
==============================================================================
--- trunk/src/ai.cpp (original)
+++ trunk/src/ai.cpp Thu Oct 23 11:03:24 2008
@@ -1239,7 +1239,10 @@
        time_taken = SDL_GetTicks() - ticks;
        LOG_AI << "analysis took " << time_taken << " ticks\n";
 
-       if(choice_rating > 0.0 /*current_team().caution()*/) {
+       // suokko tested the rating against current_team().caution()
+       // Bad mistake -- the AI became extremely reluctant to attack anything.
+       // Documenting this in case someone has this bright idea 
again...*don't*...
+       if(choice_rating > 0.0) {
                location from   = choice_it->movements[0].first;
                location to     = choice_it->movements[0].second;
                location target_loc = choice_it->target;
@@ -1518,6 +1521,13 @@
                                        LOG_AI << "retreating '" << 
i->second.type_id() << "' " << i->first
                                               << " -> " << best_pos << '\n';
                                        
move_unit(i->first,best_pos,possible_moves);
+#ifdef SUOKKO
+                                       // FIXME: This was in sukko's r29531 
but backed out.
+                                       // Is it correct?
+                                       i->second.set_movement(0);
+                                       if (best_rating < 0.0)
+                                               add_target(target(best_pos, 
-3.0*best_rating, target::SUPPORT));
+#endif
                                        return true;
                                }
                        }
@@ -1579,11 +1589,24 @@
                if (u_it == units_.end() || u_it->second.incapacitated()) {
                        LOG_STREAM(warn, ai) << "stolen or incapacitated\n";
                } else {
+                       // FIXME: sukko's r29531 inserted the following line, 
is it correct?
+                       // u_it->second.set_movement(0);
                        // Search to see if there are any enemy units next to 
the tile
                        // which really should be attacked now the move is done.
                        map_location adj[6];
                        get_adjacent_tiles(arrived_at,adj);
                        map_location target;
+#ifdef SUOKKO
+                       // FIXME: This code was in sukko's r29531 and was 
backed out. Correct?
+                       int selected = -1;
+                       boost::scoped_ptr<battle_context> bc_sel;
+
+                       double harm_weight = 2.0 + current_team().caution();
+                       if (chosen->type == target::THREAT
+                           || chosen->type == target::BATTLE_AID)
+                         harm_weight -= 1.0;
+                       harm_weight =  current_team().aggression() - 
harm_weight;
+#endif
 
                        for(int n = 0; n != 6; ++n) {
                                const unit_map::iterator enemy = 
find_visible_unit(units_,adj[n],
@@ -1595,14 +1618,36 @@
                                        // Current behavior is to only make 
risk-free attacks.
                                        game_events::fire("consider attack", 
arrived_at, adj[n]);
                                        battle_context bc(map_, teams_, units_, 
state_, arrived_at, adj[n], -1, -1, 100.0);
+#ifndef SUOKKO
                                        if (bc.get_defender_stats().damage == 
0) {
                                                attack_enemy(arrived_at, 
adj[n], bc.get_attacker_stats().attack_num,
                                                                
bc.get_defender_stats().attack_num);
                                                break;
                                        }
+#else
+                                       // FIXME: This code was in sukko's 
r29531. Correct?
+                                       const double value = 
(bc.get_defender_combatant().hp_dist[0] - 
bc.get_attacker_combatant().hp_dist[0]*harm_weight)*u_it->second.max_hitpoints()/2
+                                               + 
(bc.get_defender_combatant().average_hp() - 
bc.get_attacker_combatant().average_hp() * harm_weight);
+
+                                       if (value > 0.0
+                                               && (selected == -1 
+                                                       || 
bc_sel->better_attack(bc,harm_weight)))
+                                       {
+                                               // Select attack target
+                                               bc_sel.reset(new 
battle_context(bc));
+                                               selected = n;
+                                       }
+#endif
                                        game_events::fire("unconsider attack", 
arrived_at, adj[n]);
                                }
                        }
+#ifdef SUOKKO
+                       // FIXME: This code was in sukko's r29531 and was 
backed out. Correct?
+                       if (selected >= 0) {
+                               attack_enemy(arrived_at, adj[selected], 
bc_sel->get_attacker_stats().attack_num,
+                                               
bc_sel->get_defender_stats().attack_num);
+                       }
+#endif
                }
 
                // Don't allow any other units to move onto the tile
@@ -2097,6 +2142,8 @@
 
                                        if(p.routes.count(i->first)) {
                                                
move_unit(leader->first,current_loc,possible_moves);
+                                               // FIXME: suokko's r29531 
included this line
+                                               // 
leader->second.set_movement(0);
                                                return;
                                        }
                                }

Modified: trunk/src/ai_attack.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai_attack.cpp?rev=30334&r1=30333&r2=30334&view=diff
==============================================================================
--- trunk/src/ai_attack.cpp (original)
+++ trunk/src/ai_attack.cpp Thu Oct 23 11:03:24 2008
@@ -223,7 +223,7 @@
                        }
 
                        // Find out how vulnerable we are to attack from enemy 
units in this hex.
-                       //FIXME: suokko multiplied this by a constant 1.5. 
Should this be done?  
+                       //FIXME: suokko's r29531 multiplied this by a constant 
1.5. ?  
                        const double vulnerability = 
power_projection(tiles[j],enemy_dstsrc);
 
                        // Calculate how much support we have on this hex from 
allies.
@@ -233,14 +233,30 @@
 
                        // If this is a position with equal defense to another 
position,
                        // but more vulnerability then we don't want to use it.
+#ifdef SUOKKO
+                       //FIXME: this code was in sukko's r29531  Correct?
+                       // scale vulnerability to 60 hp unit
+                       if(cur_position >= 0 && rating < best_rating
+                                       && 
(vulnerability/surround_bonus*30.0)/unit_itor->second.hitpoints() - 
+                                               
(support*surround_bonus*30.0)/unit_itor->second.max_hitpoints()
+                                               > best_vulnerability - 
best_support) {
+                               continue;
+                       }
+#else
                        if(cur_position >= 0 && rating == best_rating && 
vulnerability/surround_bonus - support*surround_bonus >= best_vulnerability - 
best_support) {
                                continue;
                        }
-
+#endif
                        cur_position = j;
                        best_rating = rating;
+#ifdef SUOKKO
+                       //FIXME: this code was in sukko's r29531  Correct?
+                       best_vulnerability = 
(vulnerability/surround_bonus*30.0)/unit_itor->second.hitpoints();
+                       best_support = 
(support*surround_bonus*30.0)/unit_itor->second.max_hitpoints();
+#else
                        best_vulnerability = vulnerability/surround_bonus;
                        best_support = support*surround_bonus;
+#endif
                }
 
                if(cur_position != -1) {
@@ -347,6 +363,7 @@
 
                if (up->second.can_recruit()) {
                        uses_leader = true;
+                       // FIXME: suokko's r29531 omitted this line
                        leader_threat = false;
                }
 
@@ -508,8 +525,14 @@
                // into sub-optimal terrain.
                // Calculate the 'exposure' of our units to risk.
 
+#ifdef SUOKKO
+               //FIXME: this code was in sukko's r29531  Correct?
+               const double exposure_mod = uses_leader ? 
ai_obj.current_team().caution()* 8.0 : ai_obj.current_team().caution() * 4.0;
+               const double exposure = 
exposure_mod*resources_used*((terrain_quality - 
alternative_terrain_quality)/10)*vulnerability/std::max<double>(0.01,support);
+#else
                const double exposure_mod = uses_leader ? 2.0 : 
ai_obj.current_team().caution();
                const double exposure = 
exposure_mod*resources_used*(terrain_quality - 
alternative_terrain_quality)*vulnerability/std::max<double>(0.01,support);
+#endif
                LOG_AI << "attack option has base value " << value << " with 
exposure " << exposure << ": "
                        << vulnerability << "/" << support << " = " << 
(vulnerability/std::max<double>(support,0.1)) << "\n";
                if(uses_leader) {

Modified: trunk/src/ai_move.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai_move.cpp?rev=30334&r1=30333&r2=30334&view=diff
==============================================================================
--- trunk/src/ai_move.cpp (original)
+++ trunk/src/ai_move.cpp Thu Oct 23 11:03:24 2008
@@ -121,7 +121,12 @@
 
                        assert(threats.empty() == false);
 
+#ifdef SUOKKO
+                       //FIXME: sukko's veraion 29531 included this change.  
Correct?
+                       const double value = 
threat*lexical_cast_default<double>(current_team().ai_parameters()["protect_leader"],
 3.0)/leader->second.hitpoints();
+#else
                        const double value = threat/double(threats.size());
+#endif
                        for(std::set<map_location>::const_iterator i = 
threats.begin(); i != threats.end(); ++i) {
                                LOG_AI << "found threat target... " << *i << " 
with value: " << value << "\n";
                                
targets.push_back(target(*i,value,target::THREAT));
@@ -346,6 +351,9 @@
                        if(res != best_loc) {
                                return true;
                        }
+
+                       // FIXME: suokko's r29531 included the following line.  
Correct?
+                       // units_.find(best_loc)->second.set_movement(0);
 
                        
preferred_moves.erase(std::find(preferred_moves.begin(),preferred_moves.end(),best_loc));
 


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to