The Battle for Wesnoth  1.13.10+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 - 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  * Composite AI with turn sequence which is a vector of stages
18  */
19 
20 #pragma once
21 
24 
25 #ifdef _MSC_VER
26 #pragma warning(push)
27 //silence "inherits via dominance" warnings
28 #pragma warning(disable:4250)
29 #endif
30 
31 //============================================================================
32 namespace ai {
33 
34 class ai_composite : public ai_context, public virtual default_ai_context_proxy, public component {
35 public:
36 
37 
38  /**
39  * Constructor
40  */
41  ai_composite( default_ai_context &context, const config &cfg );
42 
43 
44  /**
45  * Destructor
46  */
47  virtual ~ai_composite();
48 
49 
50  /**
51  * Play the turn
52  */
53  void play_turn();
54 
55 
56  /**
57  * Evaluate command (using fai)
58  */
59  virtual std::string evaluate(const std::string& str);
60 
61  /**
62  * On new turn
63  */
64  virtual void new_turn();
65 
66 
67  std::string describe_self() const;
68 
69  /**
70  * serialize
71  */
72  virtual config to_config() const;
73 
74 
75  int get_recursion_count() const;
76 
77 
78  void switch_side(side_number side);
79 
80 
81  virtual bool add_goal(const config &cfg);
82 
83 
84  virtual bool add_stage(const config &cfg);
85 
86 
87  void create_stage(std::vector<stage_ptr> &stages, const config &cfg);
88 
89 
90  void create_goal(std::vector<goal_ptr> &goals, const config &cfg);
91 
92 
93  void create_engine(std::vector<engine_ptr> &engines, const config &cfg);
94 
95 
96  void replace_aspect(std::map<std::string,aspect_ptr> &aspects, const config &cfg, std::string id);
97 
98 
99  void on_create();
100 
101  /**
102  * unwrap
103  */
104  virtual ai_context& get_ai_context();
105 
106 
107  virtual std::string get_id() const;
108  virtual std::string get_name() const;
109  virtual std::string get_engine() const;
110 
111  static config preparse_cfg(ai_context& ctx, const config& cfg);
112 
113 protected:
114 
115  /**
116  * Config of the AI
117  */
118  const config &cfg_;
119 
120 
121  /**
122  * Stages of the composite AI
123  */
124  std::vector< stage_ptr > stages_;
125 
126 
127  /**
128  * Recursion counter
129  */
131 };
132 
133 } //end of namespace ai
134 
135 #ifdef _MSC_VER
136 #pragma warning(pop)
137 #endif
virtual std::string evaluate(const std::string &str)
Evaluate command (using fai)
Definition: ai.cpp:174
std::vector< char_t > string
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:124
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:118
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:58
recursion_counter recursion_counter_
Recursion counter.
Definition: ai.hpp:130
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
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:36
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
virtual std::string get_engine() const
Definition: ai.cpp:168
virtual std::string get_name() const
Definition: ai.cpp:162