The Battle for Wesnoth  1.17.0-dev
ai.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2021
3  by Yurii Chernyi <terraninfo@terraninfo.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * @file
18  * Composite AI with turn sequence which is a vector of stages
19  */
20 
21 #pragma once
22 
25 
26 //============================================================================
27 namespace ai {
28 
29 class ai_composite : public ai_context, public virtual default_ai_context_proxy, public component {
30 public:
31 
32  /**
33  * Constructor
34  */
35  ai_composite( default_ai_context &context, const config &cfg );
36 
37  /**
38  * Destructor
39  */
40  virtual ~ai_composite();
41 
42  /**
43  * Play the turn
44  */
45  void play_turn();
46 
47  /**
48  * Evaluate command (using fai)
49  */
50  virtual std::string evaluate(const std::string& str);
51 
52  /**
53  * On new turn
54  */
55  virtual void new_turn();
56 
57  std::string describe_self() const;
58 
59  /**
60  * serialize
61  */
62  virtual config to_config() const;
63 
64  int get_recursion_count() const;
65 
66  void switch_side(side_number side);
67 
68  virtual bool add_goal(const config &cfg);
69 
70  virtual bool add_stage(const config &cfg);
71 
72  void create_stage(std::vector<stage_ptr> &stages, const config &cfg);
73 
74  void create_goal(std::vector<goal_ptr> &goals, const config &cfg);
75 
76  void create_engine(std::vector<engine_ptr> &engines, const config &cfg);
77 
78  void replace_aspect(std::map<std::string,aspect_ptr> &aspects, const config &cfg, std::string id);
79 
80  void on_create();
81 
82  /**
83  * unwrap
84  */
85  virtual ai_context& get_ai_context();
86 
87  virtual std::string get_id() const;
88  virtual std::string get_name() const;
89  virtual std::string get_engine() const;
90 
91  static config preparse_cfg(ai_context& ctx, const config& cfg);
92 
93 protected:
94 
95  /**
96  * Config of the AI
97  */
98  const config &cfg_;
99 
100  /**
101  * Stages of the composite AI
102  */
103  std::vector< stage_ptr > stages_;
104 
105  /**
106  * Recursion counter
107  */
109 };
110 
111 } //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:103
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:98
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:61
recursion_counter recursion_counter_
Recursion counter.
Definition: ai.hpp:108
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:40
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:61
int get_recursion_count() const
Get the value of the recursion counter.
Definition: ai.cpp:184