Fuzzy.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef NAN
  2. static const unsigned long __nan[2] = {0xffffffff, 0x7fffffff};
  3. #define NAN (*(const float *) __nan)
  4. #endif
  5. #ifdef _MSC_VER
  6. #ifndef INFINITY
  7. union MSVC_FL
  8. {
  9. unsigned __int8 Bytes[4];
  10. float Value;
  11. };
  12. static union MSVC_FL INFINITY_HACK = {{0x00, 0x00, 0x80, 0x7F}};
  13. #define INFINITY (INFINITY_HACK.Value)
  14. #endif
  15. #endif
  16. #include "..\FuzzyLite\FuzzyLite.h"
  17. /*
  18. * Fuzzy.h, part of VCMI engine
  19. *
  20. * Authors: listed in file AUTHORS in main folder
  21. *
  22. * License: GNU General Public License v2.0 or later
  23. * Full text of license available in license.txt file, in main folder
  24. *
  25. */
  26. class VCAI;
  27. class CArmedInstance;
  28. template <typename T> bool isinf (T val)
  29. {
  30. return val == INFINITY || val == -INFINITY;
  31. }
  32. class FuzzyHelper
  33. {
  34. friend class VCAI;
  35. fl::FuzzyEngine engine;
  36. fl::InputLVar* bankInput;
  37. fl::OutputLVar* bankDanger;
  38. fl::RuleBlock bankBlock;
  39. fl::InputLVar * ourWalkers, * ourShooters, * ourFlyers, * enemyWalkers, * enemyShooters, * enemyFlyers;
  40. fl::InputLVar * ourSpeed, * enemySpeed;
  41. fl::InputLVar * bankPresent;
  42. fl::InputLVar * castleWalls;
  43. fl::OutputLVar * threat;
  44. fl::RuleBlock tacticalAdvantage;
  45. public:
  46. enum RuleBlocks {BANK_DANGER, TACTICAL_ADVANTAGE};
  47. FuzzyHelper();
  48. void initBank();
  49. void initTacticalAdvantage();
  50. ui64 estimateBankDanger (int ID);
  51. float getTacticalAdvantage (const CArmedInstance *we, const CArmedInstance *enemy); //returns factor how many times enemy is stronger than us
  52. };