PriorityEvaluator.h 3.5 KB

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