Fuzzy.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. #include "StdInc.h"
  2. #include "Fuzzy.h"
  3. #include <limits>
  4. #include "../../lib/mapObjects/MapObjects.h"
  5. #include "../../lib/mapObjects/CommonConstructors.h"
  6. #include "../../lib/CCreatureHandler.h"
  7. #include "../../lib/VCMI_Lib.h"
  8. #include "../../CCallback.h"
  9. #include "VCAI.h"
  10. /*
  11. * Fuzzy.cpp, part of VCMI engine
  12. *
  13. * Authors: listed in file AUTHORS in main folder
  14. *
  15. * License: GNU General Public License v2.0 or later
  16. * Full text of license available in license.txt file, in main folder
  17. *
  18. */
  19. #define MIN_AI_STRENGHT (0.5f) //lower when combat AI gets smarter
  20. #define UNGUARDED_OBJECT (100.0f) //we consider unguarded objects 100 times weaker than us
  21. struct BankConfig;
  22. class IObjectInfo;
  23. class CBankInfo;
  24. class Engine;
  25. class InputVariable;
  26. class CGTownInstance;
  27. using namespace vstd;
  28. //using namespace Goals;
  29. FuzzyHelper *fh;
  30. extern boost::thread_specific_ptr<CCallback> cb;
  31. extern boost::thread_specific_ptr<VCAI> ai;
  32. engineBase::engineBase()
  33. {
  34. engine.addRuleBlock(&rules);
  35. }
  36. void engineBase::configure()
  37. {
  38. engine.configure("Minimum", "Maximum", "Minimum", "AlgebraicSum", "Centroid");
  39. logAi->infoStream() << engine.toString();
  40. }
  41. void engineBase::addRule(const std::string &txt)
  42. {
  43. rules.addRule(fl::Rule::parse(txt, &engine));
  44. }
  45. struct armyStructure
  46. {
  47. float walkers, shooters, flyers;
  48. ui32 maxSpeed;
  49. };
  50. armyStructure evaluateArmyStructure (const CArmedInstance * army)
  51. {
  52. ui64 totalStrenght = army->getArmyStrength();
  53. double walkersStrenght = 0;
  54. double flyersStrenght = 0;
  55. double shootersStrenght = 0;
  56. ui32 maxSpeed = 0;
  57. for(auto s : army->Slots())
  58. {
  59. bool walker = true;
  60. if (s.second->type->hasBonusOfType(Bonus::SHOOTER))
  61. {
  62. shootersStrenght += s.second->getPower();
  63. walker = false;
  64. }
  65. if (s.second->type->hasBonusOfType(Bonus::FLYING))
  66. {
  67. flyersStrenght += s.second->getPower();
  68. walker = false;
  69. }
  70. if (walker)
  71. walkersStrenght += s.second->getPower();
  72. amax (maxSpeed, s.second->type->valOfBonuses(Bonus::STACKS_SPEED));
  73. }
  74. armyStructure as;
  75. as.walkers = walkersStrenght / totalStrenght;
  76. as.shooters = shootersStrenght / totalStrenght;
  77. as.flyers = flyersStrenght / totalStrenght;
  78. as.maxSpeed = maxSpeed;
  79. assert(as.walkers || as.flyers || as.shooters);
  80. return as;
  81. }
  82. FuzzyHelper::FuzzyHelper()
  83. {
  84. initTacticalAdvantage();
  85. ta.configure();
  86. initVisitTile();
  87. vt.configure();
  88. }
  89. void FuzzyHelper::initTacticalAdvantage()
  90. {
  91. try
  92. {
  93. ta.ourShooters = new fl::InputVariable("OurShooters");
  94. ta.ourWalkers = new fl::InputVariable("OurWalkers");
  95. ta.ourFlyers = new fl::InputVariable("OurFlyers");
  96. ta.enemyShooters = new fl::InputVariable("EnemyShooters");
  97. ta.enemyWalkers = new fl::InputVariable("EnemyWalkers");
  98. ta.enemyFlyers = new fl::InputVariable("EnemyFlyers");
  99. //Tactical advantage calculation
  100. std::vector<fl::InputVariable*> helper =
  101. {
  102. ta.ourShooters, ta.ourWalkers, ta.ourFlyers, ta.enemyShooters, ta.enemyWalkers, ta.enemyFlyers
  103. };
  104. for (auto val : helper)
  105. {
  106. ta.engine.addInputVariable(val);
  107. val->addTerm(new fl::Ramp("FEW", 0.6, 0.0));
  108. val->addTerm(new fl::Ramp("MANY", 0.4, 1));
  109. val->setRange(0.0, 1.0);
  110. }
  111. ta.ourSpeed = new fl::InputVariable("OurSpeed");
  112. ta.enemySpeed = new fl::InputVariable("EnemySpeed");
  113. helper = {ta.ourSpeed, ta.enemySpeed};
  114. for (auto val : helper)
  115. {
  116. ta.engine.addInputVariable(val);
  117. val->addTerm(new fl::Ramp("LOW", 6.5, 3));
  118. val->addTerm(new fl::Triangle("MEDIUM", 5.5, 10.5));
  119. val->addTerm(new fl::Ramp("HIGH", 8.5, 16));
  120. val->setRange(0, 25);
  121. }
  122. ta.castleWalls = new fl::InputVariable("CastleWalls");
  123. ta.engine.addInputVariable(ta.castleWalls);
  124. {
  125. fl::Rectangle* none = new fl::Rectangle("NONE", CGTownInstance::NONE, CGTownInstance::NONE + (CGTownInstance::FORT - CGTownInstance::NONE) * 0.5f);
  126. ta.castleWalls->addTerm(none);
  127. fl::Trapezoid* medium = new fl::Trapezoid("MEDIUM", (CGTownInstance::FORT - CGTownInstance::NONE) * 0.5f, CGTownInstance::FORT,
  128. CGTownInstance::CITADEL, CGTownInstance::CITADEL + (CGTownInstance::CASTLE - CGTownInstance::CITADEL) * 0.5f);
  129. ta.castleWalls->addTerm(medium);
  130. fl::Ramp* high = new fl::Ramp("HIGH", CGTownInstance::CITADEL - 0.1, CGTownInstance::CASTLE);
  131. ta.castleWalls->addTerm(high);
  132. ta.castleWalls->setRange(CGTownInstance::NONE, CGTownInstance::CASTLE);
  133. }
  134. ta.bankPresent = new fl::InputVariable("Bank");
  135. ta.engine.addInputVariable(ta.bankPresent);
  136. {
  137. fl::Rectangle* termFalse = new fl::Rectangle("FALSE", 0.0, 0.5f);
  138. ta.bankPresent->addTerm(termFalse);
  139. fl::Rectangle* termTrue = new fl::Rectangle("TRUE", 0.5f, 1);
  140. ta.bankPresent->addTerm(termTrue);
  141. ta.bankPresent->setRange(0, 1);
  142. }
  143. ta.threat = new fl::OutputVariable("Threat");
  144. ta.engine.addOutputVariable(ta.threat);
  145. ta.threat->addTerm(new fl::Ramp("LOW", 1, MIN_AI_STRENGHT));
  146. ta.threat->addTerm(new fl::Triangle("MEDIUM", 0.8, 1.2));
  147. ta.threat->addTerm(new fl::Ramp("HIGH", 1, 1.5));
  148. ta.threat->setRange(MIN_AI_STRENGHT, 1.5);
  149. ta.addRule("if OurShooters is MANY and EnemySpeed is LOW then Threat is LOW");
  150. ta.addRule("if OurShooters is MANY and EnemyShooters is FEW then Threat is LOW");
  151. ta.addRule("if OurSpeed is LOW and EnemyShooters is MANY then Threat is HIGH");
  152. ta.addRule("if OurSpeed is HIGH and EnemyShooters is MANY then Threat is LOW");
  153. ta.addRule("if OurWalkers is FEW and EnemyShooters is MANY then Threat is somewhat LOW");
  154. ta.addRule("if OurShooters is MANY and EnemySpeed is HIGH then Threat is somewhat HIGH");
  155. //just to cover all cases
  156. ta.addRule("if OurShooters is FEW and EnemySpeed is HIGH then Threat is MEDIUM");
  157. ta.addRule("if EnemySpeed is MEDIUM then Threat is MEDIUM");
  158. ta.addRule("if EnemySpeed is LOW and OurShooters is FEW then Threat is MEDIUM");
  159. ta.addRule("if Bank is TRUE and OurShooters is MANY then Threat is somewhat HIGH");
  160. ta.addRule("if Bank is TRUE and EnemyShooters is MANY then Threat is LOW");
  161. ta.addRule("if CastleWalls is HIGH and OurWalkers is MANY then Threat is very HIGH");
  162. ta.addRule("if CastleWalls is HIGH and OurFlyers is MANY and OurShooters is MANY then Threat is MEDIUM");
  163. ta.addRule("if CastleWalls is MEDIUM and OurShooters is MANY and EnemyWalkers is MANY then Threat is LOW");
  164. }
  165. catch (fl::Exception & pe)
  166. {
  167. logAi->errorStream() << "initTacticalAdvantage " << ": " << pe.getWhat();
  168. }
  169. }
  170. ui64 FuzzyHelper::estimateBankDanger (const CBank * bank)
  171. {
  172. //this one is not fuzzy anymore, just calculate weighted average
  173. auto objectInfo = VLC->objtypeh->getHandlerFor(bank->ID, bank->subID)->getObjectInfo(bank->appearance);
  174. CBankInfo * bankInfo = dynamic_cast<CBankInfo *> (objectInfo.get());
  175. ui64 totalStrength = 0;
  176. ui8 totalChance = 0;
  177. for (auto config : bankInfo->getPossibleGuards())
  178. {
  179. totalStrength += config.second.totalStrength * config.first;
  180. totalChance += config.first;
  181. }
  182. return totalStrength / totalChance;
  183. }
  184. float FuzzyHelper::getTacticalAdvantage (const CArmedInstance *we, const CArmedInstance *enemy)
  185. {
  186. float output = 1;
  187. try
  188. {
  189. armyStructure ourStructure = evaluateArmyStructure(we);
  190. armyStructure enemyStructure = evaluateArmyStructure(enemy);
  191. ta.ourWalkers->setInputValue(ourStructure.walkers);
  192. ta.ourShooters->setInputValue(ourStructure.shooters);
  193. ta.ourFlyers->setInputValue(ourStructure.flyers);
  194. ta.ourSpeed->setInputValue(ourStructure.maxSpeed);
  195. ta.enemyWalkers->setInputValue(enemyStructure.walkers);
  196. ta.enemyShooters->setInputValue(enemyStructure.shooters);
  197. ta.enemyFlyers->setInputValue(enemyStructure.flyers);
  198. ta.enemySpeed->setInputValue(enemyStructure.maxSpeed);
  199. bool bank = dynamic_cast<const CBank*> (enemy);
  200. if (bank)
  201. ta.bankPresent->setInputValue(1);
  202. else
  203. ta.bankPresent->setInputValue(0);
  204. const CGTownInstance * fort = dynamic_cast<const CGTownInstance*> (enemy);
  205. if (fort)
  206. {
  207. ta.castleWalls->setInputValue(fort->fortLevel());
  208. }
  209. else
  210. ta.castleWalls->setInputValue(0);
  211. //engine.process(TACTICAL_ADVANTAGE);//TODO: Process only Tactical_Advantage
  212. ta.engine.process();
  213. output = ta.threat->getOutputValue();
  214. }
  215. catch (fl::Exception & fe)
  216. {
  217. logAi->errorStream() << "getTacticalAdvantage " << ": " << fe.getWhat();
  218. }
  219. if (output < 0 || (output != output))
  220. {
  221. fl::InputVariable* tab[] = {ta.bankPresent, ta.castleWalls, ta.ourWalkers, ta.ourShooters, ta.ourFlyers, ta.ourSpeed, ta.enemyWalkers, ta.enemyShooters, ta.enemyFlyers, ta.enemySpeed};
  222. std::string names[] = {"bankPresent", "castleWalls", "ourWalkers", "ourShooters", "ourFlyers", "ourSpeed", "enemyWalkers", "enemyShooters", "enemyFlyers", "enemySpeed" };
  223. std::stringstream log("Warning! Fuzzy engine doesn't cover this set of parameters: ");
  224. for (int i = 0; i < boost::size(tab); i++)
  225. log << names[i] << ": " << tab[i]->getInputValue() << " ";
  226. logAi->errorStream() << log.str();
  227. assert(false);
  228. }
  229. return output;
  230. }
  231. FuzzyHelper::TacticalAdvantage::~TacticalAdvantage()
  232. {
  233. //TODO: smart pointers?
  234. delete ourWalkers;
  235. delete ourShooters;
  236. delete ourFlyers;
  237. delete enemyWalkers;
  238. delete enemyShooters;
  239. delete enemyFlyers;
  240. delete ourSpeed;
  241. delete enemySpeed;
  242. delete bankPresent;
  243. delete castleWalls;
  244. delete threat;
  245. }
  246. //shared_ptr<AbstractGoal> chooseSolution (std::vector<shared_ptr<AbstractGoal>> & vec)
  247. Goals::TSubgoal FuzzyHelper::chooseSolution (Goals::TGoalVec vec)
  248. {
  249. if (vec.empty()) //no possibilities found
  250. return sptr(Goals::Invalid());
  251. cachedSectorMaps.clear();
  252. //a trick to switch between heroes less often - calculatePaths is costly
  253. auto sortByHeroes = [](const Goals::TSubgoal & lhs, const Goals::TSubgoal & rhs) -> bool
  254. {
  255. return lhs->hero.h < rhs->hero.h;
  256. };
  257. boost::sort (vec, sortByHeroes);
  258. for (auto g : vec)
  259. {
  260. setPriority(g);
  261. }
  262. auto compareGoals = [](const Goals::TSubgoal & lhs, const Goals::TSubgoal & rhs) -> bool
  263. {
  264. return lhs->priority < rhs->priority;
  265. };
  266. boost::sort (vec, compareGoals);
  267. return vec.back();
  268. }
  269. float FuzzyHelper::evaluate (Goals::Explore & g)
  270. {
  271. return 1;
  272. }
  273. float FuzzyHelper::evaluate (Goals::RecruitHero & g)
  274. {
  275. return 1; //just try to recruit hero as one of options
  276. }
  277. FuzzyHelper::EvalVisitTile::~EvalVisitTile()
  278. {
  279. delete strengthRatio;
  280. delete heroStrength;
  281. delete turnDistance;
  282. delete missionImportance;
  283. }
  284. void FuzzyHelper::initVisitTile()
  285. {
  286. try
  287. {
  288. vt.strengthRatio = new fl::InputVariable("strengthRatio"); //hero must be strong enough to defeat guards
  289. vt.heroStrength = new fl::InputVariable("heroStrength"); //we want to use weakest possible hero
  290. vt.turnDistance = new fl::InputVariable("turnDistance"); //we want to use hero who is near
  291. vt.missionImportance = new fl::InputVariable("lockedMissionImportance"); //we may want to preempt hero with low-priority mission
  292. vt.value = new fl::OutputVariable("Value");
  293. vt.value->setMinimum(0);
  294. vt.value->setMaximum(5);
  295. std::vector<fl::InputVariable*> helper = {vt.strengthRatio, vt.heroStrength, vt.turnDistance, vt.missionImportance};
  296. for (auto val : helper)
  297. {
  298. vt.engine.addInputVariable(val);
  299. }
  300. vt.engine.addOutputVariable(vt.value);
  301. vt.strengthRatio->addTerm(new fl::Ramp("LOW", SAFE_ATTACK_CONSTANT, 0));
  302. vt.strengthRatio->addTerm(new fl::Ramp("HIGH", SAFE_ATTACK_CONSTANT, SAFE_ATTACK_CONSTANT * 3));
  303. vt.strengthRatio->setRange(0, SAFE_ATTACK_CONSTANT * 3 );
  304. //strength compared to our main hero
  305. vt.heroStrength->addTerm(new fl::Ramp("LOW", 0.2, 0));
  306. vt.heroStrength->addTerm(new fl::Triangle("MEDIUM", 0.2, 0.8));
  307. vt.heroStrength->addTerm(new fl::Ramp("HIGH", 0.5, 1));
  308. vt.heroStrength->setRange(0.0, 1.0);
  309. vt.turnDistance->addTerm(new fl::Ramp("SMALL", 0.5, 0));
  310. vt.turnDistance->addTerm(new fl::Triangle("MEDIUM", 0.1, 0.8));
  311. vt.turnDistance->addTerm(new fl::Ramp("LONG", 0.5, 3));
  312. vt.turnDistance->setRange(0.0, 3.0);
  313. vt.missionImportance->addTerm(new fl::Ramp("LOW", 2.5, 0));
  314. vt.missionImportance->addTerm(new fl::Triangle("MEDIUM", 2, 3));
  315. vt.missionImportance->addTerm(new fl::Ramp("HIGH", 2.5, 5));
  316. vt.missionImportance->setRange(0.0, 5.0);
  317. //an issue: in 99% cases this outputs center of mass (2.5) regardless of actual input :/
  318. //should be same as "mission Importance" to keep consistency
  319. vt.value->addTerm(new fl::Ramp("LOW", 2.5, 0));
  320. vt.value->addTerm(new fl::Triangle("MEDIUM", 2, 3)); //can't be center of mass :/
  321. vt.value->addTerm(new fl::Ramp("HIGH", 2.5, 5));
  322. vt.value->setRange(0.0,5.0);
  323. //use unarmed scouts if possible
  324. vt.addRule("if strengthRatio is HIGH and heroStrength is LOW then Value is very HIGH");
  325. //we may want to use secondary hero(es) rather than main hero
  326. vt.addRule("if strengthRatio is HIGH and heroStrength is MEDIUM then Value is somewhat HIGH");
  327. vt.addRule("if strengthRatio is HIGH and heroStrength is HIGH then Value is somewhat LOW");
  328. //don't assign targets to heroes who are too weak, but prefer targets of our main hero (in case we need to gather army)
  329. vt.addRule("if strengthRatio is LOW and heroStrength is LOW then Value is very LOW");
  330. //attempt to arm secondary heroes is not stupid
  331. vt.addRule("if strengthRatio is LOW and heroStrength is MEDIUM then Value is somewhat HIGH");
  332. vt.addRule("if strengthRatio is LOW and heroStrength is HIGH then Value is LOW");
  333. //do not cancel important goals
  334. vt.addRule("if lockedMissionImportance is HIGH then Value is very LOW");
  335. vt.addRule("if lockedMissionImportance is MEDIUM then Value is somewhat LOW");
  336. vt.addRule("if lockedMissionImportance is LOW then Value is HIGH");
  337. //pick nearby objects if it's easy, avoid long walks
  338. vt.addRule("if turnDistance is SMALL then Value is HIGH");
  339. vt.addRule("if turnDistance is MEDIUM then Value is MEDIUM");
  340. vt.addRule("if turnDistance is LONG then Value is LOW");
  341. }
  342. catch (fl::Exception & fe)
  343. {
  344. logAi->errorStream() << "visitTile " << ": " << fe.getWhat();
  345. }
  346. }
  347. float FuzzyHelper::evaluate (Goals::VisitTile & g)
  348. {
  349. //we assume that hero is already set and we want to choose most suitable one for the mission
  350. if (!g.hero)
  351. return 0;
  352. //assert(cb->isInTheMap(g.tile));
  353. float turns = 0;
  354. float distance = cb->getMovementCost(g.hero.h, g.tile);
  355. if (!distance) //we stand on that tile
  356. turns = 0;
  357. else
  358. {
  359. if (distance < g.hero->movement) //we can move there within one turn
  360. turns = (fl::scalar)distance / g.hero->movement;
  361. else
  362. turns = 1 + (fl::scalar)(distance - g.hero->movement) / g.hero->maxMovePoints(true); //bool on land?
  363. }
  364. float missionImportance = 0;
  365. if (vstd::contains(ai->lockedHeroes, g.hero))
  366. missionImportance = ai->lockedHeroes[g.hero]->priority;
  367. float strengthRatio = 10.0f; //we are much stronger than enemy
  368. ui64 danger = evaluateDanger (g.tile, g.hero.h);
  369. if (danger)
  370. strengthRatio = (fl::scalar)g.hero.h->getTotalStrength() / danger;
  371. try
  372. {
  373. vt.strengthRatio->setInputValue(strengthRatio);
  374. vt.heroStrength->setInputValue((fl::scalar)g.hero->getTotalStrength() / ai->primaryHero()->getTotalStrength());
  375. vt.turnDistance->setInputValue(turns);
  376. vt.missionImportance->setInputValue(missionImportance);
  377. vt.engine.process();
  378. //engine.process(VISIT_TILE); //TODO: Process only Visit_Tile
  379. g.priority = vt.value->getOutputValue();
  380. }
  381. catch (fl::Exception & fe)
  382. {
  383. logAi->errorStream() << "evaluate VisitTile " << ": " << fe.getWhat();
  384. }
  385. assert (g.priority >= 0);
  386. return g.priority;
  387. }
  388. float FuzzyHelper::evaluate (Goals::VisitHero & g)
  389. {
  390. auto obj = cb->getObj(ObjectInstanceID(g.objid)); //we assume for now that these goals are similar
  391. if (!obj)
  392. return -100; //hero died in the meantime
  393. //TODO: consider direct copy (constructor?)
  394. g.setpriority(Goals::VisitTile(obj->visitablePos()).sethero(g.hero).setisAbstract(g.isAbstract).accept(this));
  395. return g.priority;
  396. }
  397. float FuzzyHelper::evaluate (Goals::GatherArmy & g)
  398. {
  399. //the more army we need, the more important goal
  400. //the more army we lack, the less important goal
  401. float army = g.hero->getArmyStrength();
  402. return g.value / std::max(g.value - army, 1000.0f);
  403. }
  404. float FuzzyHelper::evaluate (Goals::ClearWayTo & g)
  405. {
  406. if (!g.hero.h)
  407. throw cannotFulfillGoalException("ClearWayTo called without hero!");
  408. int3 t = getCachedSectorMap(g.hero).firstTileToGet(g.hero, g.tile);
  409. if (t.valid())
  410. {
  411. if (isSafeToVisit(g.hero, t))
  412. {
  413. g.setpriority(Goals::VisitTile(g.tile).sethero(g.hero).setisAbstract(g.isAbstract).accept(this));
  414. }
  415. else
  416. {
  417. g.setpriority (Goals::GatherArmy(evaluateDanger(t, g.hero.h)*SAFE_ATTACK_CONSTANT).
  418. sethero(g.hero).setisAbstract(true).accept(this));
  419. }
  420. return g.priority;
  421. }
  422. else
  423. return -1;
  424. }
  425. float FuzzyHelper::evaluate (Goals::BuildThis & g)
  426. {
  427. return 1;
  428. }
  429. float FuzzyHelper::evaluate (Goals::DigAtTile & g)
  430. {
  431. return 0;
  432. }
  433. float FuzzyHelper::evaluate (Goals::CollectRes & g)
  434. {
  435. return 0;
  436. }
  437. float FuzzyHelper::evaluate (Goals::Build & g)
  438. {
  439. return 0;
  440. }
  441. float FuzzyHelper::evaluate (Goals::Invalid & g)
  442. {
  443. return -1e10;
  444. }
  445. float FuzzyHelper::evaluate (Goals::AbstractGoal & g)
  446. {
  447. logAi->warnStream() << boost::format("Cannot evaluate goal %s") % g.name();
  448. return g.priority;
  449. }
  450. void FuzzyHelper::setPriority (Goals::TSubgoal & g)
  451. {
  452. g->setpriority(g->accept(this)); //this enforces returned value is set
  453. }
  454. SectorMap& FuzzyHelper::getCachedSectorMap(HeroPtr h)
  455. {
  456. auto it = cachedSectorMaps.find(h);
  457. if (it != cachedSectorMaps.end())
  458. return it->second;
  459. else
  460. {
  461. cachedSectorMaps.insert (std::make_pair(h, SectorMap(h)));
  462. return cachedSectorMaps[h];
  463. }
  464. }