-
-
Notifications
You must be signed in to change notification settings - Fork 994
/
engine.cpp
152 lines (115 loc) · 4.13 KB
/
engine.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
Copyright (C) 2009 - 2015 by Yurii Chernyi <terraninfo@terraninfo.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
/**
* AI Support engine - creating specific ai components from config
* @file
*/
#include "engine.hpp"
#include "contexts.hpp"
#include "../../log.hpp"
namespace ai {
static lg::log_domain log_ai_engine("ai/engine");
#define DBG_AI_ENGINE LOG_STREAM(debug, log_ai_engine)
#define LOG_AI_ENGINE LOG_STREAM(info, log_ai_engine)
#define ERR_AI_ENGINE LOG_STREAM(err, log_ai_engine)
engine::engine( readonly_context &context, const config &cfg )
: ai_(context)
, ai_context_(NULL)
, engine_(cfg["engine"])
, id_(cfg["id"])
, name_(cfg["name"])
{
LOG_AI_ENGINE << "side "<< ai_.get_side() << " : "<<" created engine with name=["<<name_<<"]"<<std::endl;
}
engine::~engine()
{
}
bool engine::is_ok() const
{
return true;
}
void engine::parse_aspect_from_config( readonly_context &context, const config &cfg, const std::string &id, std::back_insert_iterator< std::vector< aspect_ptr > > b )
{
engine_ptr eng = context.get_engine_by_cfg(cfg);
if (eng){
//do not override that method in subclasses which cannot create aspects
eng->do_parse_aspect_from_config(cfg, id, b);
}
}
void engine::parse_candidate_action_from_config( rca_context &context, const config &cfg, std::back_insert_iterator<std::vector< candidate_action_ptr > > b )
{
engine_ptr eng = context.get_engine_by_cfg(cfg);
if (eng){
//do not override that method in subclasses which cannot create candidate actions
eng->do_parse_candidate_action_from_config(context, cfg, b);
}
}
void engine::parse_engine_from_config( readonly_context &context, const config &cfg, std::back_insert_iterator<std::vector< engine_ptr > > b )
{
engine_ptr eng = context.get_engine_by_cfg(cfg);
if (eng){
//do not override that method in subclasses which cannot create engines
eng->do_parse_engine_from_config(cfg, b);
}
}
void engine::parse_goal_from_config( readonly_context &context, const config &cfg, std::back_insert_iterator<std::vector< goal_ptr > > b )
{
engine_ptr eng = context.get_engine_by_cfg(cfg);
if (eng){
//do not override that method in subclasses which cannot create goals
eng->do_parse_goal_from_config(cfg, b);
}
}
void engine::parse_stage_from_config( ai_context &context, const config &cfg, std::back_insert_iterator<std::vector< stage_ptr > > b )
{
engine_ptr eng = context.get_engine_by_cfg(cfg);
if (eng){
//do not override that method in subclasses which cannot create stages
eng->do_parse_stage_from_config(context, cfg, b);
}
}
void engine::do_parse_aspect_from_config( const config &/*cfg*/, const std::string &/*id*/, std::back_insert_iterator< std::vector<aspect_ptr> > /*b*/ )
{
}
void engine::do_parse_candidate_action_from_config( rca_context &/*context*/, const config &/*cfg*/, std::back_insert_iterator<std::vector< candidate_action_ptr > > /*b*/ ){
}
void engine::do_parse_engine_from_config( const config &/*cfg*/, std::back_insert_iterator<std::vector< engine_ptr > > /*b*/ ){
}
void engine::do_parse_goal_from_config( const config &/*cfg*/, std::back_insert_iterator<std::vector< goal_ptr > > /*b*/ ){
}
void engine::do_parse_stage_from_config( ai_context &/*context*/, const config &/*cfg*/, std::back_insert_iterator<std::vector< stage_ptr > > /*b*/ )
{
}
std::string engine::evaluate(const std::string& /*str*/)
{
return "evaluate command is not implemented by this engine";
}
void engine::set_ai_context(ai_context_ptr ai_context)
{
ai_context_ = ai_context;
}
ai_context_ptr engine::get_ai_context()
{
return ai_context_;
}
config engine::to_config() const
{
config cfg;
cfg["engine"] = engine_;
cfg["name"] = get_name();
return cfg;
}
readonly_context& engine::get_readonly_context()
{
return ai_;
}
} //end of namespace ai