The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
ca.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2009 - 2025
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 * Default AI (Testing)
18 * @file
19 */
20
21#pragma once
22
23#include "units/map.hpp"
24
25#include "ai/composite/rca.hpp"
26
27namespace ai {
28
29namespace ai_default_rca {
30
31//============================================================================
32
34public:
35
36 goto_phase( rca_context &context, const config &cfg );
37
38 virtual ~goto_phase();
39
40 virtual double evaluate();
41
42 virtual void execute();
43private:
45};
46
47//============================================================================
48
50public:
51
52 combat_phase( rca_context &context, const config &cfg );
53
54 virtual ~combat_phase();
55
56 virtual double evaluate();
57
58 virtual void execute();
59private:
62
63};
64
65//============================================================================
66
68public:
69
71
73
74 virtual double evaluate();
75
76 virtual void execute();
77private:
78
79 void remove_goal(const std::string &id);
80
83 std::string id_;
85};
86
87//============================================================================
88
90public:
91
93
95
96 virtual double evaluate();
97
98 virtual void execute();
99
100private:
102};
103
104//============================================================================
105
107public:
108
109 get_villages_phase( rca_context &context, const config& cfg );
110
111 virtual ~get_villages_phase();
112
113 virtual double evaluate();
114
115 virtual void execute();
116private:
117 /** Location of the keep the closest to our leader. */
119
120 /** Locaton of our leader. */
122
123 /** The best possible location for our leader if it can't reach a village. */
125
126 /** debug log level for AI enabled? */
127 bool debug_;
128
129 typedef std::map<map_location /* unit location */,
130 std::vector<map_location /* villages we can reach */>> treachmap;
131
132 typedef std::vector<std::pair<map_location /* destination */,
133 map_location /* start */ >> tmoves;
134
135 // The list of moves we want to make
137
138 /** Dispatches all units to their best location. */
139 void dispatch(treachmap& reachmap, tmoves& moves);
140
141 /**
142 * Dispatches all units who can reach one village.
143 * Returns true if it modified reachmap isn't empty.
144 */
145 bool dispatch_unit_simple(treachmap& reachmap, tmoves& moves);
146
147 /*
148 * Dispatches units to villages which can only be reached by one unit.
149 * Returns true if modified reachmap and reachmap isn't empty.
150 */
152 treachmap& reachmap, tmoves& moves, std::size_t& village_count);
153
154 /** Removes a village for all units, returns true if anything is deleted. */
155 bool remove_village(
156 treachmap& reachmap, tmoves& moves, const map_location& village);
157
158 /** Removes a unit which can't reach any village anymore. */
159 treachmap::iterator remove_unit(
160 treachmap& reachmap, tmoves& moves, treachmap::iterator unit);
161
162 /** Dispatches the units to a village after the simple dispatching failed. */
163 void dispatch_complex(
164 treachmap& reachmap, tmoves& moves, const std::size_t village_count);
165
166 /** Dispatches all units to a village, every unit can reach every village. */
167 void full_dispatch(treachmap& reachmap, tmoves& moves);
168
169 /** Shows which villages every unit can reach (debug function). */
170 void dump_reachmap(treachmap& reachmap);
171
172 void get_villages(
173 const move_map &dstsrc, const move_map &enemy_dstsrc,
175
176 void find_villages(
177 treachmap& reachmap,
178 tmoves& moves,
179 const std::multimap<map_location,map_location>& dstsrc,
180 const std::multimap<map_location,map_location>& enemy_dstsrc);
181
182};
183
184//============================================================================
185
187public:
188
189 get_healing_phase( rca_context &context, const config& cfg );
190
191 virtual ~get_healing_phase();
192
193 virtual double evaluate();
194
195 virtual void execute();
196private:
197
199};
200
201//============================================================================
202
204public:
205
206 retreat_phase( rca_context &context, const config &cfg );
207
208 virtual ~retreat_phase();
209
210 virtual double evaluate();
211
212 virtual void execute();
213private:
214
215 bool should_retreat(const map_location& loc, const unit_map::const_iterator& un, const move_map &srcdst, const move_map &dstsrc, double caution);
216
218
219};
220
221//============================================================================
222
224public:
225
226 leader_control_phase( rca_context &context, const config &cfg );
227
228 virtual ~leader_control_phase();
229
230 virtual double evaluate();
231
232 virtual void execute();
233};
234
235//============================================================================
237public:
238
240
242
243 virtual double evaluate();
244
245 virtual void execute();
246};
247
248//============================================================================
249
250} // end of namespace testing_ai_default
251
252} // end of namespace ai
map_location loc
Definition move.cpp:172
virtual void execute()
Execute the candidate action.
Definition ca.cpp:238
attack_analysis best_analysis_
Definition ca.hpp:60
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition ca.cpp:163
virtual void execute()
Execute the candidate action.
Definition ca.cpp:1377
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition ca.cpp:1322
void dump_reachmap(treachmap &reachmap)
Shows which villages every unit can reach (debug function).
Definition ca.cpp:1286
bool dispatch_village_simple(treachmap &reachmap, tmoves &moves, std::size_t &village_count)
Definition ca.cpp:879
map_location keep_loc_
Location of the keep the closest to our leader.
Definition ca.hpp:118
treachmap::iterator remove_unit(treachmap &reachmap, tmoves &moves, treachmap::iterator unit)
Removes a unit which can't reach any village anymore.
Definition ca.cpp:948
map_location leader_loc_
Locaton of our leader.
Definition ca.hpp:121
bool dispatch_unit_simple(treachmap &reachmap, tmoves &moves)
Dispatches all units who can reach one village.
Definition ca.cpp:835
std::map< map_location, std::vector< map_location > > treachmap
Definition ca.hpp:130
void dispatch(treachmap &reachmap, tmoves &moves)
Dispatches all units to their best location.
Definition ca.cpp:775
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition ca.cpp:549
void dispatch_complex(treachmap &reachmap, tmoves &moves, const std::size_t village_count)
Dispatches the units to a village after the simple dispatching failed.
Definition ca.cpp:964
bool debug_
debug log level for AI enabled?
Definition ca.hpp:127
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:931
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:664
virtual void execute()
Execute the candidate action.
Definition ca.cpp:560
void full_dispatch(treachmap &reachmap, tmoves &moves)
Dispatches all units to a village, every unit can reach every village.
Definition ca.cpp:1276
void get_villages(const move_map &dstsrc, const move_map &enemy_dstsrc, unit_map::const_iterator &leader)
Definition ca.cpp:605
std::vector< std::pair< map_location, map_location > > tmoves
Definition ca.hpp:133
map_location best_leader_loc_
The best possible location for our leader if it can't reach a village.
Definition ca.hpp:124
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition ca.cpp:63
move_result_ptr move_
Definition ca.hpp:44
virtual void execute()
Execute the candidate action.
Definition ca.cpp:131
virtual void execute()
Execute the candidate action.
Definition ca.cpp:1556
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition ca.cpp:1550
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition ca.cpp:1572
virtual void execute()
Execute the candidate action.
Definition ca.cpp:1602
virtual void execute()
Execute the candidate action.
Definition ca.cpp:364
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition ca.cpp:276
void remove_goal(const std::string &id)
Definition ca.cpp:378
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition ca.cpp:400
virtual void execute()
Execute the candidate action.
Definition ca.cpp:525
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:1517
virtual double evaluate()
Evaluate the candidate action, resetting the internal state of the action.
Definition ca.cpp:1397
virtual void execute()
Execute the candidate action.
Definition ca.cpp:1509
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
This class represents a single unit of a specific type.
Definition unit.hpp:39
const config * cfg
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
std::shared_ptr< move_result > move_result_ptr
Definition game_info.hpp:85
candidate action framework
Encapsulates the map of the game.
Definition location.hpp:46