33 #define DBG_AI LOG_STREAM(debug, log_ai)
34 #define LOG_AI LOG_STREAM(info, log_ai)
35 #define WRN_AI LOG_STREAM(warn, log_ai)
36 #define ERR_AI LOG_STREAM(err, log_ai)
75 for(
size_t n = 0;
n != 6; ++
n) {
76 if (checked_hexes.find(adj[
n]) != checked_hexes.end())
78 checked_hexes.insert(adj[n]);
84 && u->invisible(adj[n]))
86 && u->movement_left() > 0)) {
105 int rating = 100 - defense;
107 const int healing_value = 10;
108 const int friendly_village_value = 5;
109 const int neutral_village_value = 10;
110 const int enemy_village_value = 15;
113 rating += healing_value;
120 rating += friendly_village_value;
121 }
else if(owner == 0) {
122 rating += neutral_village_value;
124 rating += enemy_village_value;
139 const bool has_leader = leader != units_.
end();
141 std::vector<target> targets;
150 std::set<map_location> threats;
154 for(
size_t n = 0;
n != 6; ++
n) {
155 std::pair<move_map::const_iterator,move_map::const_iterator> itors = enemy_dstsrc.equal_range(adj[
n]);
156 while(itors.first != itors.second) {
157 if(units_.
count(itors.first->second)) {
158 threats.insert(itors.first->second);
165 assert(threats.empty() ==
false);
169 const double value = threat*get_protect_leader()/leader->second.hitpoints();
171 const double value = threat/double(threats.size());
173 for(std::set<map_location>::const_iterator
i = threats.begin();
i != threats.end(); ++
i) {
174 LOG_AI <<
"found threat target... " << *
i <<
" with value: " << value <<
"\n";
175 targets.push_back(
target(*
i,value,target::TYPE::THREAT));
182 if(has_leader && village_value > 0.0) {
183 std::map<map_location,pathfind::paths> friends_possible_moves;
184 move_map friends_srcdst, friends_dstsrc;
187 const std::vector<map_location>& villages = map_.
villages();
188 for(std::vector<map_location>::const_iterator
t =
189 villages.begin();
t != villages.end(); ++
t) {
192 bool ally_village =
false;
193 for (
size_t i = 0;
i != teams_.size(); ++
i)
211 double value = village_value * our / enemy;
219 double value = village_value * (1.0 - leader_distance / corner_distance);
220 LOG_AI <<
"found village target... " << *
t
221 <<
" with value: " << value
222 <<
" distance: " << leader_distance <<
'\n';
223 targets.push_back(
target(*
t,value,target::TYPE::VILLAGE));
228 std::vector<goal_ptr>& goals =
get_goals();
233 for(u = units_.
begin(); u != units_.
end(); ++u) {
236 && !u->invisible(u->get_location())) {
237 assert(map_.
on_board(u->get_location()));
238 LOG_AI <<
"found enemy leader (side: " << u->side() <<
") target... " << u->get_location() <<
" with value: " <<
get_leader_value() <<
"\n";
247 j != goals.end(); ++j) {
249 if (!(*j)->active()) {
252 (*j)->add_targets(std::back_inserter(targets));
258 std::vector<double> new_values;
261 i != targets.end(); ++
i) {
263 new_values.push_back(
i->value);
265 for(std::vector<target>::const_iterator j = targets.begin(); j != targets.end(); ++j) {
266 if(
i->loc == j->loc) {
270 const double distance = abs(j->loc.x -
i->loc.x) +
271 abs(j->loc.y -
i->loc.y);
272 new_values.back() += j->value/(distance*distance);
276 assert(new_values.size() == targets.size());
277 for(
size_t n = 0;
n != new_values.size(); ++
n) {
278 LOG_AI <<
"target value: " << targets[
n].value <<
" -> " << new_values[
n] <<
"\n";
279 targets[
n].value = new_values[
n];
virtual side_number get_side() const
Get the side number.
virtual default_ai_context & get_default_ai_context()=0
virtual void add_target(const target &t) const
virtual int rate_terrain(const unit &u, const map_location &loc) const
size_t count(const map_location &loc) const
unit_iterator find_leader(int side)
virtual double get_leader_value() const
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
bool is_village(const map_location &loc) const
bool is_enemy(int n) const
static const map_location & ZERO()
Old implementation:
int village_owner(const map_location &loc) const
Given the location of a village, will return the 0-based index of the team that currently owns it...
int count_free_hexes_in_castle(const map_location &loc, std::set< map_location > &checked_hexes)
virtual const std::vector< goal_ptr > & get_goals() const
virtual std::vector< target > find_targets(const move_map &enemy_dstsrc)
bool get_ability_bool(const std::string &tag_name, const map_location &loc) const
Returns true if the unit is currently under effect by an ability with this given TAG NAME...
int defense_modifier(const t_translation::t_terrain &terrain) const
virtual double power_projection(const map_location &loc, const move_map &dstsrc) const
Function which finds how much 'power' a side can attack a certain location with.
std::multimap< map_location, map_location > move_map
The standard way in which a map of possible moves is recorded.
A small explanation about what's going on here: Each action has access to two game_info objects First...
std::vector< team > * teams
default_ai_context()
Constructor.
size_t distance_between(const map_location &a, const map_location &b)
Function which gives the number of hexes between two tiles (i.e.
virtual default_ai_context & get_default_ai_context()
GLsizei const GLfloat * value
static lg::log_domain log_ai("ai/general")
int w() const
Effective map width.
Encapsulates the map of the game.
#define log_scope2(domain, description)
virtual void calculate_possible_moves(std::map< map_location, pathfind::paths > &possible_moves, move_map &srcdst, move_map &dstsrc, bool enemy, bool assume_full_movement=false, const terrain_filter *remove_destinations=nullptr) const
static const ::config * terrain
The terrain used to create the cache.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
void init_default_ai_context_proxy(default_ai_context &target)
Encapsulates the map of the game.
virtual bool get_support_villages() const
int h() const
Effective map height.
virtual ~default_ai_context()
Destructor.
virtual config to_default_ai_context_config() const
boost::shared_ptr< std::vector< unit_const_ptr > > units_
virtual const team & current_team() const
virtual const gamemap & map() const
t_translation::t_terrain get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
virtual ~default_ai_context_proxy()
default_ai_context * target_
virtual double get_village_value() const
virtual void clear_additional_targets() const
Standard logging facilities (interface).
Container associating units to locations.
void init_readwrite_context_proxy(readwrite_context &target)
std::vector< target > additional_targets_
unit_iterator find(size_t id)
A config object defines a single node in a WML file, with access to child nodes.
const std::vector< map_location > & villages() const
Return a list of the locations of villages on the map.
virtual ~default_ai_context_impl()
This module contains various pathfinding functions and utilities.
virtual const std::vector< target > & additional_targets() const
int gives_healing(const map_location &loc) const