mirror of
https://github.com/vcmi/vcmi.git
synced 2025-04-23 12:08:45 +02:00
Banks won't use fuzzy engine at all, only center of mass.
This commit is contained in:
parent
7adb0fd600
commit
a1e42caddd
@ -23,6 +23,8 @@
|
|||||||
#define UNGUARDED_OBJECT (100.0f) //we consider unguarded objects 100 times weaker than us
|
#define UNGUARDED_OBJECT (100.0f) //we consider unguarded objects 100 times weaker than us
|
||||||
|
|
||||||
struct BankConfig;
|
struct BankConfig;
|
||||||
|
class IObjectInfo;
|
||||||
|
class CBankInfo;
|
||||||
class Engine;
|
class Engine;
|
||||||
class InputVariable;
|
class InputVariable;
|
||||||
class CGTownInstance;
|
class CGTownInstance;
|
||||||
@ -77,7 +79,6 @@ armyStructure evaluateArmyStructure (const CArmedInstance * army)
|
|||||||
|
|
||||||
FuzzyHelper::FuzzyHelper()
|
FuzzyHelper::FuzzyHelper()
|
||||||
{
|
{
|
||||||
initBank();
|
|
||||||
initTacticalAdvantage();
|
initTacticalAdvantage();
|
||||||
initVisitTile();
|
initVisitTile();
|
||||||
|
|
||||||
@ -87,38 +88,6 @@ FuzzyHelper::FuzzyHelper()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void FuzzyHelper::initBank()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
|
|
||||||
//Trivial bank estimation
|
|
||||||
bankInput = new fl::InputVariable("BankInput");
|
|
||||||
//SingletonTerm (4.0) is a Rectangle (5.0) within 5*Macheps
|
|
||||||
bankInput->addTerm(new fl::Rectangle("SET", 0.5 - 5 * fl::fuzzylite::macheps(),
|
|
||||||
0.5 + 5 * fl::fuzzylite::macheps()));
|
|
||||||
|
|
||||||
bankInput->setRange(0.5 - 5 * fl::fuzzylite::macheps(), 0.5 + 5 * fl::fuzzylite::macheps());
|
|
||||||
|
|
||||||
bankDanger = new fl::OutputVariable("BankDanger");
|
|
||||||
|
|
||||||
engine.addInputVariable(bankInput);
|
|
||||||
engine.addOutputVariable(bankDanger);
|
|
||||||
engine.addRuleBlock(&bankBlock);
|
|
||||||
for (int i = 0; i < 4; ++i)
|
|
||||||
{
|
|
||||||
bankDanger->addTerm(new fl::Triangle("Bank" + boost::lexical_cast<std::string>(i), 0, 1));
|
|
||||||
bankBlock.addRule(fl::Rule::parse("if BankInput is SET then BankDanger is Bank" + boost::lexical_cast<std::string>(i), &engine));
|
|
||||||
}
|
|
||||||
bankDanger->setRange(0.0, 1.0);
|
|
||||||
}
|
|
||||||
catch (fl::Exception & fe)
|
|
||||||
{
|
|
||||||
logAi->errorStream() << "initBank : " << fe.getWhat();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FuzzyHelper::initTacticalAdvantage()
|
void FuzzyHelper::initTacticalAdvantage()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -223,46 +192,20 @@ void FuzzyHelper::initTacticalAdvantage()
|
|||||||
|
|
||||||
ui64 FuzzyHelper::estimateBankDanger (const CBank * bank)
|
ui64 FuzzyHelper::estimateBankDanger (const CBank * bank)
|
||||||
{
|
{
|
||||||
auto info = VLC->objtypeh->getHandlerFor(bank->ID, bank->subID)->getObjectInfo(bank->appearance);
|
//this one is not fuzzy anymore, just calculate weighted average
|
||||||
|
|
||||||
ui64 val = std::numeric_limits<ui64>::max();
|
auto objectInfo = VLC->objtypeh->getHandlerFor(bank->ID, bank->subID)->getObjectInfo(bank->appearance);
|
||||||
try
|
|
||||||
{
|
|
||||||
fl::Triangle* bank0 = dynamic_cast<fl::Triangle*> (bankDanger->getTerm("Bank0"));
|
|
||||||
fl::Triangle* bank1 = dynamic_cast<fl::Triangle*> (bankDanger->getTerm("Bank1"));
|
|
||||||
if (bank0 && bank1)
|
|
||||||
{
|
|
||||||
bank0->setVertexA(info->minGuards().totalStrength * 0.5f);
|
|
||||||
bank0->setVertexC(info->minGuards().totalStrength * 1.5f);
|
|
||||||
bank1->setVertexA(info->maxGuards().totalStrength * 0.5f);
|
|
||||||
bank1->setVertexC(info->maxGuards().totalStrength * 1.5f);
|
|
||||||
|
|
||||||
fl::scalar min = std::min({bank0->getVertexA(), bank0->getVertexC(), bank1->getVertexA(), bank1->getVertexC()});
|
CBankInfo * bankInfo = dynamic_cast<CBankInfo *> (objectInfo.get());
|
||||||
fl::scalar max = std::max({bank0->getVertexA(), bank0->getVertexC(), bank1->getVertexA(), bank1->getVertexC()});
|
|
||||||
if (fl::Op::isLt(min, bankDanger->getMinimum()))
|
|
||||||
{
|
|
||||||
bankDanger->setMinimum(min);
|
|
||||||
}
|
|
||||||
if (fl::Op::isGt(max, bankDanger->getMaximum()))
|
|
||||||
{
|
|
||||||
bankDanger->setMaximum(max);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//comparison purposes
|
ui64 totalStrength = 0;
|
||||||
//int averageValue = (evaluateBankConfig (VLC->objh->banksInfo[ID][0]) + evaluateBankConfig (VLC->objh->banksInfo[ID][3])) * 0.5;
|
ui8 totalChance = 0;
|
||||||
//dynamic_cast<fl::SingletonTerm*>(bankInput->term("SET"))->setValue(0.5);
|
for (auto config : bankInfo->getPossibleGuards())
|
||||||
bankInput->setInputValue(0.5);
|
|
||||||
//engine.process(BANK_DANGER);//TODO: Process Bank_Dange only
|
|
||||||
engine.process(); //TODO: Process Bank_Dange only
|
|
||||||
val = bankDanger->getOutputValue(); //some expected value of this bank
|
|
||||||
}
|
|
||||||
catch (fl::Exception & fe)
|
|
||||||
{
|
{
|
||||||
logAi->errorStream() << "estimateBankDanger " << ": " << fe.getWhat();
|
totalStrength += config.second.totalStrength * config.first;
|
||||||
|
totalChance += config.first;
|
||||||
}
|
}
|
||||||
assert(val >= 0);
|
return totalStrength / totalChance;
|
||||||
return val;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,10 +22,6 @@ class FuzzyHelper
|
|||||||
|
|
||||||
fl::Engine engine;
|
fl::Engine engine;
|
||||||
|
|
||||||
fl::InputVariable* bankInput;
|
|
||||||
fl::OutputVariable* bankDanger;
|
|
||||||
fl::RuleBlock bankBlock;
|
|
||||||
|
|
||||||
class TacticalAdvantage
|
class TacticalAdvantage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -55,7 +51,6 @@ public:
|
|||||||
//blocks should be initialized in this order, which may be confusing :/
|
//blocks should be initialized in this order, which may be confusing :/
|
||||||
|
|
||||||
FuzzyHelper();
|
FuzzyHelper();
|
||||||
void initBank();
|
|
||||||
void initTacticalAdvantage();
|
void initTacticalAdvantage();
|
||||||
void initVisitTile();
|
void initVisitTile();
|
||||||
|
|
||||||
|
@ -370,6 +370,29 @@ IObjectInfo::CArmyStructure CBankInfo::maxGuards() const
|
|||||||
return *boost::range::max_element(armies);
|
return *boost::range::max_element(armies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TPossibleGuards CBankInfo::getPossibleGuards() const
|
||||||
|
{
|
||||||
|
TPossibleGuards out;
|
||||||
|
|
||||||
|
for (const JsonNode & configEntry : config)
|
||||||
|
{
|
||||||
|
const JsonNode & guardsInfo = configEntry["guards"];
|
||||||
|
auto stacks = JsonRandom::evaluateCreatures(configEntry["guards"]);
|
||||||
|
IObjectInfo::CArmyStructure army;
|
||||||
|
|
||||||
|
|
||||||
|
for (auto stack : stacks)
|
||||||
|
{
|
||||||
|
army.totalStrength += stack.allowedCreatures.front()->AIValue * (stack.minAmount + stack.maxAmount) / 2;
|
||||||
|
//TODO: add fields for flyers, walkers etc...
|
||||||
|
}
|
||||||
|
|
||||||
|
ui8 chance = configEntry["chance"].Float();
|
||||||
|
out.push_back(std::make_pair(chance, army));
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
bool CBankInfo::givesResources() const
|
bool CBankInfo::givesResources() const
|
||||||
{
|
{
|
||||||
for (const JsonNode & node : config)
|
for (const JsonNode & node : config)
|
||||||
|
@ -152,14 +152,20 @@ struct BankConfig
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class CBankInfo : public IObjectInfo
|
typedef std::vector<std::pair<ui8, IObjectInfo::CArmyStructure>> TPossibleGuards;
|
||||||
|
|
||||||
|
class DLL_LINKAGE CBankInfo : public IObjectInfo
|
||||||
{
|
{
|
||||||
JsonVector config;
|
JsonVector config;
|
||||||
public:
|
public:
|
||||||
CBankInfo(JsonVector config);
|
CBankInfo(JsonVector config);
|
||||||
|
|
||||||
|
TPossibleGuards getPossibleGuards() const;
|
||||||
|
|
||||||
|
//I have no idea what do these functions do or were supposed to do - War
|
||||||
CArmyStructure minGuards() const;
|
CArmyStructure minGuards() const;
|
||||||
CArmyStructure maxGuards() const;
|
CArmyStructure maxGuards() const;
|
||||||
|
|
||||||
bool givesResources() const;
|
bool givesResources() const;
|
||||||
bool givesArtifacts() const;
|
bool givesArtifacts() const;
|
||||||
bool givesCreatures() const;
|
bool givesCreatures() const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user