(C++)  1.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
PlannerReasoner.hh
1 #ifndef GRAIL_PLANNER_REASONER_H
2 #define GRAIL_PLANNER_REASONER_H
3 
4 #include "Reasoner.hh"
5 #include "../Planning/GoalSelector.hh"
6 #include "../Behavior.hh"
7 #include "../Planning/Plan.hh"
8 #include "../Planning/Planner/PlannerSnapshots.h"
9 
10 namespace grail
11 {
12  using PlannerCallback = std::function<void(const planning::Plan&, const planning::Goal&)>;
13 
14  namespace planning
15  {
16  class DomainTranslator;
17  }
20  {
21  public:
22  struct Config
23  {
24  Config() noexcept {}
25  std::size_t maxIterations = 1000;
26  int maxPlanLength = -1;
27  std::size_t iterationsPerFrame = 10;
28  double maxPlanCost = -1;
29  bool usePartialPlans = true;
30  };
31 
32  PlannerReasoner(MemoryPool& memory);
34  std::shared_ptr<planning::GoalSelector> goalSelector,
35  std::unique_ptr<planning::DomainTranslator> actionTranslator,
36  const Config& config);
37  void SelectBehavior(AIEntity& entity) override;
38  void SetNewGoal(std::unique_ptr<planning::Goal> newGoal, AIEntity& entity) override;
39 
43  void SetupNewPlanner(std::unique_ptr<planning::DomainTranslator> domainTranslator, const Config& config);
44 
46  void SetFallbackBehavior(std::unique_ptr<Behavior> behavior);
47  const planning::Goal* GetCurrentGoal() const override;
48 
49  void BindPlanningSucceededCallback(PlannerCallback callback);
50  void BindPartialPlanFoundCallback(PlannerCallback callback);
51  void BindPlanningFailedCallback(std::function<void(const planning::Goal&)> callback);
52  void BindPlanExecutedCallback(std::function<void()> callback);
53 
54  //TODO: revise this approach
55  void SetSnapshotProduction(bool shouldProduce);
56  bool IsComputing() const;
57 
58  PlannerReasonerSnapshot ProduceDebugSnapshot();
59  std::unique_ptr<ISnapshotGenerator> CreateSnapshotGenerator(std::size_t) override;
60  void ClearCurrentDebugSnapshot();
61 
62  void SetDebugSnapshotFirstIteration(std::size_t iterationNumber);
63  void SetDebugSnapshotLastIteration(std::size_t iterationNumber);
64  std::size_t GetDebugSnapshotFirstIteration() const;
65  std::size_t GetDebugSnapshotLastIteration() const;
66  private:
67  void Reset(AIEntity& entity, const class planning::Goal& goal);
68 
69  planning::Planner planner;
70  std::shared_ptr<planning::GoalSelector> goalSelector;
71  std::unique_ptr<planning::DomainTranslator> domainTranslator;
72 
73  planning::Plan currentPlan;
74  std::size_t iterationsPerFrame = 0;
75  bool usePartialPlans = false;
76 
77  std::unique_ptr<planning::Goal> chosenGoal = nullptr;
78  std::unique_ptr<Behavior> fallbackBehavior = nullptr;
79 
80  PlannerCallback onPlanningSucceeded;
81  PlannerCallback onPartialPlanFound;
82  std::function<void(const planning::Goal&)> onPlanningFailed;
83  std::function<void()> onPlanExecuted;
84 
85  //TODO: revise this approach
86  bool produceSnapshot = false;
87  PlannerReasonerSnapshot snapshot;
88 
89  std::size_t debugSnapshotFirstIteration = 0;
90  std::size_t debugSnapshotLastIteration = std::numeric_limits<std::size_t>::max();
91  };
92 }
93 #endif //GRAIL_PLANNER_REASONER_H
The Reasoner class - Entity&#39;s "brain", assigns them behaviors chosen by user-defined algorithms...
Definition: Reasoner.hh:20
The MemoryPool class - preallocated memory container for optimization issues.
Definition: MemoryPool.hh:73
Definition: PlannerReasoner.hh:22
A reasoner which uses planners to find optimal sequences of behaviors based on goals.
Definition: PlannerReasoner.hh:19
Definition: GoalSelector.hh:11
The main class responsible for finding paths in plan space.
Definition: Planner.hh:22
Definition: AIEntity.cpp:10
Represents a planner goal, used by PlannerReasoner.
Definition: Goal.hh:14
A data structure used by PlannerReasoner to execute a sequence of behaviors.
Definition: Plan.hh:15
The AIEntity class - Defines a basic object which can execute behaviors.
Definition: AIEntity.hh:38
Definition: PlannerSnapshots.h:68