Grail (C++)  1.3.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
SumAggregator.hh
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_SUM_AGGREGATOR_H
4 #define GRAIL_SUM_AGGREGATOR_H
5 
6 #include "Aggregator.hh"
7 
8 namespace grail
9 {
10 namespace evaluator
11 {
12  template <typename ContextType>
17  class SumAggregator : public Aggregator<ContextType>
18  {
19  public:
24  SumAggregator(const std::vector<std::shared_ptr<Evaluator<ContextType>>>& childEvaluators)
25  : Aggregator<ContextType>{childEvaluators}
26  {
27  }
28 
29  virtual data::EvaluatorType GetEvaluatorType() const override final { return data::EvaluatorType::AGGREGATOR_SUM; }
30 
31  protected:
32  virtual float
33  Evaluate(const ContextType& context, data::UtilityEvaluatorSnapshot* const snapshot) const override final
34  {
35  float weight = 0;
36  for(const auto& evaluator : this->childEvaluators)
37  {
38  weight += evaluator->EvaluateContext(context, snapshot);
39  }
40  return weight;
41  }
42  };
43 }
44 }
45 
46 #endif
grail::evaluator::SumAggregator::SumAggregator
SumAggregator(const std::vector< std::shared_ptr< Evaluator< ContextType >>> &childEvaluators)
SumAggregator - Constructor.
Definition: SumAggregator.hh: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::evaluator::SumAggregator
The SumAggregator class - Evaluator aggregating multiple other Evaluators' scores into one output by ...
Definition: SumAggregator.hh:17
grail::data::UtilityEvaluatorSnapshot
The UtilityEvaluatorSnapshot class - debug snapshot of whole evaluator tree assigned to evaluated obj...
Definition: UtilityEvaluatorSnapshot.h:26
grail::evaluator::SumAggregator::Evaluate
virtual float Evaluate(const ContextType &context, data::UtilityEvaluatorSnapshot *const snapshot) const override final
Evaluate - Called from EvaluateContext which also evaluates context, but without automatically fillin...
Definition: SumAggregator.hh:33