Grail (C++)  1.3.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 
17  using PreconditionFunction = std::function<bool(const std::vector<const WorldObject*>&, const WorldState&)>;
18  using EffectFunction = std::function<void(const std::vector<WorldObject*>&, WorldState&)>;
19  using CostFunction = std::function<double(const std::vector<const WorldObject*>&, const WorldState&)>;
20 
23  {
24  friend class Action;
25 
26  public:
33  ActionTemplate(const std::string& name, const std::vector<unsigned int>& actionParameterTypes,
34  PreconditionFunction preconditionFunction, EffectFunction effectFunction, CostFunction costFunction);
35  ActionTemplate(ActionTemplate&& other) = default;
36  ~ActionTemplate() = default;
37 
38  int GetTypeId() const;
39  const std::string& GetName() const;
40  std::vector<class Action> GenerateActions(const class WorldState& worldState) const;
41 
42  private:
43  std::string name = "";
44  std::vector<unsigned int> actionParameterTypes{};
45  PreconditionFunction preconditions = [](const std::vector<const WorldObject*>&, const WorldState&)
46  {
47  return true;
48  };
49  EffectFunction effects = [](const std::vector<WorldObject*>&, WorldState&)
50  {
51  };
52  CostFunction cost = [](const std::vector<const WorldObject*>&, const WorldState&) { return 1.0; };
53  int typeId = -1;
54  };
55 }
56 }
57 
58 #endif // GRAIL_ACTION_TEMPLATE_H
grail::planner::Action
Definition: Action.hh:12
grail::planner::WorldState
A class representing planner world state.
Definition: WorldState.hh:16
grail::planner::ActionTemplate
A class representing an action that can be simulated by grail planner.
Definition: ActionTemplate.hh:22
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