DeepDecomposer.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. using TGoalHashSet = std::unordered_map<Goals::TSubgoal, Goals::TGoalVec, GoalHash>;
  22. class DeepDecomposer
  23. {
  24. private:
  25. std::vector<Goals::TGoalVec> goals;
  26. std::vector<TGoalHashSet> decompositionCache;
  27. int depth;
  28. const Nullkiller * ai;
  29. public:
  30. DeepDecomposer(const Nullkiller * ai);
  31. void reset();
  32. Goals::TGoalVec decompose(Goals::TSubgoal behavior, int depthLimit);
  33. private:
  34. Goals::TSubgoal aggregateGoals(int startDepth, Goals::TSubgoal last);
  35. Goals::TSubgoal unwrapComposition(Goals::TSubgoal goal);
  36. bool isCompositionLoop(Goals::TSubgoal goal);
  37. Goals::TGoalVec decomposeCached(Goals::TSubgoal goal, bool & fromCache);
  38. void addToCache(Goals::TSubgoal goal);
  39. };
  40. }