Grail (C++)  1.4.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
Evaluator.hh
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_EVALUATOR_H
4 #define GRAIL_EVALUATOR_H
5 
6 #include "../GrailData/DebugInfo/UtilityEvaluatorSnapshot.h"
7 #include "../GrailData/UtilityModel/EvaluatorType.h"
8 
9 #include <cassert>
10 #include <limits>
11 #include <memory>
12 #include <vector>
13 
14 namespace grail
15 {
16 namespace evaluator
17 {
18  template<typename ContextType>
19  class Consideration;
20 
21  template <typename ContextType>
25  class Evaluator
26  {
27  public:
34  float EvaluateContext(const ContextType& context, data::UtilityEvaluatorSnapshot* const snapshot) const
35  {
36  float score = Evaluate(context, snapshot);
37  if(snapshot != nullptr)
38  {
39  unsigned int nodeIndex = snapshot->AddNode(this);
40  data::EvaluationDebugData debugData{GetEvaluatorType(), score, nodeIndex};
41  DebugDump(snapshot->GetNodeMapping(), debugData);
42  snapshot->AddEvaluation(std::move(debugData));
43  }
44  return score;
45  }
46 
47  virtual data::EvaluatorType GetEvaluatorType() const =0;
48  virtual void GetDependentConsiderations(std::vector<Consideration<ContextType>*>& considerations) = 0;
49 
50  protected:
57  virtual float Evaluate(const ContextType& context, data::UtilityEvaluatorSnapshot* const snapshot) const =0;
58 
64  virtual void DebugDump(const std::map<const void*, unsigned int>& nodeMapping,
65  data::EvaluationDebugData& debugData) const =0;
66  };
67 }
68 }
69 #endif //GRAIL_EVALUATOR_H
grail::data::EvaluationDebugData
The EvaluationDebugData class - debug data describing singular evaluator.
Definition: EvaluationDebugData.h:24
grail::evaluator::Evaluator::EvaluateContext
float EvaluateContext(const ContextType &context, data::UtilityEvaluatorSnapshot *const snapshot) const
EvaluateContext - evaluates provided context and if provided snapshot is not empty,...
Definition: Evaluator.hh:34
grail::evaluator::Evaluator::Evaluate
virtual float Evaluate(const ContextType &context, data::UtilityEvaluatorSnapshot *const snapshot) const =0
Evaluate - Called from EvaluateContext which also evaluates context, but without automatically fillin...
grail::evaluator::Evaluator
The Evaluator class - base class being able to evaluate given context and output the result.
Definition: Evaluator.hh:25
grail::data::UtilityEvaluatorSnapshot::AddNode
unsigned int AddNode(const void *nodePointer)
AddNode - assign index indicating position in debug tree to the given node pointer.
Definition: UtilityEvaluatorSnapshot.cpp:21
grail::data::UtilityEvaluatorSnapshot::GetNodeMapping
const std::map< const void *, unsigned int > & GetNodeMapping() const
GetNodeMapping.
Definition: UtilityEvaluatorSnapshot.cpp:32
grail::evaluator::Consideration
The Consideration class - Abstract type of Evaluator representing a subset of game state.
Definition: Consideration.hh:20
grail::evaluator::Evaluator::DebugDump
virtual void DebugDump(const std::map< const void *, unsigned int > &nodeMapping, data::EvaluationDebugData &debugData) const =0
DebugDump - Called from EvaluateContext, which generates additional debug data for each evaluator....
grail::data::UtilityEvaluatorSnapshot::AddEvaluation
void AddEvaluation(EvaluationDebugData &&debugData)
AddEvaluation - add debug data describing singular evaluator node to this snapshot.
Definition: UtilityEvaluatorSnapshot.cpp:16
grail::data::UtilityEvaluatorSnapshot
The UtilityEvaluatorSnapshot class - debug snapshot of whole evaluator tree assigned to evaluated obj...
Definition: UtilityEvaluatorSnapshot.h:26