PriorityEvaluator.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. };
  40. struct DLL_EXPORT EvaluationContext
  41. {
  42. float movementCost;
  43. std::map<HeroRole, float> movementCostByRole;
  44. int manaCost;
  45. uint64_t danger;
  46. float closestWayRatio;
  47. float armyLossPersentage;
  48. float armyReward;
  49. uint64_t armyGrowth;
  50. int32_t goldReward;
  51. int32_t goldCost;
  52. float skillReward;
  53. float strategicalValue;
  54. HeroRole heroRole;
  55. uint8_t turn;
  56. RewardEvaluator evaluator;
  57. float enemyHeroDangerRatio;
  58. EvaluationContext(const Nullkiller * ai);
  59. };
  60. class IEvaluationContextBuilder
  61. {
  62. public:
  63. virtual ~IEvaluationContextBuilder() = default;
  64. virtual void buildEvaluationContext(EvaluationContext & evaluationContext, Goals::TSubgoal goal) const = 0;
  65. };
  66. class Nullkiller;
  67. class PriorityEvaluator
  68. {
  69. public:
  70. PriorityEvaluator(const Nullkiller * ai);
  71. ~PriorityEvaluator();
  72. void initVisitTile();
  73. float evaluate(Goals::TSubgoal task);
  74. private:
  75. const Nullkiller * ai;
  76. fl::Engine * engine;
  77. fl::InputVariable * armyLossPersentageVariable;
  78. fl::InputVariable * heroRoleVariable;
  79. fl::InputVariable * mainTurnDistanceVariable;
  80. fl::InputVariable * scoutTurnDistanceVariable;
  81. fl::InputVariable * turnVariable;
  82. fl::InputVariable * goldRewardVariable;
  83. fl::InputVariable * armyRewardVariable;
  84. fl::InputVariable * armyGrowthVariable;
  85. fl::InputVariable * dangerVariable;
  86. fl::InputVariable * skillRewardVariable;
  87. fl::InputVariable * strategicalValueVariable;
  88. fl::InputVariable * rewardTypeVariable;
  89. fl::InputVariable * closestHeroRatioVariable;
  90. fl::InputVariable * goldPreasureVariable;
  91. fl::InputVariable * goldCostVariable;
  92. fl::InputVariable * fearVariable;
  93. fl::OutputVariable * value;
  94. std::vector<std::shared_ptr<IEvaluationContextBuilder>> evaluationContextBuilders;
  95. EvaluationContext buildEvaluationContext(Goals::TSubgoal goal) const;
  96. };
  97. }