The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ai.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2016 by Yurii Chernyi <[email protected]>
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  * Composite AI with turn sequence which is a vector of stages
18  */
19 
20 #ifndef AI_COMPOSITE_AI_HPP_INCLUDED
21 #define AI_COMPOSITE_AI_HPP_INCLUDED
22 
25 
26 #ifdef _MSC_VER
27 #pragma warning(push)
28 //silence "inherits via dominance" warnings
29 #pragma warning(disable:4250)
30 #endif
31 
32 //============================================================================
33 namespace ai {
34 
35 class ai_composite : public ai_context, public virtual default_ai_context_proxy, public component {
36 public:
37 
38 
39  /**
40  * Constructor
41  */
42  ai_composite( default_ai_context &context, const config &cfg );
43 
44 
45  /**
46  * Destructor
47  */
48  virtual ~ai_composite();
49 
50 
51  /**
52  * Play the turn
53  */
54  void play_turn();
55 
56 
57  /**
58  * Evaluate command (using fai)
59  */
60  virtual std::string evaluate(const std::string& str);
61 
62  /**
63  * On new turn
64  */
65  virtual void new_turn();
66 
67 
68  std::string describe_self() const;
69 
70  /**
71  * serialize
72  */
73  virtual config to_config() const;
74 
75 
76  int get_recursion_count() const;
77 
78 
79  void switch_side(side_number side);
80 
81 
82  virtual bool add_goal(const config &cfg);
83 
84 
85  virtual bool add_stage(const config &cfg);
86 
87 
88  void create_stage(std::vector<stage_ptr> &stages, const config &cfg);
89 
90 
91  void create_goal(std::vector<goal_ptr> &goals, const config &cfg);
92 
93 
94  void create_engine(std::vector<engine_ptr> &engines, const config &cfg);
95 
96 
97  void replace_aspect(std::map<std::string,aspect_ptr> &aspects, const config &cfg, std::string id);
98 
99 
100  void on_create();
101 
102  /**
103  * unwrap
104  */
105  virtual ai_context& get_ai_context();
106 
107 
108  virtual std::string get_id() const;
109  virtual std::string get_name() const;
110  virtual std::string get_engine() const;
111 
112  static config preparse_cfg(ai_context& ctx, const config& cfg);
113 
114 protected:
115 
116  /**
117  * Config of the AI
118  */
119  const config &cfg_;
120 
121 
122  /**
123  * Stages of the composite AI
124  */
125  std::vector< stage_ptr > stages_;
126 
127 
128  /**
129  * Recursion counter
130  */
132 };
133 
134 } //end of namespace ai
135 
136 #ifdef _MSC_VER
137 #pragma warning(pop)
138 #endif
139 
140 #endif
virtual std::string evaluate(const std::string &str)
Evaluate command (using fai)
Definition: ai.cpp:174
void on_create()
Definition: ai.cpp:55
virtual std::string get_id() const
Definition: ai.cpp:155
void create_engine(std::vector< engine_ptr > &engines, const config &cfg)
Definition: ai.cpp:104
std::vector< stage_ptr > stages_
Stages of the composite AI.
Definition: ai.hpp:125
void create_stage(std::vector< stage_ptr > &stages, const config &cfg)
Definition: ai.cpp:92
std::string describe_self() const
Definition: ai.cpp:44
virtual bool add_stage(const config &cfg)
Definition: ai.cpp:122
const config & cfg_
Config of the AI.
Definition: ai.hpp:119
virtual bool add_goal(const config &cfg)
Definition: ai.cpp:135
int get_recursion_count() const
Get the value of the recursion counter.
Definition: ai.cpp:198
virtual config to_config() const
serialize
Definition: ai.cpp:214
void replace_aspect(std::map< std::string, aspect_ptr > &aspects, const config &cfg, std::string id)
Definition: ai.cpp:110
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:57
recursion_counter recursion_counter_
Recursion counter.
Definition: ai.hpp:131
virtual void new_turn()
On new turn.
Definition: ai.cpp:187
ai_composite(default_ai_context &context, const config &cfg)
Constructor.
Definition: ai.cpp:49
A component of the AI framework.
virtual ai_context & get_ai_context()
unwrap
Definition: ai.cpp:208
void switch_side(side_number side)
Definition: ai.cpp:203
void create_goal(std::vector< goal_ptr > &goals, const config &cfg)
Definition: ai.cpp:98
static config preparse_cfg(ai_context &ctx, const config &cfg)
Definition: ai.cpp:226
GLbitfield stages
Definition: glew.h:4366
virtual ~ai_composite()
Destructor.
Definition: ai.cpp:117
void play_turn()
Play the turn.
Definition: ai.cpp:148
Composite AI contexts.
int side_number
Definition: game_info.hpp:44
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
virtual std::string get_engine() const
Definition: ai.cpp:168
GLsizei const GLcharARB ** string
Definition: glew.h:4503
virtual std::string get_name() const
Definition: ai.cpp:162