Browse Source

NullkillerAI: Added movement cost by hero role. New priority engine looks more or less stable.

Andrii Danylchenko 4 years ago
parent
commit
af9261d428

+ 7 - 0
AI/Nullkiller/AIUtility.h

@@ -34,6 +34,13 @@ const int ALLOWED_ROAMING_HEROES = 8;
 extern const float SAFE_ATTACK_CONSTANT;
 extern const int GOLD_RESERVE;
 
+enum HeroRole
+{
+	MAIN,
+
+	SCOUT
+};
+
 //provisional class for AI to store a reference to an owned hero object
 //checks if it's valid on access, should be used in place of const CGHeroInstance*
 

+ 4 - 2
AI/Nullkiller/Engine/PriorityEvaluator.cpp

@@ -53,7 +53,8 @@ void PriorityEvaluator::initVisitTile()
 	armyLossPersentageVariable = engine->getInputVariable("armyLoss");
 	heroRoleVariable = engine->getInputVariable("heroRole");
 	dangerVariable = engine->getInputVariable("danger");
-	turnDistanceVariable = engine->getInputVariable("turnDistance");
+	mainTurnDistanceVariable = engine->getInputVariable("mainTurnDistance");
+	scoutTurnDistanceVariable = engine->getInputVariable("scoutTurnDistance");
 	goldRewardVariable = engine->getInputVariable("goldReward");
 	armyRewardVariable = engine->getInputVariable("armyReward");
 	skillRewardVariable = engine->getInputVariable("skillReward");
@@ -380,7 +381,8 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task)
 	{
 		armyLossPersentageVariable->setValue(armyLossPersentage);
 		heroRoleVariable->setValue(heroRole);
-		turnDistanceVariable->setValue(task->evaluationContext.movementCost);
+		mainTurnDistanceVariable->setValue(task->evaluationContext.movementCostByRole[HeroRole::MAIN]);
+		scoutTurnDistanceVariable->setValue(task->evaluationContext.movementCostByRole[HeroRole::SCOUT]);
 		goldRewardVariable->setValue(goldReward);
 		armyRewardVariable->setValue(armyReward);
 		skillRewardVariable->setValue(skillReward);

+ 2 - 1
AI/Nullkiller/Engine/PriorityEvaluator.h

@@ -30,7 +30,8 @@ private:
 	fl::Engine * engine;
 	fl::InputVariable * armyLossPersentageVariable;
 	fl::InputVariable * heroRoleVariable;
-	fl::InputVariable * turnDistanceVariable;
+	fl::InputVariable * mainTurnDistanceVariable;
+	fl::InputVariable * scoutTurnDistanceVariable;
 	fl::InputVariable * goldRewardVariable;
 	fl::InputVariable * armyRewardVariable;
 	fl::InputVariable * dangerVariable;

+ 4 - 1
AI/Nullkiller/Goals/AbstractGoal.h

@@ -95,6 +95,8 @@ namespace Goals
 	struct DLL_EXPORT EvaluationContext
 	{
 		float movementCost;
+		std::map<HeroRole, float> movementCostByRole;
+		float scoutMovementCost;
 		int manaCost;
 		uint64_t danger;
 		float closestWayRatio;
@@ -107,7 +109,8 @@ namespace Goals
 			danger(0),
 			closestWayRatio(1),
 			armyLoss(0),
-			heroStrength(0)
+			heroStrength(0),
+			movementCostByRole()
 		{
 		}
 	};

+ 8 - 0
AI/Nullkiller/Goals/ExecuteHeroChain.cpp

@@ -30,9 +30,17 @@ ExecuteHeroChain::ExecuteHeroChain(const AIPath & path, const CGObjectInstance *
 	evaluationContext.movementCost = path.movementCost();
 	evaluationContext.armyLoss = path.getTotalArmyLoss();
 	evaluationContext.heroStrength = path.getHeroStrength();
+
 	hero = path.targetHero;
 	tile = path.targetTile();
 
+	for(auto & node : path.nodes)
+	{
+		auto role = ai->ah->getHeroRole(node.targetHero);
+
+		evaluationContext.movementCostByRole[role] += node.cost;
+	}
+
 	if(obj)
 	{
 		objid = obj->id.getNum();

+ 0 - 7
AI/Nullkiller/HeroManager.h

@@ -18,13 +18,6 @@
 #include "../../lib/CBuildingHandler.h"
 #include "VCAI.h"
 
-enum HeroRole
-{
-	MAIN,
-
-	SCOUT
-};
-
 class DLL_EXPORT IHeroManager //: public: IAbstractManager
 {
 public: