Fuzzy.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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 boost::assign;
  26. using namespace vstd;
  27. //using namespace Goals;
  28. FuzzyHelper *fh;
  29. extern boost::thread_specific_ptr<CCallback> cb;
  30. extern boost::thread_specific_ptr<VCAI> ai;
  31. struct armyStructure
  32. {
  33. float walkers, shooters, flyers;
  34. ui32 maxSpeed;
  35. };
  36. armyStructure evaluateArmyStructure (const CArmedInstance * army)
  37. {
  38. ui64 totalStrenght = army->getArmyStrength();
  39. double walkersStrenght = 0;
  40. double flyersStrenght = 0;
  41. double shootersStrenght = 0;
  42. ui32 maxSpeed = 0;
  43. for(auto s : army->Slots())
  44. {
  45. bool walker = true;
  46. if (s.second->type->hasBonusOfType(Bonus::SHOOTER))
  47. {
  48. shootersStrenght += s.second->getPower();
  49. walker = false;
  50. }
  51. if (s.second->type->hasBonusOfType(Bonus::FLYING))
  52. {
  53. flyersStrenght += s.second->getPower();
  54. walker = false;
  55. }
  56. if (walker)
  57. walkersStrenght += s.second->getPower();
  58. amax (maxSpeed, s.second->type->valOfBonuses(Bonus::STACKS_SPEED));
  59. }
  60. armyStructure as;
  61. as.walkers = walkersStrenght / totalStrenght;
  62. as.shooters = shootersStrenght / totalStrenght;
  63. as.flyers = flyersStrenght / totalStrenght;
  64. as.maxSpeed = maxSpeed;
  65. return as;
  66. }
  67. FuzzyHelper::FuzzyHelper()
  68. {
  69. engine.hedgeSet().add(new fl::HedgeSomewhat());
  70. engine.hedgeSet().add(new fl::HedgeVery());
  71. engine.fuzzyOperator().setAggregation(new fl::FuzzyOrSum()); //to consider all cases simultaneously
  72. initBank();
  73. initTacticalAdvantage();
  74. initVisitTile();
  75. logAi->infoStream() << engine.toString();
  76. }
  77. void FuzzyHelper::initBank()
  78. {
  79. try
  80. {
  81. //Trivial bank estimation
  82. bankInput = new fl::InputLVar("BankInput");
  83. bankDanger = new fl::OutputLVar("BankDanger");
  84. bankInput->addTerm(new fl::SingletonTerm ("SET", 0.5));
  85. engine.addInputLVar (bankInput);
  86. engine.addOutputLVar (bankDanger);
  87. engine.addRuleBlock (&bankBlock);
  88. for (int i = 0; i < 4; ++i)
  89. {
  90. bankDanger->addTerm(new fl::TriangularTerm ("Bank" + boost::lexical_cast<std::string>(i), 0, 1));
  91. bankBlock.addRule(new fl::MamdaniRule("if BankInput is SET then BankDanger is Bank" + boost::lexical_cast<std::string>(i), engine));
  92. }
  93. }
  94. catch (fl::FuzzyException & fe)
  95. {
  96. logAi->errorStream() << "initBank " << fe.name() << ": " << fe.message();
  97. }
  98. }
  99. void FuzzyHelper::initTacticalAdvantage()
  100. {
  101. try
  102. {
  103. //Tactical advantage calculation
  104. std::vector<fl::InputLVar*> helper;
  105. ta.ourShooters = new fl::InputLVar("OurShooters");
  106. ta.ourWalkers = new fl::InputLVar("OurWalkers");
  107. ta.ourFlyers = new fl::InputLVar("OurFlyers");
  108. ta.enemyShooters = new fl::InputLVar("EnemyShooters");
  109. ta.enemyWalkers = new fl::InputLVar("EnemyWalkers");
  110. ta.enemyFlyers = new fl::InputLVar("EnemyFlyers");
  111. helper += ta.ourShooters, ta.ourWalkers, ta.ourFlyers, ta.enemyShooters, ta.enemyWalkers, ta.enemyFlyers;
  112. for (auto val : helper)
  113. {
  114. engine.addInputLVar(val);
  115. val->addTerm (new fl::ShoulderTerm("FEW", 0, 0.6, true));
  116. val->addTerm (new fl::ShoulderTerm("MANY", 0.4, 1, false));
  117. }
  118. helper.clear();
  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. std::vector<fl::InputLVar*> helper;
  286. vt.strengthRatio = new fl::InputLVar("strengthRatio"); //hero must be strong enough to defeat guards
  287. vt.heroStrength = new fl::InputLVar("heroStrength"); //we want to use weakest possible hero
  288. vt.turnDistance = new fl::InputLVar("turnDistance"); //we want to use hero who is near
  289. vt.missionImportance = new fl::InputLVar("lockedMissionImportance"); //we may want to preempt hero with low-priority mission
  290. vt.value = new fl::OutputLVar("Value");
  291. helper += vt.strengthRatio, vt.heroStrength, vt.turnDistance, vt.missionImportance;
  292. for (auto val : helper)
  293. {
  294. engine.addInputLVar(val);
  295. }
  296. engine.addOutputLVar (vt.value);
  297. vt.strengthRatio->addTerm (new fl::ShoulderTerm("LOW", 0, SAFE_ATTACK_CONSTANT, true));
  298. vt.strengthRatio->addTerm (new fl::ShoulderTerm("HIGH", SAFE_ATTACK_CONSTANT, SAFE_ATTACK_CONSTANT * 3, false));
  299. //strength compared to our main hero
  300. vt.heroStrength->addTerm (new fl::ShoulderTerm("LOW", 0, 0.2, true));
  301. vt.heroStrength->addTerm (new fl::TriangularTerm("MEDIUM", 0.2, 0.8));
  302. vt.heroStrength->addTerm (new fl::ShoulderTerm("HIGH", 0.5, 1, false));
  303. vt.turnDistance->addTerm (new fl::ShoulderTerm("SMALL", 0, 0.5, true));
  304. vt.turnDistance->addTerm (new fl::TriangularTerm("MEDIUM", 0.1, 0.8));
  305. vt.turnDistance->addTerm (new fl::ShoulderTerm("LONG", 0.5, 3, false));
  306. vt.missionImportance->addTerm (new fl::ShoulderTerm("LOW", 0, 2.5, true));
  307. vt.missionImportance->addTerm (new fl::TriangularTerm("MEDIUM", 2, 3));
  308. vt.missionImportance->addTerm (new fl::ShoulderTerm("HIGH", 2.5, 5, false));
  309. //an issue: in 99% cases this outputs center of mass (2.5) regardless of actual input :/
  310. //should be same as "mission Importance" to keep consistency
  311. vt.value->addTerm (new fl::ShoulderTerm("LOW", 0, 2.5, true));
  312. vt.value->addTerm (new fl::TriangularTerm("MEDIUM", 2, 3)); //can't be center of mass :/
  313. vt.value->addTerm (new fl::ShoulderTerm("HIGH", 2.5, 5, false));
  314. engine.addRuleBlock (&vt.rules);
  315. //use unarmed scouts if possible
  316. vt.rules.addRule (new fl::MamdaniRule("if strengthRatio is HIGH and heroStrength is LOW then Value is very HIGH", engine));
  317. //we may want to use secondary hero(es) rather than main hero
  318. vt.rules.addRule (new fl::MamdaniRule("if strengthRatio is HIGH and heroStrength is MEDIUM then Value is somewhat HIGH", engine));
  319. vt.rules.addRule (new fl::MamdaniRule("if strengthRatio is HIGH and heroStrength is HIGH then Value is somewhat LOW", engine));
  320. //don't assign targets to heroes who are too weak, but prefer targets of our main hero (in case we need to gather army)
  321. vt.rules.addRule (new fl::MamdaniRule("if strengthRatio is LOW and heroStrength is LOW then Value is very LOW", engine));
  322. //attempt to arm secondary heroes is not stupid
  323. vt.rules.addRule (new fl::MamdaniRule("if strengthRatio is LOW and heroStrength is MEDIUM then Value is somewhat HIGH", engine));
  324. vt.rules.addRule (new fl::MamdaniRule("if strengthRatio is LOW and heroStrength is HIGH then Value is LOW", engine));
  325. //do not cancel important goals
  326. vt.rules.addRule (new fl::MamdaniRule("if lockedMissionImportance is HIGH then Value is very LOW", engine));
  327. vt.rules.addRule (new fl::MamdaniRule("if lockedMissionImportance is MEDIUM then Value is somewhat LOW", engine));
  328. vt.rules.addRule (new fl::MamdaniRule("if lockedMissionImportance is LOW then Value is HIGH", engine));
  329. //pick nearby objects if it's easy, avoid long walks
  330. vt.rules.addRule (new fl::MamdaniRule("if turnDistance is SMALL then Value is HIGH", engine));
  331. vt.rules.addRule (new fl::MamdaniRule("if turnDistance is MEDIUM then Value is MEDIUM", engine));
  332. vt.rules.addRule (new fl::MamdaniRule("if turnDistance is LONG then Value is LOW", engine));
  333. }
  334. catch (fl::FuzzyException & fe)
  335. {
  336. logAi->errorStream() << "visitTile " << fe.name() << ": " << fe.message();
  337. }
  338. }
  339. float FuzzyHelper::evaluate (Goals::VisitTile & g)
  340. {
  341. //we assume that hero is already set and we want to choose most suitable one for the mission
  342. if (!g.hero)
  343. return 0;
  344. //assert(cb->isInTheMap(g.tile));
  345. cb->setSelection (g.hero.h);
  346. float turns = 0;
  347. float distance = cb->getMovementCost(g.hero.h, g.tile);
  348. if (!distance) //we stand on that tile
  349. turns = 0;
  350. else
  351. {
  352. if (distance < g.hero->movement) //we can move there within one turn
  353. turns = (fl::flScalar)distance /g.hero->movement;
  354. else
  355. turns = 1 + (fl::flScalar)(distance - g.hero->movement)/g.hero->maxMovePoints(true); //bool on land?
  356. }
  357. float missionImportance = 0;
  358. if (vstd::contains(ai->lockedHeroes, g.hero))
  359. missionImportance = ai->lockedHeroes[g.hero]->priority;
  360. float strengthRatio = 10.0f; //we are much stronger than enemy
  361. ui64 danger = evaluateDanger (g.tile, g.hero.h);
  362. if (danger)
  363. strengthRatio = (fl::flScalar)g.hero.h->getTotalStrength() / danger;
  364. try
  365. {
  366. vt.strengthRatio->setInput (strengthRatio);
  367. vt.heroStrength->setInput ((fl::flScalar)g.hero->getTotalStrength()/ai->primaryHero()->getTotalStrength());
  368. vt.turnDistance->setInput (turns);
  369. vt.missionImportance->setInput (missionImportance);
  370. //engine.process();
  371. engine.process (VISIT_TILE);
  372. g.priority = vt.value->output().defuzzify();
  373. }
  374. catch (fl::FuzzyException & fe)
  375. {
  376. logAi->errorStream() << "evaluate VisitTile " << fe.name() << ": " << fe.message();
  377. }
  378. return g.priority;
  379. }
  380. float FuzzyHelper::evaluate (Goals::VisitHero & g)
  381. {
  382. auto obj = cb->getObj(ObjectInstanceID(g.objid)); //we assume for now that these goals are similar
  383. if (!obj)
  384. return -100; //hero died in the meantime
  385. //TODO: consider direct copy (constructor?)
  386. g.setpriority(Goals::VisitTile(obj->visitablePos()).sethero(g.hero).setisAbstract(g.isAbstract).accept(this));
  387. return g.priority;
  388. }
  389. float FuzzyHelper::evaluate (Goals::GatherArmy & g)
  390. {
  391. //the more army we need, the more important goal
  392. //the more army we lack, the less important goal
  393. float army = g.hero->getArmyStrength();
  394. return g.value / std::max(g.value - army, 1000.0f);
  395. }
  396. float FuzzyHelper::evaluate (Goals::ClearWayTo & g)
  397. {
  398. if (!g.hero.h)
  399. throw cannotFulfillGoalException("ClearWayTo called without hero!");
  400. SectorMap sm(g.hero);
  401. int3 t = sm.firstTileToGet(g.hero, g.tile);
  402. if (t.valid())
  403. {
  404. if (isSafeToVisit(g.hero, t))
  405. {
  406. g.setpriority(Goals::VisitTile(g.tile).sethero(g.hero).setisAbstract(g.isAbstract).accept(this));
  407. }
  408. else
  409. {
  410. g.setpriority (Goals::GatherArmy(evaluateDanger(t, g.hero.h)*SAFE_ATTACK_CONSTANT).
  411. sethero(g.hero).setisAbstract(true).accept(this));
  412. }
  413. return g.priority;
  414. }
  415. else
  416. return -1;
  417. }
  418. float FuzzyHelper::evaluate (Goals::BuildThis & g)
  419. {
  420. return 1;
  421. }
  422. float FuzzyHelper::evaluate (Goals::DigAtTile & g)
  423. {
  424. return 0;
  425. }
  426. float FuzzyHelper::evaluate (Goals::CollectRes & g)
  427. {
  428. return 0;
  429. }
  430. float FuzzyHelper::evaluate (Goals::Build & g)
  431. {
  432. return 0;
  433. }
  434. float FuzzyHelper::evaluate (Goals::Invalid & g)
  435. {
  436. return -1e10;
  437. }
  438. float FuzzyHelper::evaluate (Goals::AbstractGoal & g)
  439. {
  440. logAi->warnStream() << boost::format("Cannot evaluate goal %s") % g.name();
  441. return g.priority;
  442. }
  443. void FuzzyHelper::setPriority (Goals::TSubgoal & g)
  444. {
  445. g->setpriority(g->accept(this)); //this enforces returned value is set
  446. }