DeepDecomposer.h 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * DeepDecomposer.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../Goals/AbstractGoal.h"
  12. namespace NKAI
  13. {
  14. struct GoalHash
  15. {
  16. uint64_t operator()(const Goals::TSubgoal & goal) const
  17. {
  18. return goal->getHash();
  19. }
  20. };
  21. typedef std::unordered_map<Goals::TSubgoal, Goals::TGoalVec, GoalHash> TGoalHashSet;
  22. class DeepDecomposer
  23. {
  24. private:
  25. std::vector<Goals::TGoalVec> goals;
  26. std::vector<TGoalHashSet> decompositionCache;
  27. int depth;
  28. public:
  29. void reset();
  30. Goals::TGoalVec decompose(Goals::TSubgoal behavior, int depthLimit);
  31. private:
  32. Goals::TSubgoal aggregateGoals(int startDepth, Goals::TSubgoal last);
  33. Goals::TSubgoal unwrapComposition(Goals::TSubgoal goal);
  34. bool isCompositionLoop(Goals::TSubgoal goal);
  35. Goals::TGoalVec decomposeCached(Goals::TSubgoal goal, bool & fromCache);
  36. void addToCache(Goals::TSubgoal goal);
  37. };
  38. }