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