The Battle for Wesnoth  1.19.5+dev
ca_move_to_targets.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2024
3  by Yurii Chernyi <terraninfo@terraninfo.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Strategic movement routine, for experimentation
19  */
20 
21 #pragma once
22 
23 #include "ai/composite/rca.hpp"
24 
25 #include "units/map.hpp"
26 
27 namespace pathfind {
28 
29 struct plain_route;
30 
31 } //of namespace pathfind
32 
33 namespace ai {
34 
35 namespace ai_default_rca {
36 
38 public:
39 
40  move_to_targets_phase( rca_context &context, const config &cfg );
41 
42  virtual ~move_to_targets_phase();
43 
44  virtual double evaluate();
45 
46  virtual void execute();
47 
48 protected:
49  void access_points(const move_map& srcdst, const map_location& u, const map_location& dst, std::vector<map_location>& out);
50 
51  std::pair<map_location,map_location> choose_move(std::vector<target>& targets);
52 
53  double compare_groups(const std::set<map_location>& our_group, const std::set<map_location>& their_group, const std::vector<map_location>& battlefield) const;
54 
55  void enemies_along_path(const std::vector<map_location>& route, const move_map& dstsrc, std::set<map_location>& res);
56 
57  map_location form_group(const std::vector<map_location>& route, const move_map& dstsrc, std::set<map_location>& res);
58 
59  bool move_group(const map_location& dst, const std::vector<map_location>& route, const std::set<map_location>& units);
60 
61  double rate_group(const std::set<map_location>& group, const std::vector<map_location>& battlefield) const;
62 
63  /**
64  * rate a target, but can also return the maximal possible rating
65  * by passing a dummy route
66  */
67  double rate_target(const target& tg, const unit_map::iterator& u,
68  const move_map& dstsrc, const move_map& enemy_dstsrc,
69  const pathfind::plain_route& rt);
70 
71  bool should_retreat(const map_location& loc, const unit_map::const_iterator& un,
72  const move_map& srcdst, const move_map& dstsrc, const move_map& enemy_dstsrc,
73  double caution);
74 };
75 
76 } // of namespace testing_ai_default
77 
78 } // of namespace ai
void access_points(const move_map &srcdst, const map_location &u, const map_location &dst, std::vector< map_location > &out)
map_location form_group(const std::vector< map_location > &route, const move_map &dstsrc, std::set< map_location > &res)
void enemies_along_path(const std::vector< map_location > &route, const move_map &dstsrc, std::set< map_location > &res)
bool move_group(const map_location &dst, const std::vector< map_location > &route, const std::set< map_location > &units)
bool should_retreat(const map_location &loc, const unit_map::const_iterator &un, const move_map &srcdst, const move_map &dstsrc, const move_map &enemy_dstsrc, double caution)
double rate_group(const std::set< map_location > &group, const std::vector< map_location > &battlefield) const
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
double compare_groups(const std::set< map_location > &our_group, const std::set< map_location > &their_group, const std::vector< map_location > &battlefield) const
move_to_targets_phase(rca_context &context, const config &cfg)
double rate_target(const target &tg, const unit_map::iterator &u, const move_map &dstsrc, const move_map &enemy_dstsrc, const pathfind::plain_route &rt)
rate a target, but can also return the maximal possible rating by passing a dummy route
virtual void execute()
Execute the candidate action.
std::pair< map_location, map_location > choose_move(std::vector< target > &targets)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:59
std::multimap< map_location, map_location > move_map
The standard way in which a map of possible moves is recorded.
Definition: game_info.hpp:43
candidate action framework
rect dst
Location on the final composed sheet.
Encapsulates the map of the game.
Definition: location.hpp:45
Structure which holds a single route between one location and another.
Definition: pathfind.hpp:133