1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-03 00:46:55 +02:00

Initial split of classes

This commit is contained in:
Dydzio
2018-08-04 17:36:16 +02:00
parent a0909468de
commit a8f5882a77
2 changed files with 71 additions and 59 deletions

View File

@ -308,7 +308,7 @@ float FuzzyHelper::getWanderTargetObjectValue(const CGHeroInstance & h, const Ob
float output = -1.0f; float output = -1.0f;
try try
{ {
wanderTarget.distance->setValue(distFromObject); wanderTarget.turnDistance->setValue(distFromObject);
wanderTarget.objectValue->setValue(objValue); wanderTarget.objectValue->setValue(objValue);
wanderTarget.engine.process(); wanderTarget.engine.process();
output = wanderTarget.visitGain->getValue(); output = wanderTarget.visitGain->getValue();
@ -321,7 +321,7 @@ float FuzzyHelper::getWanderTargetObjectValue(const CGHeroInstance & h, const Ob
return output; return output;
} }
FuzzyHelper::TacticalAdvantage::~TacticalAdvantage() TacticalAdvantage::~TacticalAdvantage()
{ {
//TODO: smart pointers? //TODO: smart pointers?
delete ourWalkers; delete ourWalkers;
@ -373,7 +373,7 @@ float FuzzyHelper::evaluate(Goals::RecruitHero & g)
{ {
return 1; return 1;
} }
FuzzyHelper::EvalVisitTile::~EvalVisitTile() HeroMovementGoalEngine::~HeroMovementGoalEngine()
{ {
delete strengthRatio; delete strengthRatio;
delete heroStrength; delete heroStrength;
@ -466,21 +466,21 @@ void FuzzyHelper::initWanderTarget()
{ {
try try
{ {
wanderTarget.distance = new fl::InputVariable("distance"); //distance on map from object wanderTarget.turnDistance = new fl::InputVariable("turnDistance"); //distance on map from object
wanderTarget.objectValue = new fl::InputVariable("objectValue"); //value of that object type known by AI wanderTarget.objectValue = new fl::InputVariable("objectValue"); //value of that object type known by AI
wanderTarget.visitGain = new fl::OutputVariable("visitGain"); wanderTarget.value = new fl::OutputVariable("value");
wanderTarget.visitGain->setMinimum(0); wanderTarget.value->setMinimum(0);
wanderTarget.visitGain->setMaximum(10); wanderTarget.value->setMaximum(10);
wanderTarget.engine.addInputVariable(wanderTarget.distance); wanderTarget.engine.addInputVariable(wanderTarget.turnDistance);
wanderTarget.engine.addInputVariable(wanderTarget.objectValue); wanderTarget.engine.addInputVariable(wanderTarget.objectValue);
wanderTarget.engine.addOutputVariable(wanderTarget.visitGain); wanderTarget.engine.addOutputVariable(wanderTarget.visitGain);
//for now distance variable same as in as VisitTile //for now distance variable same as in as VisitTile
wanderTarget.distance->addTerm(new fl::Ramp("SHORT", 0.5, 0)); wanderTarget.turnDistance->addTerm(new fl::Ramp("SHORT", 0.5, 0));
wanderTarget.distance->addTerm(new fl::Triangle("MEDIUM", 0.1, 0.8)); wanderTarget.turnDistance->addTerm(new fl::Triangle("MEDIUM", 0.1, 0.8));
wanderTarget.distance->addTerm(new fl::Ramp("LONG", 0.5, 3)); wanderTarget.turnDistance->addTerm(new fl::Ramp("LONG", 0.5, 3));
wanderTarget.distance->setRange(0, 3.0); wanderTarget.turnDistance->setRange(0, 3.0);
//objectValue ranges are based on checking RMG priorities of some objects and trying to guess sane value ranges //objectValue ranges are based on checking RMG priorities of some objects and trying to guess sane value ranges
wanderTarget.objectValue->addTerm(new fl::Ramp("LOW", 3000, 0)); //I have feeling that concave shape might work well instead of ramp for objectValue FL terms wanderTarget.objectValue->addTerm(new fl::Ramp("LOW", 3000, 0)); //I have feeling that concave shape might work well instead of ramp for objectValue FL terms
@ -488,22 +488,22 @@ void FuzzyHelper::initWanderTarget()
wanderTarget.objectValue->addTerm(new fl::Ramp("HIGH", 5000, 20000)); wanderTarget.objectValue->addTerm(new fl::Ramp("HIGH", 5000, 20000));
wanderTarget.objectValue->setRange(0, 20000); //relic artifact value is border value by design, even better things are scaled down. wanderTarget.objectValue->setRange(0, 20000); //relic artifact value is border value by design, even better things are scaled down.
wanderTarget.visitGain->addTerm(new fl::Ramp("LOW", 5, 0)); wanderTarget.value->addTerm(new fl::Ramp("LOW", 5, 0));
wanderTarget.visitGain->addTerm(new fl::Triangle("MEDIUM", 4, 6)); wanderTarget.value->addTerm(new fl::Triangle("MEDIUM", 4, 6));
wanderTarget.visitGain->addTerm(new fl::Ramp("HIGH", 5, 10)); wanderTarget.value->addTerm(new fl::Ramp("HIGH", 5, 10));
wanderTarget.visitGain->setRange(0, 10); wanderTarget.value->setRange(0, 10);
wanderTarget.addRule("if distance is LONG and objectValue is HIGH then visitGain is MEDIUM"); wanderTarget.addRule("if turnDistance is LONG and objectValue is HIGH then value is MEDIUM");
wanderTarget.addRule("if distance is MEDIUM and objectValue is HIGH then visitGain is somewhat HIGH"); wanderTarget.addRule("if turnDistance is MEDIUM and objectValue is HIGH then value is somewhat HIGH");
wanderTarget.addRule("if distance is SHORT and objectValue is HIGH then visitGain is HIGH"); wanderTarget.addRule("if turnDistance is SHORT and objectValue is HIGH then value is HIGH");
wanderTarget.addRule("if distance is LONG and objectValue is MEDIUM then visitGain is somewhat LOW"); wanderTarget.addRule("if turnDistance is LONG and objectValue is MEDIUM then value is somewhat LOW");
wanderTarget.addRule("if distance is MEDIUM and objectValue is MEDIUM then visitGain is MEDIUM"); wanderTarget.addRule("if turnDistance is MEDIUM and objectValue is MEDIUM then value is MEDIUM");
wanderTarget.addRule("if distance is SHORT and objectValue is MEDIUM then visitGain is somewhat HIGH"); wanderTarget.addRule("if turnDistance is SHORT and objectValue is MEDIUM then value is somewhat HIGH");
wanderTarget.addRule("if distance is LONG and objectValue is LOW then visitGain is very LOW"); wanderTarget.addRule("if turnDistance is LONG and objectValue is LOW then value is very LOW");
wanderTarget.addRule("if distance is MEDIUM and objectValue is LOW then visitGain is LOW"); wanderTarget.addRule("if turnDistance is MEDIUM and objectValue is LOW then value is LOW");
wanderTarget.addRule("if distance is SHORT and objectValue is LOW then visitGain is MEDIUM"); wanderTarget.addRule("if turnDistance is SHORT and objectValue is LOW then value is MEDIUM");
} }
catch(fl::Exception & fe) catch(fl::Exception & fe)
{ {
@ -635,9 +635,11 @@ void FuzzyHelper::setPriority(Goals::TSubgoal & g) //calls evaluate - Visitor pa
g->setpriority(g->accept(this)); //this enforces returned value is set g->setpriority(g->accept(this)); //this enforces returned value is set
} }
FuzzyHelper::EvalWanderTargetObject::~EvalWanderTargetObject() EvalWanderTargetObject::~EvalWanderTargetObject()
{ {
delete distance;
delete objectValue; delete objectValue;
delete visitGain; }
EvalVisitTile::~EvalVisitTile()
{
} }

View File

@ -27,42 +27,52 @@ public:
void addRule(const std::string & txt); void addRule(const std::string & txt);
}; };
class FuzzyHelper class TacticalAdvantage : public engineBase
{ {
friend class VCAI; public:
fl::InputVariable * ourWalkers, *ourShooters, *ourFlyers, *enemyWalkers, *enemyShooters, *enemyFlyers;
class TacticalAdvantage : public engineBase fl::InputVariable * ourSpeed, *enemySpeed;
{
public:
fl::InputVariable * ourWalkers, * ourShooters, * ourFlyers, * enemyWalkers, * enemyShooters, * enemyFlyers;
fl::InputVariable * ourSpeed, * enemySpeed;
fl::InputVariable * bankPresent; fl::InputVariable * bankPresent;
fl::InputVariable * castleWalls; fl::InputVariable * castleWalls;
fl::OutputVariable * threat; fl::OutputVariable * threat;
~TacticalAdvantage(); ~TacticalAdvantage();
} ta; };
class EvalVisitTile : public engineBase class HeroMovementGoalEngine : public engineBase
{ {
public: public:
fl::InputVariable * strengthRatio; fl::InputVariable * strengthRatio;
fl::InputVariable * heroStrength; fl::InputVariable * heroStrength;
fl::InputVariable * turnDistance; fl::InputVariable * turnDistance;
fl::InputVariable * missionImportance; fl::InputVariable * missionImportance;
fl::InputVariable * estimatedReward; fl::InputVariable * estimatedReward;
fl::OutputVariable * value; fl::OutputVariable * value;
fl::RuleBlock rules; ~HeroMovementGoalEngine();
~EvalVisitTile(); };
} vt;
class EvalWanderTargetObject : public engineBase //designed for use with VCAI::wander() class EvalVisitTile : public HeroMovementGoalEngine
{ {
public: public:
fl::InputVariable * distance; ~EvalVisitTile();
};
class EvalWanderTargetObject : public HeroMovementGoalEngine //designed for use with VCAI::wander()
{
public:
fl::InputVariable * objectValue; fl::InputVariable * objectValue;
fl::OutputVariable * visitGain; fl::OutputVariable * visitGain;
~EvalWanderTargetObject(); ~EvalWanderTargetObject();
} wanderTarget; };
class FuzzyHelper
{
friend class VCAI;
TacticalAdvantage ta;
EvalVisitTile vt;
EvalWanderTargetObject wanderTarget;
private: private:
float calculateTurnDistanceInputValue(const CGHeroInstance * h, int3 tile) const; float calculateTurnDistanceInputValue(const CGHeroInstance * h, int3 tile) const;