The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ca.hpp
Go to the documentation of this file.
1 
2 /*
3  Copyright (C) 2009 - 2016 by Yurii Chernyi <[email protected]>
4  Part of the Battle for Wesnoth Project http://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  * Default AI (Testing)
18  * @file
19  */
20 
21 #ifndef AI_TESTING_CA_HPP_INCLUDED
22 #define AI_TESTING_CA_HPP_INCLUDED
23 
24 #include "units/map.hpp"
25 
26 #include "ai/composite/rca.hpp"
27 
28 
29 #ifdef _MSC_VER
30 #pragma warning(push)
31 //silence "inherits via dominance" warnings
32 #pragma warning(disable:4250)
33 #endif
34 
35 namespace ai {
36 
37 namespace ai_default_rca {
38 
39 //============================================================================
40 
41 class goto_phase : public candidate_action {
42 public:
43 
44  goto_phase( rca_context &context, const config &cfg );
45 
46  virtual ~goto_phase();
47 
48  virtual double evaluate();
49 
50  virtual void execute();
51 private:
53 };
54 
55 //============================================================================
56 
58 public:
59 
60  combat_phase( rca_context &context, const config &cfg );
61 
62  virtual ~combat_phase();
63 
64  virtual double evaluate();
65 
66  virtual void execute();
67 private:
70 
71 };
72 
73 //============================================================================
74 
76 public:
77 
78  move_leader_to_goals_phase( rca_context &context, const config &cfg );
79 
81 
82  virtual double evaluate();
83 
84  virtual void execute();
85 private:
86 
87  void remove_goal(const std::string &id);
88 
93 };
94 
95 //============================================================================
96 
98 public:
99 
100  move_leader_to_keep_phase( rca_context &context, const config &cfg );
101 
102  virtual ~move_leader_to_keep_phase();
103 
104  virtual double evaluate();
105 
106  virtual void execute();
107 
108 private:
110 };
111 
112 //============================================================================
113 
115 public:
116 
117  get_villages_phase( rca_context &context, const config& cfg );
118 
119  virtual ~get_villages_phase();
120 
121  virtual double evaluate();
122 
123  virtual void execute();
124 private:
125  /** Location of the keep the closest to our leader. */
127 
128  /** Locaton of our leader. */
130 
131  /** The best possible location for our leader if it can't reach a village. */
133 
134  /** debug log level for AI enabled? */
135  bool debug_;
136 
137  typedef std::map<map_location /* unit location */,
138  std::vector<map_location /* villages we can reach */> > treachmap;
139 
140  typedef std::vector<std::pair<map_location /* destination */,
141  map_location /* start */ > > tmoves;
142 
143 
144  // The list of moves we want to make
145  tmoves moves_;
146 
147 
148  /** Dispatches all units to their best location. */
149  void dispatch(treachmap& reachmap, tmoves& moves);
150 
151 
152  /**
153  * Dispatches all units who can reach one village.
154  * Returns true if it modified reachmap isn't empty.
155  */
156  bool dispatch_unit_simple(treachmap& reachmap, tmoves& moves);
157 
158 
159  /*
160  * Dispatches units to villages which can only be reached by one unit.
161  * Returns true if modified reachmap and reachmap isn't empty.
162  */
164  treachmap& reachmap, tmoves& moves, size_t& village_count);
165 
166 
167  /** Removes a village for all units, returns true if anything is deleted. */
168  bool remove_village(
169  treachmap& reachmap, tmoves& moves, const map_location& village);
170 
171 
172  /** Removes a unit which can't reach any village anymore. */
174  treachmap& reachmap, tmoves& moves, treachmap::iterator unit);
175 
176 
177  /** Dispatches the units to a village after the simple dispatching failed. */
178  void dispatch_complex(
179  treachmap& reachmap, tmoves& moves, const size_t village_count);
180 
181 
182  /** Dispatches all units to a village, every unit can reach every village. */
183  void full_dispatch(treachmap& reachmap, tmoves& moves);
184 
185 
186  /** Shows which villages every unit can reach (debug function). */
187  void dump_reachmap(treachmap& reachmap);
188 
189 
190  void get_villages(
191  const move_map &dstsrc, const move_map &enemy_dstsrc,
192  unit_map::const_iterator &leader);
193 
194 
195  void find_villages(
196  treachmap& reachmap,
197  tmoves& moves,
198  const std::multimap<map_location,map_location>& dstsrc,
199  const std::multimap<map_location,map_location>& enemy_dstsrc);
200 
201 };
202 
203 //============================================================================
204 
206 public:
207 
208  get_healing_phase( rca_context &context, const config& cfg );
209 
210  virtual ~get_healing_phase();
211 
212  virtual double evaluate();
213 
214  virtual void execute();
215 private:
216 
218 };
219 
220 //============================================================================
221 
223 public:
224 
225  retreat_phase( rca_context &context, const config &cfg );
226 
227  virtual ~retreat_phase();
228 
229  virtual double evaluate();
230 
231  virtual void execute();
232 private:
233 
234  bool should_retreat(const map_location& loc, const unit_map::const_iterator& un, const move_map &srcdst, const move_map &dstsrc, double caution);
235 
237 
238 };
239 
240 
241 //============================================================================
242 
244 public:
245 
246  leader_control_phase( rca_context &context, const config &cfg );
247 
248  virtual ~leader_control_phase();
249 
250  virtual double evaluate();
251 
252  virtual void execute();
253 };
254 
255 
256 //============================================================================
258 public:
259 
260  leader_shares_keep_phase( rca_context &context, const config &cfg );
261 
262  virtual ~leader_shares_keep_phase();
263 
264  virtual double evaluate();
265 
266  virtual void execute();
267 };
268 
269 
270 //============================================================================
271 
272 } // end of namespace testing_ai_default
273 
274 } // end of namespace ai
275 
276 #ifdef _MSC_VER
277 #pragma warning(pop)
278 #endif
279 
280 #endif
virtual void execute()
Execute the candidate action.
Definition: ca.cpp:220
virtual void execute()
Execute the candidate action.
Definition: ca.cpp:336
move_result_ptr move_
Definition: ca.hpp:52
std::vector< std::pair< map_location, map_location > > tmoves
Definition: ca.hpp:141
Definition: unit.hpp:95
void dispatch(treachmap &reachmap, tmoves &moves)
Dispatches all units to their best location.
Definition: ca.cpp:768
goto_phase(rca_context &context, const config &cfg)
Definition: ca.cpp:54
map_location best_leader_loc_
The best possible location for our leader if it can't reach a village.
Definition: ca.hpp:132
void dump_reachmap(treachmap &reachmap)
Shows which villages every unit can reach (debug function).
Definition: ca.cpp:1290
leader_shares_keep_phase(rca_context &context, const config &cfg)
Definition: ca.cpp:1586
map_location keep_loc_
Location of the keep the closest to our leader.
Definition: ca.hpp:126
bool dispatch_village_simple(treachmap &reachmap, tmoves &moves, size_t &village_count)
Definition: ca.cpp:873
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition: ca.cpp:161
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition: ca.cpp:1327
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition: ca.cpp:372
move_leader_to_keep_phase(rca_context &context, const config &cfg)
Definition: ca.cpp:361
retreat_phase(rca_context &context, const config &cfg)
Definition: ca.cpp:1394
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition: ca.cpp:526
bool remove_village(treachmap &reachmap, tmoves &moves, const map_location &village)
Removes a village for all units, returns true if anything is deleted.
Definition: ca.cpp:925
virtual void execute()
Execute the candidate action.
Definition: ca.cpp:1616
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition: ca.cpp:1403
std::multimap< map_location, map_location > move_map
The standard way in which a map of possible moves is recorded.
Definition: game_info.hpp:47
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:57
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition: ca.cpp:258
bool should_retreat(const map_location &loc, const unit_map::const_iterator &un, const move_map &srcdst, const move_map &dstsrc, double caution)
Definition: ca.cpp:1536
virtual void execute()
Execute the candidate action.
Definition: ca.cpp:502
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition: ca.cpp:1571
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition: ca.cpp:1595
leader_control_phase(rca_context &context, const config &cfg)
Definition: ca.cpp:1561
Encapsulates the map of the game.
Definition: location.hpp:38
map_location leader_loc_
Locaton of our leader.
Definition: ca.hpp:129
void dispatch_complex(treachmap &reachmap, tmoves &moves, const size_t village_count)
Dispatches the units to a village after the simple dispatching failed.
Definition: ca.cpp:958
get_healing_phase(rca_context &context, const config &cfg)
Definition: ca.cpp:1318
bool debug_
debug log level for AI enabled?
Definition: ca.hpp:135
bool dispatch_unit_simple(treachmap &reachmap, tmoves &moves)
Dispatches all units who can reach one village.
Definition: ca.cpp:828
virtual void execute()
Execute the candidate action.
Definition: ca.cpp:538
std::map< map_location, std::vector< map_location > > treachmap
Definition: ca.hpp:138
void get_villages(const move_map &dstsrc, const move_map &enemy_dstsrc, unit_map::const_iterator &leader)
Definition: ca.cpp:589
void full_dispatch(treachmap &reachmap, tmoves &moves)
Dispatches all units to a village, every unit can reach every village.
Definition: ca.cpp:1280
treachmap::iterator remove_unit(treachmap &reachmap, tmoves &moves, treachmap::iterator unit)
Removes a unit which can't reach any village anymore.
Definition: ca.cpp:942
get_villages_phase(rca_context &context, const config &cfg)
Definition: ca.cpp:512
virtual void execute()
Execute the candidate action.
Definition: ca.cpp:1579
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition: ca.cpp:64
virtual void execute()
Execute the candidate action.
Definition: ca.cpp:1383
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
combat_phase(rca_context &context, const config &cfg)
Definition: ca.cpp:152
virtual void execute()
Execute the candidate action.
Definition: ca.cpp:128
virtual void execute()
Execute the candidate action.
Definition: ca.cpp:1526
void remove_goal(const std::string &id)
Definition: ca.cpp:350
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void find_villages(treachmap &reachmap, tmoves &moves, const std::multimap< map_location, map_location > &dstsrc, const std::multimap< map_location, map_location > &enemy_dstsrc)
Definition: ca.cpp:649
move_leader_to_goals_phase(rca_context &context, const config &cfg)
Definition: ca.cpp:249
candidate action framework
attack_analysis best_analysis_
Definition: ca.hpp:68