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