Fuzzy.cpp 18 KB

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