PriorityEvaluator.h 2.8 KB

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