Grail (C++)  1.2.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
WorldState.hh
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_WORLD_STATE_H
4 #define GRAIL_WORLD_STATE_H
5 
6 #include <sstream>
7 #include <vector>
8 #include "WorldObject.hh"
9 #include "../Domain.hh"
10 
11 namespace grail
12 {
13 namespace planner
14 {
17  {
18  public:
19  WorldState(MemoryPool* memory, const std::shared_ptr<Domain>& domain,
20  const std::vector<WorldObject>& worldObjects);
21  WorldState(const WorldState& other);
22  WorldState(WorldState&& other) = default;
23  virtual ~WorldState() override = default;
24 
25  WorldState& operator=(const WorldState& other);
26  WorldState& operator=(WorldState&& other) = default;
27 
28  bool operator==(const WorldState& other) const;
29 
30  std::vector<class Action> GetLegalActions() const;
31  std::vector<std::vector<unsigned int>> GenerateParameterLists(
32  const std::vector<std::vector<unsigned int>>& precedingParameterLists,
33  unsigned int searchedTypeIndex) const;
34 
35  const WorldObject* GetObjectByIndex(unsigned int index) const;
36  WorldObject* GetObjectByIndex(unsigned int index);
37  const std::map<unsigned int, WorldObject>& GetObjectMap() const;
38  std::shared_ptr<Domain> GetDomain() const;
39 
40  WorldObject& AddObject(const std::string& typeName);
41 
44  void RemoveObject(unsigned int objectIndex);
45  void AddQueuedObjects();
46  void RemoveQueuedObjects();
47 
49  std::vector<const WorldObject*> GetObjectsOfType(const std::string& typeName) const;
50 
52  std::vector<WorldObject*> GetObjectsOfType(const std::string& typeName);
53 
55  int CountObjectsOfType(const std::string& typeName) const;
56 
57  private:
58  std::shared_ptr<Domain> domain = nullptr;
59  std::map<unsigned int, WorldObject> objects{};
60  std::vector<WorldObject> objectsToAdd{};
61  //TODO: move it out of this class, preferably to a temporal object (that is removed when not needed anymore)
62  //REVIEW: resolve todo
63 
64  std::vector<unsigned int> indicesToRemove{};
65  // 0 is reserved for world
66  unsigned int nextIndex = 1;
67  };
68 }
69 }
70 
71 #endif //GRAIL_WORLD_STATE_H
grail::planner::WorldObject
Definition: WorldObject.hh:15
grail::planner::WorldState
A class representing planner world state.
Definition: WorldState.hh:16
grail::planner::WorldState::CountObjectsOfType
int CountObjectsOfType(const std::string &typeName) const
Definition: WorldState.cpp:135
grail::planner::WorldState::GetObjectsOfType
std::vector< const WorldObject * > GetObjectsOfType(const std::string &typeName) const
Definition: WorldState.cpp:107
grail::planner::MemoryPool
The MemoryPool class - preallocated memory container for optimization issues.
Definition: MemoryPool.hh:77
grail::planner::ParametrizedObject
Definition: ParametrizedObject.hh:22
grail::planner::WorldState::RemoveObject
void RemoveObject(unsigned int objectIndex)
Definition: WorldState.cpp:83