PriorityEvaluator.h 3.2 KB

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