(C++)  1.1.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
Evaluator.hh
1 #ifndef GRAIL_EVALUATOR_H
2 #define GRAIL_EVALUATOR_H
3 
4 #include "../GrailData/UtilityModel/EvaluatorType.h"
5 #include "../GrailData/DebugInfo/UtilityEvaluatorSnapshot.h"
6 
7 #include <vector>
8 #include <cassert>
9 #include <limits>
10 #include <memory>
11 
12 namespace grail
13 {
14  namespace utility
15  {
16  template <typename ContextType>
20  class Evaluator
21  {
22  public:
29  float EvaluateContext(const ContextType& context, UtilityEvaluatorSnapshot* const snapshot) const
30  {
31  float score = Evaluate(context, snapshot);
32  if(snapshot != nullptr)
33  {
34  std::size_t nodeIndex = snapshot->AddNode(this);
35  EvaluationDebugData debugData{GetEvaluatorType(), score, nodeIndex};
36  DebugDump(snapshot->GetNodeMapping(), debugData);
37  snapshot->AddEvaluation(std::move(debugData));
38  }
39  return score;
40  }
41 
42  virtual EvaluatorType GetEvaluatorType() const =0;
43 
44  protected:
51  virtual float Evaluate(const ContextType& context, UtilityEvaluatorSnapshot* const snapshot) const =0;
52 
58  virtual void DebugDump(const std::map<const void*, std::size_t>& nodeMapping, EvaluationDebugData& debugData) const =0;
59  };
60  }
61 }
62 #endif //GRAIL_EVALUATOR_H
The EvaluationDebugData class - debug data describing singular evaluator.
Definition: EvaluationDebugData.h:20
The UtilityEvaluatorSnapshot class - debug snapshot of whole evaluator tree assigned to evaluated obj...
Definition: UtilityEvaluatorSnapshot.h:22
std::size_t AddNode(const void *nodePointer)
AddNode - assign index indicating position in debug tree to the given node pointer.
Definition: UtilityEvaluatorSnapshot.cpp:15
const std::map< const void *, std::size_t > & GetNodeMapping() const
GetNodeMapping.
Definition: UtilityEvaluatorSnapshot.cpp:26
void AddEvaluation(EvaluationDebugData &&debugData)
AddEvaluation - add debug data describing singular evaluator node to this snapshot.
Definition: UtilityEvaluatorSnapshot.cpp:10
The Evaluator class - base class being able to evaluate given context and output the result.
Definition: Evaluator.hh:21
virtual float Evaluate(const ContextType &context, UtilityEvaluatorSnapshot *const snapshot) const =0
Evaluate - Called from EvaluateContext which also evaluates context, but without automatically fillin...
float EvaluateContext(const ContextType &context, UtilityEvaluatorSnapshot *const snapshot) const
EvaluateContext - evaluates provided context and if provided snapshot is not empty,...
Definition: Evaluator.hh:29
virtual void DebugDump(const std::map< const void *, std::size_t > &nodeMapping, EvaluationDebugData &debugData) const =0
DebugDump - Called from EvaluateContext, which generates additional debug data for each evaluator....