Grail (C++)  1.1.1
A multi-platform, modular, universal engine for embedding advanced AI in games.
AverageAggregator.hh
1 #ifndef GRAIL_AVERAGE_AGGREGATOR_H
2 #define GRAIL_AVERAGE_AGGREGATOR_H
3 
4 #include "Aggregator.hh"
5 
6 namespace grail
7 {
8  namespace utility
9  {
10  template <typename ContextType>
15  class AverageAggregator : public Aggregator<ContextType>
16  {
17  public:
22  AverageAggregator(const std::vector<std::shared_ptr<Evaluator<ContextType>>>& childEvaluators)
23  : Aggregator<ContextType>{childEvaluators}
24  {
25  }
26 
27  virtual EvaluatorType GetEvaluatorType() const override final { return EvaluatorType::AGGREGATOR_AVERAGE; }
28 
29  protected:
30  virtual float
31  Evaluate(const ContextType& context, UtilityEvaluatorSnapshot* const snapshot) const override final
32  {
33  float weight = 0;
34  for(const auto& evaluator : this->childEvaluators)
35  {
36  weight += evaluator->EvaluateContext(context, snapshot);
37  }
38  return this->childEvaluators.size() > 0 ? weight / this->childEvaluators.size() : 0;
39  }
40  };
41  }
42 }
43 
44 #endif
grail::UtilityEvaluatorSnapshot
The UtilityEvaluatorSnapshot class - debug snapshot of whole evaluator tree assigned to evaluated obj...
Definition: UtilityEvaluatorSnapshot.h:21
grail::utility::AverageAggregator::Evaluate
virtual float Evaluate(const ContextType &context, UtilityEvaluatorSnapshot *const snapshot) const override final
Evaluate - Called from EvaluateContext which also evaluates context, but without automatically fillin...
Definition: AverageAggregator.hh:31
grail::utility::AverageAggregator::AverageAggregator
AverageAggregator(const std::vector< std::shared_ptr< Evaluator< ContextType >>> &childEvaluators)
AverageAggregator - Constructor.
Definition: AverageAggregator.hh:22
grail::utility::Aggregator
The Aggregator class - Base class for an Evaluator aggregating multiple other Evaluators' scores into...
Definition: Aggregator.hh:20
grail::utility::AverageAggregator
The AverageAggregator class - Evaluator aggregating multiple other Evaluators' scores into one output...
Definition: AverageAggregator.hh:15
grail::utility::Evaluator
The Evaluator class - base class being able to evaluate given context and output the result.
Definition: Evaluator.hh:20