2
0

FuzzyEngines.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * FuzzyEngines.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/AbstractGoal.h"
  17. VCMI_LIB_NAMESPACE_BEGIN
  18. class CArmedInstance;
  19. VCMI_LIB_NAMESPACE_END
  20. class engineBase //subclasses create fuzzylite variables with "new" that are not freed - this is desired as fl::Engine wants to destroy these...
  21. {
  22. protected:
  23. fl::Engine engine;
  24. fl::RuleBlock * rules;
  25. virtual void configure();
  26. void addRule(const std::string & txt);
  27. public:
  28. engineBase();
  29. };
  30. class TacticalAdvantageEngine : public engineBase //TODO: rework this engine, it does not work well (example: AI hero with 140 beholders attacked 150 beholders - engine lowered danger 50000 -> 35000)
  31. {
  32. public:
  33. TacticalAdvantageEngine();
  34. float getTacticalAdvantage(const CArmedInstance * we, const CArmedInstance * enemy); //returns factor how many times enemy is stronger than us
  35. private:
  36. fl::InputVariable * ourWalkers;
  37. fl::InputVariable * ourShooters;
  38. fl::InputVariable * ourFlyers;
  39. fl::InputVariable * enemyWalkers;
  40. fl::InputVariable * enemyShooters;
  41. fl::InputVariable * enemyFlyers;
  42. fl::InputVariable * ourSpeed;
  43. fl::InputVariable * enemySpeed;
  44. fl::InputVariable * bankPresent;
  45. fl::InputVariable * castleWalls;
  46. fl::OutputVariable * threat;
  47. };
  48. class HeroMovementGoalEngineBase : public engineBase //in future - maybe derive from some (GoalEngineBase : public engineBase) class for handling non-movement goals with common utility for goal engines
  49. {
  50. public:
  51. HeroMovementGoalEngineBase();
  52. protected:
  53. void setSharedFuzzyVariables(Goals::AbstractGoal & goal);
  54. fl::InputVariable * strengthRatio;
  55. fl::InputVariable * heroStrength;
  56. fl::InputVariable * turnDistance;
  57. fl::InputVariable * missionImportance;
  58. fl::OutputVariable * value;
  59. private:
  60. float calculateTurnDistanceInputValue(const Goals::AbstractGoal & goal) const;
  61. };
  62. class VisitTileEngine : public HeroMovementGoalEngineBase
  63. {
  64. public:
  65. VisitTileEngine();
  66. float evaluate(Goals::VisitTile & goal);
  67. };
  68. class VisitObjEngine : public HeroMovementGoalEngineBase
  69. {
  70. public:
  71. VisitObjEngine();
  72. float evaluate(Goals::VisitObj & goal);
  73. protected:
  74. fl::InputVariable * objectValue;
  75. };