The Battle for Wesnoth  1.15.11+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  * Constructor
33  */
34  ai_composite( default_ai_context &context, const config &cfg );
35 
36  /**
37  * Destructor
38  */
39  virtual ~ai_composite();
40 
41  /**
42  * Play the turn
43  */
44  void play_turn();
45 
46  /**
47  * Evaluate command (using fai)
48  */
49  virtual std::string evaluate(const std::string& str);
50 
51  /**
52  * On new turn
53  */
54  virtual void new_turn();
55 
56  std::string describe_self() const;
57 
58  /**
59  * serialize
60  */
61  virtual config to_config() const;
62 
63  int get_recursion_count() const;
64 
65  void switch_side(side_number side);
66 
67  virtual bool add_goal(const config &cfg);
68 
69  virtual bool add_stage(const config &cfg);
70 
71  void create_stage(std::vector<stage_ptr> &stages, const config &cfg);
72 
73  void create_goal(std::vector<goal_ptr> &goals, const config &cfg);
74 
75  void create_engine(std::vector<engine_ptr> &engines, const config &cfg);
76 
77  void replace_aspect(std::map<std::string,aspect_ptr> &aspects, const config &cfg, std::string id);
78 
79  void on_create();
80 
81  /**
82  * unwrap
83  */
84  virtual ai_context& get_ai_context();
85 
86  virtual std::string get_id() const;
87  virtual std::string get_name() const;
88  virtual std::string get_engine() const;
89 
90  static config preparse_cfg(ai_context& ctx, const config& cfg);
91 
92 protected:
93 
94  /**
95  * Config of the AI
96  */
97  const config &cfg_;
98 
99  /**
100  * Stages of the composite AI
101  */
102  std::vector< stage_ptr > stages_;
103 
104  /**
105  * Recursion counter
106  */
108 };
109 
110 } //end of namespace ai
virtual std::string evaluate(const std::string &str)
Evaluate command (using fai)
Definition: ai.cpp:163
void on_create()
Definition: ai.cpp:55
void create_engine(std::vector< engine_ptr > &engines, const config &cfg)
Definition: ai.cpp:101
std::vector< stage_ptr > stages_
Stages of the composite AI.
Definition: ai.hpp:102
void create_stage(std::vector< stage_ptr > &stages, const config &cfg)
Definition: ai.cpp:91
virtual bool add_stage(const config &cfg)
Definition: ai.cpp:117
virtual std::string get_name() const
Definition: ai.cpp:153
virtual std::string get_engine() const
Definition: ai.cpp:158
const config & cfg_
Config of the AI.
Definition: ai.hpp:97
virtual std::string get_id() const
Definition: ai.cpp:147
virtual bool add_goal(const config &cfg)
Definition: ai.cpp:129
virtual config to_config() const
serialize
Definition: ai.cpp:199
void replace_aspect(std::map< std::string, aspect_ptr > &aspects, const config &cfg, std::string id)
Definition: ai.cpp:106
A small explanation about what&#39;s going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:59
recursion_counter recursion_counter_
Recursion counter.
Definition: ai.hpp:107
virtual void new_turn()
On new turn.
Definition: ai.cpp:175
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:194
void switch_side(side_number side)
Definition: ai.cpp:189
void create_goal(std::vector< goal_ptr > &goals, const config &cfg)
Definition: ai.cpp:96
static config preparse_cfg(ai_context &ctx, const config &cfg)
Definition: ai.cpp:211
virtual ~ai_composite()
Destructor.
Definition: ai.cpp:113
void play_turn()
Play the turn.
Definition: ai.cpp:141
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:59
int get_recursion_count() const
Get the value of the recursion counter.
Definition: ai.cpp:184