42 #define DBG_AI_TESTING_AI_DEFAULT LOG_STREAM(debug, log_ai_testing_ai_default)
43 #define LOG_AI_TESTING_AI_DEFAULT LOG_STREAM(info, log_ai_testing_ai_default)
44 #define WRN_AI_TESTING_AI_DEFAULT LOG_STREAM(warn, log_ai_testing_ai_default)
45 #define ERR_AI_TESTING_AI_DEFAULT LOG_STREAM(err, log_ai_testing_ai_default)
50 namespace ai_default_rca {
67 std::vector<map_location> gotos;
72 if (ui->get_goto() == ui->get_location()) {
75 gotos.push_back(ui->get_location());
79 for(std::vector<map_location>::const_iterator
g = gotos.begin();
g != gotos.end(); ++
g) {
92 route =
pathfind::a_star_search(ui->get_location(), ui->get_goto(), 10000.0, &calc, map_.
w(), map_.
h(), &allowed_teleports);
94 if (!route.
steps.empty()){
101 int closest_distance = -1;
102 std::pair<map_location,map_location> closest_move;
104 if(
i->second != ui->get_location()) {
108 if(closest_distance == -1 || distance < closest_distance) {
109 closest_distance = distance;
113 if(closest_distance != -1) {
120 if (
move_->is_ok()) {
135 if (!
move_->is_ok()){
142 if (!
move_->is_gamestate_changed()){
166 int ticks = SDL_GetTicks();
168 const std::vector<attack_analysis> analysis =
get_attacks();
170 int time_taken = SDL_GetTicks() - ticks;
172 <<
" positions. Analyzing...\n";
174 ticks = SDL_GetTicks();
176 const int max_sims = 50000;
177 int num_sims = analysis.empty() ? 0 : max_sims/analysis.size();
185 const int max_positions = 30000;
186 const int skip_num = analysis.size()/max_positions;
188 std::vector<attack_analysis>::const_iterator choice_it = analysis.end();
189 for(std::vector<attack_analysis>::const_iterator it = analysis.begin();
190 it != analysis.end(); ++it) {
192 if(skip_num > 0 && ((it - analysis.begin())%skip_num) && it->movements.size() > 1)
205 time_taken = SDL_GetTicks() - ticks;
229 if (!move_res->is_ok()) {
236 if (!attack_res->is_ok()) {
239 attack_res->execute();
240 if (!attack_res->is_ok()) {
273 double max_risk = goal[
"max_risk"].to_double(1 -
get_caution());
283 if (!leader.
valid() || leader->incapacitated()) {
288 id_ = goal[
"id"].str();
289 if (leader->get_location() ==
dst_) {
295 if (
move_->is_ok()) {
306 if(route.
steps.empty()) {
313 std::map<map_location,pathfind::paths> possible_moves;
314 possible_moves.insert(std::pair<map_location,pathfind::paths>(leader->get_location(), leader_paths));
328 if (
move_->is_ok()) {
339 if (!
move_->is_ok()){
354 mod_ai[
"path"] =
"aspect[leader_goal].facet["+
id+
"]";
355 mod_ai[
"action"] =
"delete";
391 if (leaders.empty()) {
396 const unit* best_leader =
nullptr;
398 int shortest_distance = 99999;
401 if (leader->incapacitated() || leader->movement_left() == 0) {
407 const ai::moves_map::const_iterator& p_it = possible_moves.find(leader->get_location());
408 if (p_it == possible_moves.end()) {
425 if (!route.
steps.empty() || route.
move_cost < shortest_distance) {
426 best_leader = &(*leader);
432 if (best_leader ==
nullptr) {
437 const unit* leader = best_leader;
445 if (
move_->is_ok()) {
455 typedef std::multimap<int, map_location> ordered_locations;
456 ordered_locations moves_toward_keep;
463 int next_hop_cost = 0;
476 moves_toward_keep.insert(std::make_pair(0, next_hop));
483 moves_toward_keep.insert(std::make_pair(route.
move_cost, dest.
curr));
490 for (
const ordered_locations::value_type& pair : moves_toward_keep) {
494 if (
move_->is_ok()) {
505 if (!
move_->is_ok()) {
544 std::pair<map_location,map_location> leader_move;
546 for(tmoves::const_iterator
i =
moves_.begin();
i !=
moves_.end(); ++
i) {
548 if(leader != units_.
end() && leader->get_location() ==
i->second) {
553 if (!move_res->is_ok()) {
561 if (new_unit != units_.
end() &&
576 if(leader_move.second.valid()) {
580 if (!move_res->is_ok()) {
595 const int ticks = SDL_GetTicks();
597 if(leader != units_.
end()) {
610 u_itor != units_.
end(); ++u_itor) {
614 if(u_itor->side() ==
get_side() && u_itor->movement_left()) {
615 reachmap.insert(std::make_pair(u_itor->get_location(), std::vector<map_location>()));
625 while(itor != reachmap.end()) {
626 if(itor->second.size() == 0) {
633 if(!reachmap.empty()) {
635 "can't reach a village, send the to the dispatcher.\n";
645 <<
" ms, resulted in " <<
moves_.size() <<
" units being dispatched.\n";
652 const std::multimap<map_location,map_location>& dstsrc,
653 const std::multimap<map_location,map_location>& enemy_dstsrc)
656 std::map<map_location, double> vulnerability;
660 size_t min_distance = 100000;
666 std::vector<map_location> dispatched_units;
667 for(std::multimap<map_location, map_location>::const_iterator
669 j != dstsrc.end(); ++j) {
679 if(distance < min_distance) {
680 min_distance = distance;
685 if(
std::find(dispatched_units.begin(), dispatched_units.end(),
686 j->second) != dispatched_units.end()) {
694 bool want_village =
true, owned =
false;
695 for(
size_t n = 0;
n != teams_.size(); ++
n) {
696 owned = teams_[
n].owns_village(current_loc);
698 want_village =
false;
706 if(want_village ==
false) {
717 const std::map<map_location,double>::const_iterator vuln = vulnerability.find(current_loc);
718 if(vuln != vulnerability.end()) {
719 threat = vuln->second;
722 vulnerability.insert(std::pair<map_location,double>(current_loc,threat));
740 std::multimap<map_location, map_location>::const_iterator
next = j;
742 const bool at_begin = (j == dstsrc.begin());
743 std::multimap<map_location, map_location>::const_iterator
prev = j;
748 if((next == dstsrc.end() || next->first != current_loc)
749 && (at_begin || prev->first != current_loc)) {
752 if (move_check_res->is_ok()) {
754 moves.push_back(std::make_pair(j->first, j->second));
756 reachmap.erase(j->second);
757 dispatched_units.push_back(j->second);
761 reachmap[j->second].push_back(current_loc);
765 << reachmap.size() <<
" left to evaluate.\n";
779 size_t village_count = 0;
780 bool dispatched =
true;
787 if(reachmap.empty()) {
798 if(reachmap.empty()) {
806 if(reachmap.size() != 0 && dispatched) {
813 if(reachmap.size() == 0) {
819 << village_count <<
" villages left.\n";
833 while(itor != reachmap.end()) {
834 if(itor->second.size() == 1) {
839 moves.push_back(std::make_pair(village, itor->first));
840 reachmap.erase(itor++);
843 itor = reachmap.begin();
852 if(reachmap.empty()) {
857 if(reachmap.size() == 1) {
860 <<
" to village " << reachmap.begin()->second[0] <<
'\n';
862 moves.push_back(std::make_pair(
863 reachmap.begin()->second[0], reachmap.begin()->first));
878 bool dispatched =
true;
884 std::vector<map_location > >reversemap;
886 treachmap::const_iterator
itor = reachmap.begin();
887 for(;itor != reachmap.end(); ++
itor) {
889 for(std::vector<map_location>::const_iterator
890 v_itor = itor->second.begin();
891 v_itor != itor->second.end(); ++v_itor) {
893 reversemap[*v_itor].push_back(itor->first);
898 village_count = reversemap.size();
900 itor = reversemap.begin();
901 while(itor != reversemap.end()) {
902 if(itor->second.size() == 1) {
904 const map_location village = itor->first;
909 moves.push_back(std::make_pair(itor->first, itor->second[0]));
911 reachmap.erase(itor->second[0]);
930 while(itor != reachmap.end()) {
931 itor->second.erase(
std::remove(itor->second.begin(), itor->second.end(), village), itor->second.end());
932 if(itor->second.empty()) {
945 assert(unit->second.empty());
951 moves.push_back(std::make_pair(best_leader_loc_,
leader_loc_));
954 reachmap.erase(unit++);
963 const size_t unit_count = reachmap.size();
965 const size_t max_result = unit_count < village_count ? unit_count : village_count;
967 assert(unit_count >= 2 && village_count >= 2);
970 if(unit_count == 2 && village_count == 2) {
976 std::vector<map_location>
units(unit_count);
977 std::vector<size_t> villages_per_unit(unit_count);
978 std::vector<map_location> villages;
979 std::vector<size_t> units_per_village(village_count);
983 std::multimap<
size_t ,
984 size_t > unit_lookup;
986 std::vector<std::vector<
bool> >
987 matrix(reachmap.size(), std::vector<bool>(village_count,
false));
989 treachmap::const_iterator
itor = reachmap.begin();
990 for(
size_t u = 0; u < unit_count; ++u, ++
itor) {
991 units[u] = itor->first;
992 villages_per_unit[u] = itor->second.size();
993 unit_lookup.insert(std::make_pair(villages_per_unit[u], u));
995 assert(itor->second.size() >= 2);
997 for(
size_t v = 0;
v < itor->second.size(); ++
v) {
1001 std::vector<map_location>::const_iterator v_itor =
1002 std::find(villages.begin(), villages.end(), itor->second[
v]);
1003 if(v_itor == villages.end()) {
1004 v_index = villages.size();
1005 villages.push_back(itor->second[
v]);
1007 v_index = v_itor - villages.begin();
1010 units_per_village[v_index]++;
1012 matrix[u][v_index] =
true;
1015 for(std::vector<size_t>::const_iterator upv_it = units_per_village.begin();
1016 upv_it != units_per_village.end(); ++upv_it) {
1018 assert(*upv_it >=2);
1023 std::cerr <<
"Reach matrix:\n\nvillage";
1025 for(v = 0; v < village_count; ++
v) {
1026 std::cerr <<
'\t' << villages[
v];
1028 std::cerr <<
"\ttotal\nunit\n";
1031 for(u = 0; u < unit_count; ++u) {
1032 std::cerr << units[u];
1034 for(
size_t v = 0; v < village_count; ++
v) {
1035 std::cerr <<
'\t' << matrix[u][
v];
1037 std::cerr <<
"\t" << villages_per_unit[u] <<
'\n';
1041 std::cerr <<
"total";
1042 for(v = 0; v < village_count; ++
v) {
1043 std::cerr <<
'\t' << units_per_village[
v];
1049 const bool reach_all = ((village_count == unit_count)
1050 && (std::accumulate(villages_per_unit.begin(), villages_per_unit.end(), size_t())
1051 == (village_count * unit_count)));
1061 std::multimap<
size_t ,
size_t >
1062 ::const_iterator src_itor = unit_lookup.begin();
1064 while(src_itor != unit_lookup.end() && src_itor->first == 2) {
1066 for(std::multimap<size_t, size_t>::const_iterator
1067 dst_itor = unit_lookup.begin();
1068 dst_itor != unit_lookup.end(); ++ dst_itor) {
1071 if(src_itor == dst_itor) {
1075 std::vector<bool>
result;
1076 std::transform(matrix[src_itor->second].begin(), matrix[src_itor->second].end(),
1077 matrix[dst_itor->second].begin(),
1078 std::back_inserter(result),
1079 std::logical_and<bool>()
1082 size_t matched =
std::count(result.begin(), result.end(),
true);
1090 const map_location village1 = villages[first - result.begin()];
1091 const map_location village2 = villages[second - result.begin()];
1093 const bool perfect = (src_itor->first == 2 &&
1094 dst_itor->first == 2 &&
1095 units_per_village[first - result.begin()] == 2 &&
1096 units_per_village[second - result.begin()] == 2);
1100 <<
" to village " << village1 <<
'\n';
1101 moves.push_back(std::make_pair(village1, units[src_itor->second]));
1104 <<
" to village " << village2 <<
'\n';
1105 moves.push_back(std::make_pair(village2, units[dst_itor->second]));
1108 reachmap.erase(units[src_itor->second]);
1109 reachmap.erase(units[dst_itor->second]);
1141 std::vector<std::pair<map_location, map_location> > best_result;
1149 const size_t max_options = 8;
1150 if(unit_count >= max_options && village_count >= max_options) {
1153 << village_count<<
" found, evaluate only the first "
1154 << max_options <<
" options;\n";
1156 std::vector<size_t> perm (max_options, 0);
1157 for(
size_t i =0;
i < max_options; ++
i) {
1160 while(std::next_permutation(perm.begin(), perm.end())) {
1163 std::vector<std::pair<map_location,map_location> >
result;
1164 for(
size_t u = 0; u < max_options; ++u) {
1165 if(matrix[u][perm[u]]) {
1166 result.push_back(std::make_pair(villages[perm[u]], units[u]));
1170 if(result.size() == max_result) {
1171 best_result.swap(result);
1175 if(result.size() > best_result.size()) {
1176 best_result.swap(result);
1180 moves.insert(moves.end(), best_result.begin(), best_result.end());
1183 for(std::vector<std::pair<map_location, map_location> >::const_iterator
1184 itor = best_result.begin(); itor != best_result.end(); ++
itor) {
1185 reachmap.erase(itor->second);
1192 }
else if(unit_count <= village_count) {
1196 std::vector<size_t> perm (unit_count, 0);
1197 for(
size_t i =0;
i < unit_count; ++
i) {
1200 while(std::next_permutation(perm.begin(), perm.end())) {
1202 std::vector<std::pair<map_location,map_location> >
result;
1203 for(
size_t u = 0; u < unit_count; ++u) {
1204 if(matrix[u][perm[u]]) {
1205 result.push_back(std::make_pair(villages[perm[u]], units[u]));
1209 if(result.size() == max_result) {
1210 moves.insert(moves.end(), result.begin(), result.end());
1215 if(result.size() > best_result.size()) {
1216 best_result.swap(result);
1220 moves.insert(moves.end(), best_result.begin(), best_result.end());
1224 for(std::vector<std::pair<map_location, map_location> >::const_iterator
1225 itor = best_result.begin(); itor != best_result.end(); ++
itor) {
1226 reachmap.erase(itor->second);
1229 if(unit != reachmap.end()) {
1230 unit->second.clear();
1239 std::vector<size_t> perm (village_count, 0);
1240 for(
size_t i =0;
i < village_count; ++
i) {
1243 while(std::next_permutation(perm.begin(), perm.end())) {
1245 std::vector<std::pair<map_location,map_location> >
result;
1246 for(
size_t v = 0;
v < village_count; ++
v) {
1247 if(matrix[perm[
v]][
v]) {
1248 result.push_back(std::make_pair(villages[v], units[perm[v]]));
1252 if(result.size() == max_result) {
1253 moves.insert(moves.end(), result.begin(), result.end());
1258 if(result.size() > best_result.size()) {
1259 best_result.swap(result);
1263 moves.insert(moves.end(), best_result.begin(), best_result.end());
1267 for(std::vector<std::pair<map_location, map_location> >::const_iterator
1268 itor = best_result.begin(); itor != best_result.end(); ++
itor) {
1269 reachmap.erase(itor->second);
1272 if(unit != reachmap.end()) {
1273 unit->second.clear();
1282 treachmap::const_iterator
itor = reachmap.begin();
1283 for(
size_t i = 0;
i < reachmap.size(); ++
i, ++
itor) {
1285 <<
" to village " << itor->second[
i] <<
'\n';
1286 moves.push_back(std::make_pair(itor->second[
i], itor->first));
1296 for(treachmap::const_iterator
itor =
1297 reachmap.begin();
itor != reachmap.end(); ++
itor) {
1299 std::cerr <<
"Reachlist for unit at " <<
itor->first;
1301 if(
itor->second.empty()) {
1302 std::cerr <<
"\tNone";
1305 for(std::vector<map_location>::const_iterator
1306 v_itor =
itor->second.begin();
1307 v_itor !=
itor->second.end(); ++v_itor) {
1309 std::cerr <<
'\t' << *v_itor;
1332 for(; u_it != units_.
end(); ++u_it) {
1348 typedef std::multimap<map_location,map_location>::const_iterator Itor;
1349 std::pair<Itor,Itor> it =
get_srcdst().equal_range(u_it->get_location());
1350 double best_vulnerability = 100000.0;
1352 const double leader_penalty = (u.
can_recruit()?2.0:1.0);
1353 Itor best_loc = it.second;
1354 while(it.first != it.second) {
1359 if(vuln < best_vulnerability) {
1360 best_vulnerability = vuln;
1361 best_loc = it.first;
1371 if(best_loc != it.second && best_vulnerability*leader_penalty < u.
hitpoints()) {
1373 if (
move_->is_ok()) {
1387 if (!
move_->is_ok()){
1412 std::map<map_location,pathfind::paths> dummy_possible_moves;
1424 std::vector<map_location> leaders_adj_v;
1437 leaders_adj_v.push_back(loc);
1446 i->movement_left() ==
i->total_movement() &&
1448 std::find(leaders.begin(), leaders.end(),
i) == leaders.end() &&
1449 !
i->incapacitated())
1456 bool can_reach_leader =
false;
1462 typedef move_map::const_iterator Itor;
1463 std::pair<Itor,Itor> itors =
get_srcdst().equal_range(
i->get_location());
1466 double best_rating = -1000.0;
1467 int best_defensive_rating =
i->defense_modifier(
resources::gameboard->map().get_terrain(
i->get_location()))
1469 while(itors.first != itors.second) {
1473 if(
std::find(leaders_adj_v.begin(), leaders_adj_v.end(), itors.first->second) != leaders_adj_v.end()){
1475 can_reach_leader =
true;
1486 const double rating = our_power - their_power;
1487 if(rating > best_rating) {
1489 best_rating = rating;
1495 if(modified_defense < best_defensive_rating) {
1496 best_defensive_rating = modified_defense;
1497 best_defensive = hex;
1505 if(can_reach_leader) {
1509 if(!best_pos.
valid()) {
1510 best_pos = best_defensive;
1513 if(best_pos.
valid()) {
1515 if (
move_->is_ok()) {
1529 if (!
move_->is_ok()){
1540 if(caution <= 0.0) {
1545 srcdst, enemy_dstsrc).chance_to_hit/100.0;
1546 const double proposed_terrain =
1551 const double exposure = proposed_terrain - optimal_terrain;
1555 return caution*their_power*(1.0+exposure) > our_power;
1600 bool allied_leaders_available =
false;
1604 if (!allied_leaders.empty()){
1605 allied_leaders_available =
true;
1610 if(allied_leaders_available){
1622 typedef std::map<map_location, pathfind::paths> path_map;
1623 path_map possible_moves;
1624 move_map friends_srcdst, friends_dstsrc;
1638 bool friend_can_reach_keep =
false;
1641 for(path_map::const_iterator
i = possible_moves.begin();
i != possible_moves.end(); ++
i){
1643 team &leader_team = (*resources::teams)[itor->side() - 1];
1645 pathfind::paths::dest_vect::const_iterator tokeep =
i->second.destinations.find(keep);
1646 if(tokeep !=
i->second.destinations.end()){
1647 friend_can_reach_keep =
true;
1653 if(friend_can_reach_keep){
1656 int defense_modifier = 100;
1657 for(pathfind::paths::dest_vect::const_iterator
i = possible_moves[keep].destinations.begin()
1658 ;
i != possible_moves[keep].destinations.end()
1663 &&
static_cast<int>(
distance_between(
i->curr, keep)) <= ai_leader->movement_left()){
1666 if(tmp_def_mod < defense_modifier){
1667 defense_modifier = tmp_def_mod;
1668 best_move =
i->curr;
1673 if(defense_modifier < 100){
1677 if (!move->is_ok()){
1680 ai_leader->set_goto(keep);
1687 ai_leader->remove_movement_ai();
1690 leader->remove_movement_ai();
virtual side_number get_side() const
Get the side number.
virtual void execute()
Execute the candidate action.
virtual void execute()
Execute the candidate action.
plain_route a_star_search(const map_location &src, const map_location &dst, double stop_at, const cost_calculator *calc, const size_t width, const size_t height, const teleport_map *teleports, bool border)
std::vector< unit_iterator > find_leaders(int side)
const map_location & get_location() const
virtual config get_leader_goal() const
std::vector< std::pair< map_location, map_location > > tmoves
int max_hitpoints() const
bool get_state(const std::string &state) const
bool dont_log(log_domain const &domain) const
virtual double get_caution() const
void dispatch(treachmap &reachmap, tmoves &moves)
Dispatches all units to their best location.
map_location find_vacant_castle(const unit &leader)
Wrapper for find_vacant_tile() when looking for a vacant castle tile near a leader.
goto_phase(rca_context &context, const config &cfg)
int movement_cost(const t_translation::t_terrain &terrain) const
size_t count(const map_location &loc) const
map_location best_leader_loc_
The best possible location for our leader if it can't reach a village.
unit_iterator find_leader(int side)
void dump_reachmap(treachmap &reachmap)
Shows which villages every unit can reach (debug function).
Managing the AI-Game interaction - AI actions and their results.
void get_adjacent_tiles(const map_location &a, map_location *res)
Function which, given a location, will place all adjacent locations in res.
leader_shares_keep_phase(rca_context &context, const config &cfg)
virtual std::string get_name() const
Get the name of the candidate action (useful for debug purposes)
bool is_village(const map_location &loc) const
std::map< map_location, pathfind::paths > moves_map
The standard way in which a map of possible movement routes to location is recorded.
double get_score() const
Get the usual score of the candidate action without re-evaluation.
virtual void calculate_moves(const unit_map &units, 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, bool see_all=false) const
map_location keep_loc_
Location of the keep the closest to our leader.
bool dispatch_village_simple(treachmap &reachmap, tmoves &moves, size_t &village_count)
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
virtual ~move_leader_to_keep_phase()
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
AI Support engine - creating specific ai components from config.
virtual ~move_leader_to_goals_phase()
virtual const map_location & nearest_keep(const map_location &loc) const
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...
move_leader_to_keep_phase(rca_context &context, const config &cfg)
retreat_phase(rca_context &context, const config &cfg)
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
#define ERR_AI_TESTING_AI_DEFAULT
virtual const attacks_vector & get_attacks() const
bool remove_village(treachmap &reachmap, tmoves &moves, const map_location &village)
Removes a village for all units, returns true if anything is deleted.
int defense_modifier(const t_translation::t_terrain &terrain) const
virtual void execute()
Execute the candidate action.
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
virtual double get_leader_aggression() 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.
GLuint GLenum GLenum transform
std::multimap< map_location, map_location > move_map
The standard way in which a map of possible moves is recorded.
bool contains(const map_location &) const
This class stores all the data for a single 'side' (in game nomenclature).
static lg::log_domain log_ai_testing_ai_default("ai/ca/testing_ai_default")
A small explanation about what's going on here: Each action has access to two game_info objects First...
virtual double get_aggression() const
virtual const moves_map & get_possible_moves() const
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
std::vector< map_location > steps
std::vector< team > * teams
bool should_retreat(const map_location &loc, const unit_map::const_iterator &un, const move_map &srcdst, const move_map &dstsrc, double caution)
virtual void execute()
Execute the candidate action.
Structure which holds a single route between one location and another.
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 double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
int w() const
Effective map width.
virtual move_result_ptr check_move_action(const map_location &from, const map_location &to, bool remove_movement=true, bool unreach_is_ok=false)
Encapsulates the map of the game.
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
virtual bool get_leader_ignores_keep() const
leader_control_phase(rca_context &context, const config &cfg)
Managing the AIs lifecycle - headers.
virtual const move_map & get_srcdst() const
static void modify_active_ai_for_side(ai::side_number side, const config &cfg)
Modifies AI parameters for active AI of the given side.
virtual bool get_passive_leader_shares_keep() const
virtual const map_location & suitable_keep(const map_location &leader_location, const pathfind::paths &leader_paths)
get most suitable keep for leader - nearest free that can be reached in 1 turn, if none - return near...
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 map_location & null_location()
GLuint GLuint GLsizei count
virtual const move_map & get_enemy_dstsrc() const
int move_cost
Movement cost for reaching the end of the route.
#define DBG_AI_TESTING_AI_DEFAULT
Encapsulates the map of the game.
map_location leader_loc_
Locaton of our leader.
void dispatch_complex(treachmap &reachmap, tmoves &moves, const size_t village_count)
Dispatches the units to a village after the simple dispatching failed.
virtual ~leader_control_phase()
get_healing_phase(rca_context &context, const config &cfg)
bool debug_
debug log level for AI enabled?
std::map< std::string, tfilter >::iterator itor
bool dispatch_unit_simple(treachmap &reachmap, tmoves &moves)
Dispatches all units who can reach one village.
int h() const
Effective map height.
virtual ~leader_shares_keep_phase()
virtual bool get_passive_leader() const
virtual ~get_villages_phase()
std::vector< std::pair< map_location, map_location > > movements
#define LOG_AI_TESTING_AI_DEFAULT
virtual void execute()
Execute the candidate action.
defensive_position const & best_defensive_position(const map_location &unit, const move_map &dstsrc, const move_map &srcdst, const move_map &enemy_dstsrc) const
virtual move_result_ptr execute_move_action(const map_location &from, const map_location &to, bool remove_movement=true, bool unreach_is_ok=false)
std::map< map_location, std::vector< map_location > > treachmap
boost::shared_ptr< std::vector< unit_const_ptr > > units_
void get_villages(const move_map &dstsrc, const move_map &enemy_dstsrc, unit_map::const_iterator &leader)
virtual ~get_healing_phase()
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.
void full_dispatch(treachmap &reachmap, tmoves &moves)
Dispatches all units to a village, every unit can reach every village.
treachmap::iterator remove_unit(treachmap &reachmap, tmoves &moves, treachmap::iterator unit)
Removes a unit which can't reach any village anymore.
get_villages_phase(rca_context &context, const config &cfg)
virtual void execute()
Execute the candidate action.
bool find(E event, F functor)
Tests whether an event handler is available.
Standard logging facilities (interface).
Object which contains all the possible locations a unit can move to, with associated best routes to t...
static const double BAD_SCORE
Container associating units to locations.
const std::string remove
remove directive
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
virtual void execute()
Execute the candidate action.
unit_iterator find(size_t id)
const teleport_map get_teleport_locations(const unit &u, const team &viewing_team, bool see_all, bool ignore_units)
A config object defines a single node in a WML file, with access to child nodes.
virtual const std::vector< std::string > get_recruitment_pattern() const
combat_phase(rca_context &context, const config &cfg)
virtual attack_result_ptr check_attack_action(const map_location &attacker_loc, const map_location &defender_loc, int attacker_weapon)
virtual const terrain_filter & get_avoid() const
virtual void execute()
Execute the candidate action.
virtual void execute()
Execute the candidate action.
#define WRN_AI_TESTING_AI_DEFAULT
This module contains various pathfinding functions and utilities.
void remove_goal(const std::string &id)
GLsizei const GLcharARB ** string
virtual const move_map & get_dstsrc() const
virtual stopunit_result_ptr check_stopunit_action(const map_location &unit_location, bool remove_movement=true, bool remove_attacks=false)
void find_villages(treachmap &reachmap, tmoves &moves, const std::multimap< map_location, map_location > &dstsrc, const std::multimap< map_location, map_location > &enemy_dstsrc)
move_leader_to_goals_phase(rca_context &context, const config &cfg)
candidate action framework
attack_analysis best_analysis_
int minimum_recruit_price() const