Grail (C++)  1.4.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
ActionTemplate.hh
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_ACTION_TEMPLATE_H
4 #define GRAIL_ACTION_TEMPLATE_H
5 
6 #include <functional>
7 #include <string>
8 #include <vector>
9 
10 namespace grail
11 {
12 namespace planner
13 {
14  class WorldObject;
15  class WorldState;
16 
20  using PreconditionFunction = std::function<bool(const std::vector<const WorldObject*>&, const WorldState&)>;
21 
25  using EffectFunction = std::function<void(const std::vector<WorldObject*>&, WorldState&)>;
26 
30  using CostFunction = std::function<double(const std::vector<const WorldObject*>&, const WorldState&)>;
31 
35  {
36  friend class Action;
37 
38  public:
45  ActionTemplate(const std::string& name, const std::vector<unsigned int>& actionParameterTypes,
46  PreconditionFunction preconditionFunction, EffectFunction effectFunction, CostFunction costFunction);
47  ActionTemplate(ActionTemplate&& other) = default;
48  ~ActionTemplate() = default;
49 
54  int GetTypeId() const;
55 
60  const std::string& GetName() const;
61 
67  std::vector<class Action> GenerateActions(const class WorldState& worldState) const;
68 
69  private:
70  std::string name = "";
71  std::vector<unsigned int> actionParameterTypes{};
72  PreconditionFunction preconditions = [](const std::vector<const WorldObject*>&, const WorldState&)
73  {
74  return true;
75  };
76  EffectFunction effects = [](const std::vector<WorldObject*>&, WorldState&)
77  {
78  };
79  CostFunction cost = [](const std::vector<const WorldObject*>&, const WorldState&) { return 1.0; };
80  int typeId = -1;
81  };
82 }
83 }
84 
85 #endif // GRAIL_ACTION_TEMPLATE_H
grail::planner::ActionTemplate::GetName
const std::string & GetName() const
Definition: ActionTemplate.cpp:24
grail::planner::Action
Definition: Action.hh:16
grail::planner::WorldState
Definition: WorldState.hh:20
grail::planner::ActionTemplate
Definition: ActionTemplate.hh:34
grail::planner::ActionTemplate::GenerateActions
std::vector< class Action > GenerateActions(const class WorldState &worldState) const
Definition: ActionTemplate.cpp:29
grail::planner::ActionTemplate::GetTypeId
int GetTypeId() const
Definition: ActionTemplate.cpp:19
grail::planner::ActionTemplate::ActionTemplate
ActionTemplate(const std::string &name, const std::vector< unsigned int > &actionParameterTypes, PreconditionFunction preconditionFunction, EffectFunction effectFunction, CostFunction costFunction)
Definition: ActionTemplate.cpp:12