(C++)  1.1.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
MaxAggregator.hh
1 #ifndef GRAIL_MAX_AGGREGATOR_H
2 #define GRAIL_MAX_AGGREGATOR_H
3 
4 #include "Aggregator.hh"
5 #include <cmath>
6 
7 namespace grail
8 {
9  namespace utility
10  {
11  template <typename ContextType>
16  class MaxAggregator : public Aggregator<ContextType>
17  {
18  public:
23  MaxAggregator(const std::vector<std::shared_ptr<Evaluator<ContextType>>>& childEvaluators)
24  : Aggregator<ContextType>{childEvaluators}
25  {
26  }
27 
28  virtual EvaluatorType GetEvaluatorType() const override final { return EvaluatorType::AGGREGATOR_MAX; }
29 
30  protected:
31  virtual float Evaluate(const ContextType& context, UtilityEvaluatorSnapshot* const snapshot) const override final
32  {
33  float weight = std::numeric_limits<float>::min();
34  for (const auto& evaluator : this->childEvaluators)
35  {
36  float current = evaluator->EvaluateContext(context, snapshot);
37  weight = std::max(weight, current);
38  }
39  return weight;
40  }
41  };
42  }
43 }
44 
45 #endif
The UtilityEvaluatorSnapshot class - debug snapshot of whole evaluator tree assigned to evaluated obj...
Definition: UtilityEvaluatorSnapshot.h:22
The Aggregator class - Base class for an Evaluator aggregating multiple other Evaluators' scores into...
Definition: Aggregator.hh:21
The Evaluator class - base class being able to evaluate given context and output the result.
Definition: Evaluator.hh:21
The MaxAggregator class - Evaluator aggregating multiple other Evaluators' scores into one output by ...
Definition: MaxAggregator.hh:17
MaxAggregator(const std::vector< std::shared_ptr< Evaluator< ContextType >>> &childEvaluators)
MaxAggregator - Constructor.
Definition: MaxAggregator.hh:23
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: MaxAggregator.hh:31