Grail (C++)  1.3.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
Aggregator.hh
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_AGGREGATOR_H
4 #define GRAIL_AGGREGATOR_H
5 
6 #include "../Evaluator.hh"
7 
8 #include <cassert>
9 #include <limits>
10 #include <memory>
11 #include <vector>
12 
13 namespace grail
14 {
15 namespace evaluator
16 {
17  template <typename ContextType>
22  class Aggregator : public Evaluator<ContextType>
23  {
24  public:
29  Aggregator(const std::vector<std::shared_ptr<Evaluator<ContextType>>>& childEvaluators)
30  : childEvaluators{childEvaluators}
31  {
32  }
33 
34  Aggregator(const Aggregator<ContextType>&) = default;
35  Aggregator(Aggregator<ContextType>&&) = default;
36 
37  virtual ~Aggregator() = default;
38 
39  Aggregator& operator =(const Aggregator<ContextType>&) = default;
40  Aggregator& operator =(Aggregator<ContextType>&&) = default;
41 
42  protected:
43  virtual void DebugDump(const std::map<const void*, unsigned int>& nodeMapping,
44  data::EvaluationDebugData& debugData) const override
45  {
46  for(const auto& childEvaluator : childEvaluators)
47  {
48  debugData.AddChildNode(nodeMapping.at(childEvaluator.get()));
49  }
50  }
51 
52  std::vector<std::shared_ptr<Evaluator<ContextType>>> childEvaluators{};
53  };
54 }
55 }
56 #endif //GRAIL_EVALUATOR_H
grail::evaluator::Aggregator::Aggregator
Aggregator(const std::vector< std::shared_ptr< Evaluator< ContextType >>> &childEvaluators)
Aggregator - Constructor.
Definition: Aggregator.hh:29
grail::data::EvaluationDebugData
The EvaluationDebugData class - debug data describing singular evaluator.
Definition: EvaluationDebugData.h:24
grail::evaluator::Aggregator
The Aggregator class - Base class for an Evaluator aggregating multiple other Evaluators' scores into...
Definition: Aggregator.hh:22
grail::evaluator::Evaluator
The Evaluator class - base class being able to evaluate given context and output the result.
Definition: Evaluator.hh:22
grail::data::EvaluationDebugData::AddChildNode
void AddChildNode(unsigned int childNodeIndex)
AddChildNode - add node as leaf/child to this data node.
Definition: EvaluationDebugData.cpp:14
grail::evaluator::Aggregator::DebugDump
virtual void DebugDump(const std::map< const void *, unsigned int > &nodeMapping, data::EvaluationDebugData &debugData) const override
DebugDump - Called from EvaluateContext, which generates additional debug data for each evaluator....
Definition: Aggregator.hh:43