1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

Fixed AI recklessly visting Utopia.

Made algorithm asctually working. Library fixes were needed.
This commit is contained in:
DjWarmonger 2012-03-03 11:39:54 +00:00
parent 998d8bf501
commit 1354351a40
2 changed files with 22 additions and 12 deletions

View File

@ -59,18 +59,25 @@ ui64 evaluateBankConfig (BankConfig * bc)
FuzzyHelper::FuzzyHelper()
{
bankInput = new fl::InputLVar("BankInput");
bankDanger = new fl::OutputLVar("BankDanger");
bankInput->addTerm(new fl::SingletonTerm ("SET"));
engine.addRuleBlock (&ruleBlock); //have to be added before the rules are parsed
engine.addInputLVar (bankInput);
for (int i = 0; i < 4; ++i)
try
{
bankDanger->addTerm(new fl::TriangularTerm ("Bank" + boost::lexical_cast<std::string>(i), 0, 1));
ruleBlock.addRule(new fl::MamdaniRule("if BankInput is SET then BankDanger is Bank" + boost::lexical_cast<std::string>(i), engine));
bankInput = new fl::InputLVar("BankInput");
bankDanger = new fl::OutputLVar("BankDanger");
bankInput->addTerm(new fl::SingletonTerm ("SET"));
engine.addRuleBlock (&ruleBlock); //have to be added before the rules are parsed
engine.addInputLVar (bankInput);
engine.addOutputLVar (bankDanger);
for (int i = 0; i < 4; ++i)
{
bankDanger->addTerm(new fl::TriangularTerm ("Bank" + boost::lexical_cast<std::string>(i), 0, 1));
ruleBlock.addRule(new fl::MamdaniRule("if BankInput is SET then BankDanger is Bank" + boost::lexical_cast<std::string>(i), engine));
}
}
catch (fl::FuzzyException fe)
{
tlog1 << fe.name() << ": " << fe.message() << '\n';
}
engine.addOutputLVar (bankDanger);
}
ui64 FuzzyHelper::estimateBankDanger (int ID)
@ -90,8 +97,8 @@ ui64 FuzzyHelper::estimateBankDanger (int ID)
bankDanger->term("Bank" + boost::lexical_cast<std::string>(i))->setMaximum(bankVal * 1.5f);
}
int averageValue = (evaluateBankConfig (VLC->objh->banksInfo[ID][0]) + evaluateBankConfig (VLC->objh->banksInfo[ID][3])) * 0.5;
dynamic_cast<fl::SingletonTerm*>(bankInput->term("SET"))->setValue(1);
bankInput->setInput (0);
dynamic_cast<fl::SingletonTerm*>(bankInput->term("SET"))->setValue(0.5);
bankInput->setInput (0.5);
engine.process();
val = bankDanger->output().defuzzify(); //some expected value of this bank
}
@ -99,6 +106,7 @@ ui64 FuzzyHelper::estimateBankDanger (int ID)
{
tlog1 << fe.name() << ": " << fe.message() << '\n';
}
break;
case 1: //rare case - Pyramid
val = evaluateBankConfig (VLC->objh->banksInfo[ID][0]);
break;

View File

@ -68,6 +68,7 @@ namespace Obj
CREATURE_BANK = 16,
CREATURE_GENERATOR1 = 17,
DERELICT_SHIP = 24,
DRAGON_UTOPIA = 25,
GARRISON = 33,
MONOLITH1 = 43,
MONOLITH2 = 44,
@ -324,6 +325,7 @@ ui64 evaluateDanger(const CGObjectInstance *obj)
}
case Obj::CRYPT: //crypt
case Obj::CREATURE_BANK: //crebank
case Obj::DRAGON_UTOPIA:
case Obj::SHIPWRECK: //shipwreck
case Obj::DERELICT_SHIP: //derelict ship
case Obj::PYRAMID: