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