DeepDecomposer.h 993 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. struct GoalHash
  13. {
  14. uint64_t operator()(const Goals::TSubgoal & goal) const
  15. {
  16. return goal->getHash();
  17. }
  18. };
  19. typedef std::unordered_map<Goals::TSubgoal, Goals::TGoalVec, GoalHash> TGoalHashSet;
  20. class DeepDecomposer
  21. {
  22. private:
  23. std::vector<Goals::TGoalVec> goals;
  24. std::vector<TGoalHashSet> decompositionCache;
  25. int depth;
  26. public:
  27. void reset();
  28. Goals::TGoalVec decompose(Goals::TSubgoal behavior, int depthLimit);
  29. private:
  30. Goals::TSubgoal aggregateGoals(int startDepth, Goals::TSubgoal last);
  31. Goals::TSubgoal unwrapComposition(Goals::TSubgoal goal);
  32. bool isCompositionLoop(Goals::TSubgoal goal);
  33. Goals::TGoalVec decomposeCached(Goals::TSubgoal goal, bool & fromCache);
  34. void addToCache(Goals::TSubgoal goal);
  35. };