PriorityEvaluator.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * PriorityEvaluator.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. #if __has_include(<fuzzylite/Headers.h>)
  12. # include <fuzzylite/Headers.h>
  13. #else
  14. # include <fl/Headers.h>
  15. #endif
  16. #include "../Goals/CGoal.h"
  17. #include "../Pathfinding/AIPathfinder.h"
  18. VCMI_LIB_NAMESPACE_BEGIN
  19. VCMI_LIB_NAMESPACE_END
  20. namespace NKAI
  21. {
  22. class BuildingInfo;
  23. class Nullkiller;
  24. struct HitMapInfo;
  25. class RewardEvaluator
  26. {
  27. public:
  28. const Nullkiller * ai;
  29. RewardEvaluator(const Nullkiller * ai) : ai(ai) {}
  30. uint64_t getArmyReward(const CGObjectInstance * target, const CGHeroInstance * hero, const CCreatureSet * army, bool checkGold) const;
  31. uint64_t getArmyGrowth(const CGObjectInstance * target, const CGHeroInstance * hero, const CCreatureSet * army) const;
  32. int getGoldCost(const CGObjectInstance * target, const CGHeroInstance * hero, const CCreatureSet * army) const;
  33. float getEnemyHeroStrategicalValue(const CGHeroInstance * enemy) const;
  34. float getResourceRequirementStrength(int resType) const;
  35. float getResourceRequirementStrength(const TResources & res) const;
  36. float getStrategicalValue(const CGObjectInstance * target, const CGHeroInstance * hero = nullptr) const;
  37. float getTotalResourceRequirementStrength(int resType) const;
  38. float evaluateWitchHutSkillScore(const CGObjectInstance * hut, const CGHeroInstance * hero, HeroRole role) const;
  39. float getSkillReward(const CGObjectInstance * target, const CGHeroInstance * hero, HeroRole role) const;
  40. int32_t getGoldReward(const CGObjectInstance * target, const CGHeroInstance * hero) const;
  41. uint64_t getUpgradeArmyReward(const CGTownInstance * town, const BuildingInfo & bi) const;
  42. const HitMapInfo & getEnemyHeroDanger(const int3 & tile, uint8_t turn) const;
  43. uint64_t townArmyGrowth(const CGTownInstance * town) const;
  44. uint64_t getManaRecoveryArmyReward(const CGHeroInstance * hero) const;
  45. };
  46. struct DLL_EXPORT EvaluationContext
  47. {
  48. float movementCost;
  49. std::map<HeroRole, float> movementCostByRole;
  50. int manaCost;
  51. uint64_t danger;
  52. float closestWayRatio;
  53. float armyLossPersentage;
  54. float armyReward;
  55. uint64_t armyGrowth;
  56. int32_t goldReward;
  57. int32_t goldCost;
  58. float skillReward;
  59. float strategicalValue;
  60. HeroRole heroRole;
  61. uint8_t turn;
  62. RewardEvaluator evaluator;
  63. float enemyHeroDangerRatio;
  64. EvaluationContext(const Nullkiller * ai);
  65. void addNonCriticalStrategicalValue(float value);
  66. };
  67. class IEvaluationContextBuilder
  68. {
  69. public:
  70. virtual ~IEvaluationContextBuilder() = default;
  71. virtual void buildEvaluationContext(EvaluationContext & evaluationContext, Goals::TSubgoal goal) const = 0;
  72. };
  73. class Nullkiller;
  74. class PriorityEvaluator
  75. {
  76. public:
  77. PriorityEvaluator(const Nullkiller * ai);
  78. ~PriorityEvaluator();
  79. void initVisitTile();
  80. float evaluate(Goals::TSubgoal task);
  81. private:
  82. const Nullkiller * ai;
  83. fl::Engine * engine;
  84. fl::InputVariable * armyLossPersentageVariable;
  85. fl::InputVariable * heroRoleVariable;
  86. fl::InputVariable * mainTurnDistanceVariable;
  87. fl::InputVariable * scoutTurnDistanceVariable;
  88. fl::InputVariable * turnVariable;
  89. fl::InputVariable * goldRewardVariable;
  90. fl::InputVariable * armyRewardVariable;
  91. fl::InputVariable * armyGrowthVariable;
  92. fl::InputVariable * dangerVariable;
  93. fl::InputVariable * skillRewardVariable;
  94. fl::InputVariable * strategicalValueVariable;
  95. fl::InputVariable * rewardTypeVariable;
  96. fl::InputVariable * closestHeroRatioVariable;
  97. fl::InputVariable * goldPressureVariable;
  98. fl::InputVariable * goldCostVariable;
  99. fl::InputVariable * fearVariable;
  100. fl::OutputVariable * value;
  101. std::vector<std::shared_ptr<IEvaluationContextBuilder>> evaluationContextBuilders;
  102. EvaluationContext buildEvaluationContext(Goals::TSubgoal goal) const;
  103. };
  104. }