The Battle for Wesnoth
1.17.17+dev
ai
composite
stage.cpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2009 - 2023
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
* Stage of a composite AI
18
* @file
19
*/
20
21
#include "
ai/composite/ai.hpp
"
22
#include "
ai/composite/engine.hpp
"
23
#include "
ai/composite/stage.hpp
"
24
#include "
ai/contexts.hpp
"
25
#include "
log.hpp
"
26
#include "
resources.hpp
"
27
#include "
tod_manager.hpp
"
28
#include <map>
29
#include <string>
30
31
namespace
ai
{
32
33
static
lg::log_domain
log_ai_stage
(
"ai/stage"
);
34
#define DBG_AI_STAGE LOG_STREAM(debug, log_ai_stage)
35
#define LOG_AI_STAGE LOG_STREAM(info, log_ai_stage)
36
#define ERR_AI_STAGE LOG_STREAM(err, log_ai_stage)
37
38
// =======================================================================
39
// COMPOSITE AI STAGE
40
// =======================================================================
41
42
stage::stage
(
ai_context
&context,
const
config
&cfg )
43
: recursion_counter_(context.get_recursion_count()), cfg_(cfg)
44
{
45
init_ai_context_proxy
(context);
46
}
47
48
void
stage::on_create
()
49
{
50
LOG_AI_STAGE
<<
"side "
<<
get_side
() <<
" : "
<<
" created stage with name=["
<<
cfg_
[
"name"
]<<
"]"
;
51
}
52
53
stage::~stage
()
54
{
55
}
56
57
bool
stage::play_stage
()
58
{
59
return
do_play_stage
();
60
}
61
62
int
stage::get_recursion_count
()
const
63
{
64
return
recursion_counter_
.
get_count
();
65
}
66
67
config
stage::to_config
()
const
68
{
69
config
cfg;
70
cfg[
"engine"
] =
cfg_
[
"engine"
];
71
cfg[
"name"
] =
cfg_
[
"name"
];
72
cfg[
"id"
] =
cfg_
[
"id"
];
73
return
cfg;
74
}
75
76
std::string
stage::get_id
()
const
77
{
78
return
cfg_
[
"id"
];
79
}
80
81
std::string
stage::get_engine
()
const
82
{
83
return
cfg_
[
"engine"
];
84
}
85
86
std::string
stage::get_name
()
const
87
{
88
return
cfg_
[
"name"
];
89
}
90
91
// =======================================================================
92
// COMPOSITE AI IDLE STAGE
93
// =======================================================================
94
95
idle_stage::idle_stage
(
ai_context
&context,
const
config
&cfg )
96
:
stage
(context,cfg)
97
{
98
}
99
100
idle_stage::~idle_stage
()
101
{
102
}
103
104
bool
idle_stage::do_play_stage
(){
105
LOG_AI_STAGE
<<
"Turn "
<<
resources::tod_manager
->
turn
() <<
": playing idle stage for side: "
<<
get_side
();
106
return
false
;
107
}
108
109
// This is defined in the source file so that it can easily access the logger
110
bool
stage_factory::is_duplicate
(
const
std::string& name)
111
{
112
if
(
get_list
().find(name) !=
get_list
().end()) {
113
ERR_AI_STAGE
<<
"Error: Attempt to double-register stage "
<< name;
114
return
true
;
115
}
116
return
false
;
117
}
118
119
}
//end of namespace ai
ai::ai_context_proxy::init_ai_context_proxy
void init_ai_context_proxy(ai_context &target)
Definition:
contexts.hpp:94
ai::ai_context
Definition:
contexts.hpp:28
ai::idle_stage::do_play_stage
virtual bool do_play_stage()
Play the turn - implementation.
Definition:
stage.cpp:104
ai::idle_stage::idle_stage
idle_stage(ai_context &context, const config &cfg)
Definition:
stage.cpp:95
ai::idle_stage::~idle_stage
~idle_stage()
Definition:
stage.cpp:100
ai::recursion_counter::get_count
int get_count() const
Get the current value of the recursion counter.
Definition:
contexts.hpp:70
ai::side_context_proxy::get_side
virtual side_number get_side() const override
Get the side number.
Definition:
contexts.hpp:403
ai::stage_factory::is_duplicate
bool is_duplicate(const std::string &name)
Definition:
stage.cpp:110
ai::stage_factory::get_list
static factory_map & get_list()
Definition:
stage.hpp:97
ai::stage
Definition:
stage.hpp:30
ai::stage::get_recursion_count
int get_recursion_count() const
get the value of the recursion counter
Definition:
stage.cpp:62
ai::stage::recursion_counter_
recursion_counter recursion_counter_
Definition:
stage.hpp:75
ai::stage::get_engine
virtual std::string get_engine() const
Definition:
stage.cpp:81
ai::stage::get_id
virtual std::string get_id() const
Definition:
stage.cpp:76
ai::stage::~stage
virtual ~stage()
Destructor.
Definition:
stage.cpp:53
ai::stage::cfg_
config cfg_
Definition:
stage.hpp:77
ai::stage::play_stage
bool play_stage()
Play the turn - strategy.
Definition:
stage.cpp:57
ai::stage::stage
stage(ai_context &context, const config &cfg)
Constructor.
Definition:
stage.cpp:42
ai::stage::do_play_stage
virtual bool do_play_stage()=0
Play the turn - implementation.
ai::stage::to_config
virtual config to_config() const
serialize
Definition:
stage.cpp:67
ai::stage::on_create
virtual void on_create()
Initialization.
Definition:
stage.cpp:48
ai::stage::get_name
virtual std::string get_name() const
Definition:
stage.cpp:86
config
A config object defines a single node in a WML file, with access to child nodes.
Definition:
config.hpp:161
lg::log_domain
Definition:
log.hpp:115
tod_manager::turn
int turn() const
Definition:
tod_manager.hpp:160
ai.hpp
Composite AI with turn sequence which is a vector of stages.
contexts.hpp
Helper functions for the object which operates in the context of AI for specific side this is part of...
engine.hpp
AI Support engine - creating specific ai components from config.
log.hpp
Standard logging facilities (interface).
ai
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition:
actions.cpp:61
ai::log_ai_stage
static lg::log_domain log_ai_stage("ai/stage")
resources::tod_manager
::tod_manager * tod_manager
Definition:
resources.cpp:30
resources.hpp
LOG_AI_STAGE
#define LOG_AI_STAGE
Definition:
stage.cpp:35
ERR_AI_STAGE
#define ERR_AI_STAGE
Definition:
stage.cpp:36
stage.hpp
Composite AI stages.
tod_manager.hpp
Generated by
1.9.1