Author: crab
Date: Mon Apr 2 20:07:01 2012
New Revision: 53754
URL: http://svn.gna.org/viewcvs/wesnoth?rev=53754&view=rev
Log:
Power projection improvement: use next turn with proper next-turn ToD if
necessary. Patch #3185 by ejls
Modified:
trunk/data/core/about.cfg
trunk/src/ai/contexts.cpp
trunk/src/ai/testing/aspect_attacks.cpp
trunk/src/ai/testing/aspect_attacks.hpp
Modified: trunk/data/core/about.cfg
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/data/core/about.cfg?rev=53754&r1=53753&r2=53754&view=diff
==============================================================================
--- trunk/data/core/about.cfg (original)
+++ trunk/data/core/about.cfg Mon Apr 2 20:07:01 2012
@@ -948,6 +948,9 @@
name = "Ely Levy (Nakee)"
[/entry]
[entry]
+ name = "Ãtienne Simon (ejls)"
+ [/entry]
+ [entry]
name = "Etkin Baris Ozgul (pokhbocee)"
comment = "Lua AI"
ircuser = "pokhbocee"
Modified: trunk/src/ai/contexts.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/contexts.cpp?rev=53754&r1=53753&r2=53754&view=diff
==============================================================================
--- trunk/src/ai/contexts.cpp (original)
+++ trunk/src/ai/contexts.cpp Mon Apr 2 20:07:01 2012
@@ -964,7 +964,6 @@
map_location locs[6];
get_adjacent_tiles(loc,locs);
- const int lawful_bonus =
resources::tod_manager->get_time_of_day().lawful_bonus;
gamemap& map_ = *resources::game_map;
unit_map& units_ = *resources::units;
@@ -1006,6 +1005,13 @@
const unit& un = *u;
+ // The unit might play on the next turn
+ int attack_turn = resources::tod_manager->turn();
+ if(un.side() < get_side()) {
+ ++attack_turn;
+ }
+ // Considering the unit location would be too slow, we
only apply the bonus granted by the global ToD
+ const int lawful_bonus =
resources::tod_manager->get_time_of_day(attack_turn).lawful_bonus;
int tod_modifier = 0;
if(un.alignment() == unit_type::LAWFUL) {
tod_modifier = lawful_bonus;
Modified: trunk/src/ai/testing/aspect_attacks.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/testing/aspect_attacks.cpp?rev=53754&r1=53753&r2=53754&view=diff
==============================================================================
--- trunk/src/ai/testing/aspect_attacks.cpp (original)
+++ trunk/src/ai/testing/aspect_attacks.cpp Mon Apr 2 20:07:01 2012
@@ -110,7 +110,7 @@
analysis.support = 0.0;
do_attack_analysis(j->get_location(), srcdst, dstsrc,
fullmove_srcdst, fullmove_dstsrc, enemy_srcdst,
enemy_dstsrc,
-
adjacent,used_locations,unit_locs,*res,analysis, current_team(), this);
+
adjacent,used_locations,unit_locs,*res,analysis, current_team());
}
}
return res;
@@ -127,9 +127,8 @@
std::vector<map_location>& units,
std::vector<attack_analysis>& result,
attack_analysis& cur_analysis,
- const team ¤t_team,
- const readonly_context *ai_obj
- )
+ const team ¤t_team
+ ) const
{
// This function is called fairly frequently, so interact with the user
here.
@@ -297,10 +296,10 @@
// Find out how vulnerable we are to attack from enemy
units in this hex.
//FIXME: suokko's r29531 multiplied this by a constant
1.5. ?
- const double vulnerability =
power_projection2(tiles[j],enemy_dstsrc);//?
+ const double vulnerability =
power_projection(tiles[j],enemy_dstsrc);//?
// Calculate how much support we have on this hex from
allies.
- const double support = power_projection2(tiles[j],
fullmove_dstsrc);//?
+ const double support = power_projection(tiles[j],
fullmove_dstsrc);//?
// If this is a position with equal defense to another
position,
// but more vulnerability then we don't want to use it.
@@ -340,14 +339,12 @@
cur_analysis.support += best_support;
cur_analysis.is_surrounded = is_surrounded;
- if (ai_obj!=NULL) {
- cur_analysis.analyze(map_, units_, *ai_obj, dstsrc,
srcdst, enemy_dstsrc, ai_obj->get_aggression());
- }
+ cur_analysis.analyze(map_, units_, *this, dstsrc,
srcdst, enemy_dstsrc, get_aggression());
result.push_back(cur_analysis);
used_locations[cur_position] = true;
do_attack_analysis(loc,srcdst,dstsrc,fullmove_srcdst,fullmove_dstsrc,enemy_srcdst,enemy_dstsrc,
tiles,used_locations,
- units,result,cur_analysis, current_team,
ai_obj);
+ units,result,cur_analysis, current_team);
used_locations[cur_position] = false;
@@ -405,216 +402,6 @@
return cfg;
}
-double aspect_attacks::power_projection(const map_location& loc, const
move_map& dstsrc) const
-{
- map_location used_locs[6];
- int ratings[6];
- int num_used_locs = 0;
-
- map_location locs[6];
- get_adjacent_tiles(loc,locs);
-
- const int lawful_bonus =
resources::tod_manager->get_time_of_day().lawful_bonus;
- gamemap& map_ = *resources::game_map;
- unit_map& units_ = *resources::units;
-
- int res = 0;
-
- bool changed = false;
- for (int i = 0;; ++i) {
- if (i == 6) {
- if (!changed) break;
- // Loop once again, in case a unit found a better spot
- // and freed the place for another unit.
- changed = false;
- i = 0;
- }
-
- if (map_.on_board(locs[i]) == false) {
- continue;
- }
-
- const t_translation::t_terrain terrain = map_[locs[i]];
-
- typedef move_map::const_iterator Itor;
- typedef std::pair<Itor,Itor> Range;
- Range its = dstsrc.equal_range(locs[i]);
-
- map_location* const beg_used = used_locs;
- map_location* end_used = used_locs + num_used_locs;
-
- int best_rating = 0;
- map_location best_unit;
-
- for(Itor it = its.first; it != its.second; ++it) {
- const unit_map::const_iterator u =
units_.find(it->second);
-
- // Unit might have been killed, and no longer exist
- if(u == units_.end()) {
- continue;
- }
-
- const unit &un = *u;
-
- int tod_modifier = 0;
- if(un.alignment() == unit_type::LAWFUL) {
- tod_modifier = lawful_bonus;
- } else if(un.alignment() == unit_type::CHAOTIC) {
- tod_modifier = -lawful_bonus;
- } else if(un.alignment() == unit_type::LIMINAL) {
- tod_modifier = -(abs(lawful_bonus));
- }
-
- // The 0.5 power avoids underestimating too much the
damage of a wounded unit.
- int hp = int(sqrt(double(un.hitpoints()) /
un.max_hitpoints()) * 1000);
- int most_damage = 0;
- foreach (const attack_type &att, un.attacks())
- {
- int damage = att.damage() * att.num_attacks() *
(100 + tod_modifier);
- if (damage > most_damage) {
- most_damage = damage;
- }
- }
-
- int village_bonus = map_.is_village(terrain) ? 3 : 2;
- int defense = 100 - un.defense_modifier(terrain);
- int rating = hp * defense * most_damage * village_bonus
/ 200;
- if(rating > best_rating) {
- map_location *pos = std::find(beg_used,
end_used, it->second);
- // Check if the spot is the same or better than
an older one.
- if (pos == end_used || rating >= ratings[pos -
beg_used]) {
- best_rating = rating;
- best_unit = it->second;
- }
- }
- }
-
- if (!best_unit.valid()) continue;
- map_location *pos = std::find(beg_used, end_used, best_unit);
- int index = pos - beg_used;
- if (index == num_used_locs)
- ++num_used_locs;
- else if (best_rating == ratings[index])
- continue;
- else {
- // The unit was in another spot already, so remove its
older rating
- // from the final result, and require a new run to fill
its old spot.
- res -= ratings[index];
- changed = true;
- }
- used_locs[index] = best_unit;
- ratings[index] = best_rating;
- res += best_rating;
- }
-
- return res / 100000.;
-}
-double aspect_attacks::power_projection2(const map_location& loc, const
move_map& dstsrc)
-{
- map_location used_locs[6];
- int ratings[6];
- int num_used_locs = 0;
-
- map_location locs[6];
- get_adjacent_tiles(loc,locs);
-
- const int lawful_bonus =
resources::tod_manager->get_time_of_day().lawful_bonus;
- gamemap& map_ = *resources::game_map;
- unit_map& units_ = *resources::units;
-
- int res = 0;
-
- bool changed = false;
- for (int i = 0;; ++i) {
- if (i == 6) {
- if (!changed) break;
- // Loop once again, in case a unit found a better spot
- // and freed the place for another unit.
- changed = false;
- i = 0;
- }
-
- if (map_.on_board(locs[i]) == false) {
- continue;
- }
-
- const t_translation::t_terrain terrain = map_[locs[i]];
-
- typedef move_map::const_iterator Itor;
- typedef std::pair<Itor,Itor> Range;
- Range its = dstsrc.equal_range(locs[i]);
-
- map_location* const beg_used = used_locs;
- map_location* end_used = used_locs + num_used_locs;
-
- int best_rating = 0;
- map_location best_unit;
-
- for(Itor it = its.first; it != its.second; ++it) {
- const unit_map::const_iterator u =
units_.find(it->second);
-
- // Unit might have been killed, and no longer exist
- if(u == units_.end()) {
- continue;
- }
-
- const unit &un = *u;
-
- int tod_modifier = 0;
- if(un.alignment() == unit_type::LAWFUL) {
- tod_modifier = lawful_bonus;
- } else if(un.alignment() == unit_type::CHAOTIC) {
- tod_modifier = -lawful_bonus;
- } else if(un.alignment() == unit_type::LIMINAL) {
- tod_modifier = -(abs(lawful_bonus));
- }
-
- // The 0.5 power avoids underestimating too much the
damage of a wounded unit.
- int hp = int(sqrt(double(un.hitpoints()) /
un.max_hitpoints()) * 1000);
- int most_damage = 0;
- foreach (const attack_type &att, un.attacks())
- {
- int damage = att.damage() * att.num_attacks() *
(100 + tod_modifier);
- if (damage > most_damage) {
- most_damage = damage;
- }
- }
-
- int village_bonus = map_.is_village(terrain) ? 3 : 2;
- int defense = 100 - un.defense_modifier(terrain);
- int rating = hp * defense * most_damage * village_bonus
/ 200;
- if(rating > best_rating) {
- map_location *pos = std::find(beg_used,
end_used, it->second);
- // Check if the spot is the same or better than
an older one.
- if (pos == end_used || rating >= ratings[pos -
beg_used]) {
- best_rating = rating;
- best_unit = it->second;
- }
- }
- }
-
- if (!best_unit.valid()) continue;
- map_location *pos = std::find(beg_used, end_used, best_unit);
- int index = pos - beg_used;
- if (index == num_used_locs)
- ++num_used_locs;
- else if (best_rating == ratings[index])
- continue;
- else {
- // The unit was in another spot already, so remove its
older rating
- // from the final result, and require a new run to fill
its old spot.
- res -= ratings[index];
- changed = true;
- }
- used_locs[index] = best_unit;
- ratings[index] = best_rating;
- res += best_rating;
- }
-
- return res / 100000.;
-}
-
-
} // end of namespace testing_ai_default
} // end of namespace ai
Modified: trunk/src/ai/testing/aspect_attacks.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai/testing/aspect_attacks.hpp?rev=53754&r1=53753&r2=53754&view=diff
==============================================================================
--- trunk/src/ai/testing/aspect_attacks.hpp (original)
+++ trunk/src/ai/testing/aspect_attacks.hpp Mon Apr 2 20:07:01 2012
@@ -52,7 +52,7 @@
protected:
boost::shared_ptr<attacks_vector> analyze_targets() const;
- static void do_attack_analysis(const map_location& loc,
+ void do_attack_analysis(const map_location& loc,
const move_map& srcdst, const move_map& dstsrc,
const move_map& fullmove_srcdst, const move_map&
fullmove_dstsrc,
const move_map& enemy_srcdst, const move_map&
enemy_dstsrc,
@@ -60,11 +60,8 @@
std::vector<map_location>& units,
std::vector<attack_analysis>& result,
attack_analysis& cur_analysis,
- const team ¤t_team,
- const readonly_context *ai_obj);
+ const team ¤t_team) const;
static int rate_terrain(const unit& u, const map_location& loc);
- double power_projection(const map_location& loc, const move_map&
dstsrc) const;
- static double power_projection2(const map_location& loc, const
move_map& dstsrc);
config filter_own_;
config filter_enemy_;
};
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits