The Battle for Wesnoth  1.15.0-dev
ai.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2018 by Yurii Chernyi <terraninfo@terraninfo.net>
3  Part of the Battle for Wesnoth Project https://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 //============================================================================
26 namespace ai {
27 
28 class ai_composite : public ai_context, public virtual default_ai_context_proxy, public component {
29 public:
30 
31 
32  /**
33  * Constructor
34  */
35  ai_composite( default_ai_context &context, const config &cfg );
36 
37 
38  /**
39  * Destructor
40  */
41  virtual ~ai_composite();
42 
43 
44  /**
45  * Play the turn
46  */
47  void play_turn();
48 
49 
50  /**
51  * Evaluate command (using fai)
52  */
53  virtual std::string evaluate(const std::string& str);
54 
55  /**
56  * On new turn
57  */
58  virtual void new_turn();
59 
60 
61  std::string describe_self() const;
62 
63  /**
64  * serialize
65  */
66  virtual config to_config() const;
67 
68 
69  int get_recursion_count() const;
70 
71 
72  void switch_side(side_number side);
73 
74 
75  virtual bool add_goal(const config &cfg);
76 
77 
78  virtual bool add_stage(const config &cfg);
79 
80 
81  void create_stage(std::vector<stage_ptr> &stages, const config &cfg);
82 
83 
84  void create_goal(std::vector<goal_ptr> &goals, const config &cfg);
85 
86 
87  void create_engine(std::vector<engine_ptr> &engines, const config &cfg);
88 
89 
90  void replace_aspect(std::map<std::string,aspect_ptr> &aspects, const config &cfg, std::string id);
91 
92 
93  void on_create();
94 
95  /**
96  * unwrap
97  */
98  virtual ai_context& get_ai_context();
99 
100 
101  virtual std::string get_id() const;
102  virtual std::string get_name() const;
103  virtual std::string get_engine() const;
104 
105  static config preparse_cfg(ai_context& ctx, const config& cfg);
106 
107 protected:
108 
109  /**
110  * Config of the AI
111  */
112  const config &cfg_;
113 
114 
115  /**
116  * Stages of the composite AI
117  */
118  std::vector< stage_ptr > stages_;
119 
120 
121  /**
122  * Recursion counter
123  */
125 };
126 
127 } //end of namespace ai
virtual std::string evaluate(const std::string &str)
Evaluate command (using fai)
Definition: ai.cpp:174
void on_create()
Definition: ai.cpp:55
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:118
void create_stage(std::vector< stage_ptr > &stages, const config &cfg)
Definition: ai.cpp:92
virtual bool add_stage(const config &cfg)
Definition: ai.cpp:122
virtual std::string get_name() const
Definition: ai.cpp:162
virtual std::string get_engine() const
Definition: ai.cpp:168
const config & cfg_
Config of the AI.
Definition: ai.hpp:112
virtual std::string get_id() const
Definition: ai.cpp:155
virtual bool add_goal(const config &cfg)
Definition: ai.cpp:135
virtual config to_config() const
serialize
Definition: ai.cpp:213
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&#39;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:124
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:207
void switch_side(side_number side)
Definition: ai.cpp:202
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:225
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:39
std::string describe_self() const
Definition: ai.cpp:44
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
int get_recursion_count() const
Get the value of the recursion counter.
Definition: ai.cpp:197