34 #define DBG_AI LOG_STREAM(debug, log_ai)
35 #define LOG_AI LOG_STREAM(info, log_ai)
36 #define WRN_AI LOG_STREAM(warn, log_ai)
37 #define ERR_AI LOG_STREAM(err, log_ai)
72 if (checked_hexes.find(adj) != checked_hexes.end())
82 && u->movement_left() > 0)) {
99 int rating = 100 - defense;
101 const int healing_value = 10;
102 const int friendly_village_value = 5;
103 const int neutral_village_value = 10;
104 const int enemy_village_value = 15;
107 rating += healing_value;
114 rating += friendly_village_value;
115 }
else if(owner == 0) {
116 rating += neutral_village_value;
118 rating += enemy_village_value;
132 const bool has_leader = leader != units_.
end();
134 std::vector<target> targets;
143 std::set<map_location> threats;
146 std::pair<move_map::const_iterator,move_map::const_iterator> itors = enemy_dstsrc.equal_range(adj);
147 while(itors.first != itors.second) {
148 if(units_.
count(itors.first->second)) {
149 threats.insert(itors.first->second);
156 assert(threats.empty() ==
false);
158 const double value = threat/
static_cast<double>(threats.size());
159 for(std::set<map_location>::const_iterator
i = threats.begin();
i != threats.end(); ++
i) {
160 LOG_AI <<
"found threat target... " << *
i <<
" with value: " << value;
161 targets.emplace_back(*
i,value,ai_target::type::threat);
168 if(has_leader && village_value > 0.0) {
169 std::map<map_location,pathfind::paths> friends_possible_moves;
170 move_map friends_srcdst, friends_dstsrc;
176 bool ally_village =
false;
178 if(!
current_team().is_enemy(
t.side()) &&
t.owns_village(village_loc)) {
194 double value = village_value * our /
enemy;
201 double leader_distance =
distance_between(village_loc, leader->get_location());
202 double value = village_value * (1.0 - leader_distance / corner_distance);
203 LOG_AI <<
"found village target... " << village_loc
204 <<
" with value: " << value
205 <<
" distance: " << leader_distance;
206 targets.emplace_back(village_loc,value,ai_target::type::village);
211 std::vector<goal_ptr>& goals =
get_goals();
216 for(u = units_.
begin(); u != units_.
end(); ++u) {
218 if (u->can_recruit() &&
current_team().is_enemy(u->side())
219 && !u->invisible(u->get_location())) {
220 assert(map_.
on_board(u->get_location()));
221 LOG_AI <<
"found enemy leader (side: " << u->side() <<
") target... " << u->get_location() <<
" with value: " <<
get_leader_value();
222 targets.emplace_back(u->get_location(),
get_leader_value(), ai_target::type::leader);
230 j != goals.end(); ++j) {
232 if (!(*j)->active()) {
235 (*j)->add_targets(std::back_inserter(targets));
241 std::vector<double> new_values;
244 i != targets.end(); ++
i) {
246 new_values.push_back(
i->value);
248 for(std::vector<target>::const_iterator j = targets.begin(); j != targets.end(); ++j) {
249 if(
i->loc == j->loc) {
253 const double distance = std::abs(j->loc.x -
i->loc.x) +
254 std::abs(j->loc.y -
i->loc.y);
255 new_values.back() += j->value/(distance*distance);
259 assert(new_values.size() == targets.size());
260 for(std::size_t
n = 0;
n != new_values.size(); ++
n) {
261 LOG_AI <<
"target value: " << targets[
n].value <<
" -> " << new_values[
n];
262 targets[
n].value = new_values[
n];
virtual default_ai_context & get_default_ai_context()
virtual void clear_additional_targets() const
virtual const std::vector< target > & additional_targets() const
virtual int rate_terrain(const unit &u, const map_location &loc) const
virtual std::vector< target > find_targets(const move_map &enemy_dstsrc)
virtual ~default_ai_context_impl()
virtual config to_default_ai_context_config() const
int count_free_hexes_in_castle(const map_location &loc, std::set< map_location > &checked_hexes)
virtual void add_target(const target &t) const
std::vector< target > additional_targets_
virtual ~default_ai_context_proxy()
default_ai_context * target_
void init_default_ai_context_proxy(default_ai_context &target)
default_ai_context()
Constructor.
virtual ~default_ai_context()
Destructor.
virtual const team & current_team() const override
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 override
virtual const std::vector< goal_ptr > & get_goals() const override
virtual double power_projection(const map_location &loc, const move_map &dstsrc) const override
Function which finds how much 'power' a side can attack a certain location with.
virtual double get_village_value() const override
virtual double get_leader_value() const override
virtual bool get_support_villages() const override
void init_readwrite_context_proxy(readwrite_context &target)
virtual side_number get_side() const override
Get the side number.
A config object defines a single node in a WML file, with access to child nodes.
int village_owner(const map_location &loc) const
Given the location of a village, will return the 1-based number of the team that currently owns it,...
virtual const unit_map & units() const override
virtual const gamemap & map() const override
terrain_code get_terrain(const map_location &loc) const
Looks up terrain at a particular location.
int w() const
Effective map width.
int h() const
Effective map height.
bool on_board(const map_location &loc) const
Tell if a location is on the map.
Encapsulates the map of the game.
bool is_village(const map_location &loc) const
const std::vector< map_location > & villages() const
Return a list of the locations of villages on the map.
int gives_healing(const map_location &loc) const
This class stores all the data for a single 'side' (in game nomenclature).
Container associating units to locations.
std::size_t count(const map_location &loc) const
unit_iterator find(std::size_t id)
unit_iterator find_leader(int side)
umap_retval_pair_t insert(unit_ptr p)
Inserts the unit pointed to by p into the map.
This class represents a single unit of a specific type.
static lg::log_domain log_ai("ai/general")
bool get_ability_bool(const std::string &tag_name, const map_location &loc) const
Checks whether this unit currently possesses or is affected by a given ability.
int defense_modifier(const t_translation::terrain_code &terrain) const
The unit's defense on a given terrain.
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
std::size_t distance_between(const map_location &a, const map_location &b)
Function which gives the number of hexes between two tiles (i.e.
Standard logging facilities (interface).
#define log_scope2(domain, description)
A small explanation about what's going on here: Each action has access to two game_info objects First...
std::multimap< map_location, map_location > move_map
The standard way in which a map of possible moves is recorded.
std::string::const_iterator iterator
@ enemy
Belongs to a non-friendly side; normally visualised by not displaying an orb.
This module contains various pathfinding functions and utilities.
Encapsulates the map of the game.
static const map_location & ZERO()
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
static map_location::direction n