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