(C++)  1.0.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
ActionTemplate.hh
1 #ifndef GRAIL_ACTION_TEMPLATE_H
2 #define GRAIL_ACTION_TEMPLATE_H
3 
4 #include <functional>
5 #include <vector>
6 #include <string>
7 
8 namespace grail
9 {
10  namespace planning
11  {
12  class WorldObject;
13  class WorldState;
14 
15  using PreconditionFunction = std::function<bool(const std::vector<const WorldObject*>&, const WorldState&)>;
16  using EffectFunction = std::function<void(const std::vector<WorldObject*>&, WorldState&)>;
17  using CostFunction = std::function<double(const std::vector<const WorldObject*>&, const WorldState&)>;
18 
21  {
22  friend class Action;
23 
24  public:
25  ActionTemplate(const std::string& name, const std::vector<unsigned int>& actionParameterTypes);
26  ActionTemplate(ActionTemplate&& other) = default;
27  ~ActionTemplate() = default;
28 
31  void SetPreconditions(PreconditionFunction preconditionFunction);
32 
35  void SetEffects(EffectFunction effectFunction);
36 
39  void SetCostFunction(CostFunction costFunction);
40 
41  void SetTypeId(int id);
42  int GetTypeId() const;
43  const std::string& GetName() const;
44  std::vector<class Action> GenerateActions(const class WorldState& worldState) const;
45 
46  private:
47  std::string name = "";
48  std::vector<unsigned int> actionParameterTypes{};
49  PreconditionFunction preconditions = [](const std::vector<const WorldObject*>&, const WorldState&) {return true; };
50  EffectFunction effects = [](const std::vector<WorldObject*>&, WorldState&) {};
51  CostFunction cost = [](const std::vector<const WorldObject*>&, const WorldState&) {return 1.0; };
52  int typeId = -1;
53  };
54  }
55 }
56 #endif // GRAIL_ACTION_TEMPLATE_H
Definition: Action.hh:11
A class representing an action that can be simulated by grail planner.
Definition: ActionTemplate.hh:21
void SetPreconditions(PreconditionFunction preconditionFunction)
Definition: ActionTemplate.cpp:16
void SetEffects(EffectFunction effectFunction)
Definition: ActionTemplate.cpp:21
void SetCostFunction(CostFunction costFunction)
Definition: ActionTemplate.cpp:26
A class representing planner world state.
Definition: WorldState.hh:15