1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-25 22:42:04 +02:00

Enum for PriorityTiers

In order to not confuse PriorityTiers, especially after adding new ones, now using an enum to identify them.
This commit is contained in:
Xilmi
2024-09-02 00:16:19 +02:00
parent c667ca46d1
commit 09badeb5be
4 changed files with 24 additions and 13 deletions

View File

@@ -467,7 +467,7 @@ void ObjectClusterizer::clusterizeObject(
heroesProcessed.insert(path.targetHero); heroesProcessed.insert(path.targetHero);
float priority = priorityEvaluator->evaluate(Goals::sptr(Goals::ExecuteHeroChain(path, obj)), 5); float priority = priorityEvaluator->evaluate(Goals::sptr(Goals::ExecuteHeroChain(path, obj)), PriorityEvaluator::PriorityTier::HUNTER_GATHER);
if(ai->settings->isUseFuzzy() && priority < MIN_PRIORITY) if(ai->settings->isUseFuzzy() && priority < MIN_PRIORITY)
continue; continue;
@@ -490,7 +490,7 @@ void ObjectClusterizer::clusterizeObject(
heroesProcessed.insert(path.targetHero); heroesProcessed.insert(path.targetHero);
float priority = priorityEvaluator->evaluate(Goals::sptr(Goals::ExecuteHeroChain(path, obj)), 5); float priority = priorityEvaluator->evaluate(Goals::sptr(Goals::ExecuteHeroChain(path, obj)), PriorityEvaluator::PriorityTier::HUNTER_GATHER);
if (ai->settings->isUseFuzzy() && priority < MIN_PRIORITY) if (ai->settings->isUseFuzzy() && priority < MIN_PRIORITY)
continue; continue;

View File

@@ -180,7 +180,7 @@ Goals::TTaskVec Nullkiller::buildPlan(TGoalVec & tasks, int priorityTier) const
for(size_t i = r.begin(); i != r.end(); i++) for(size_t i = r.begin(); i != r.end(); i++)
{ {
auto task = tasks[i]; auto task = tasks[i];
if (task->asTask()->priority <= 0 || priorityTier != 0) if (task->asTask()->priority <= 0 || priorityTier != PriorityEvaluator::PriorityTier::BUILDINGS)
task->asTask()->priority = evaluator->evaluate(task, priorityTier); task->asTask()->priority = evaluator->evaluate(task, priorityTier);
} }
}); });
@@ -385,7 +385,7 @@ void Nullkiller::makeTurn()
if(bestTask->priority > 0) if(bestTask->priority > 0)
{ {
logAi->info("Pass %d: Performing task %s with prio: %d", bestTask->toString(), bestTask->priority); logAi->info("Pass %d: Performing task %s with prio: %d", i, bestTask->toString(), bestTask->priority);
if(!executeTask(bestTask)) if(!executeTask(bestTask))
return; return;
@@ -408,7 +408,7 @@ void Nullkiller::makeTurn()
TTaskVec selectedTasks; TTaskVec selectedTasks;
int prioOfTask = 0; int prioOfTask = 0;
for (int prio = 1; prio <= 6; ++prio) for (int prio = PriorityEvaluator::PriorityTier::INSTAKILL; prio <= PriorityEvaluator::PriorityTier::DEFEND; ++prio)
{ {
prioOfTask = prio; prioOfTask = prio;
selectedTasks = buildPlan(bestTasks, prio); selectedTasks = buildPlan(bestTasks, prio);

View File

@@ -1398,7 +1398,7 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
switch (priorityTier) switch (priorityTier)
{ {
case 1: //Take towns / kill heroes in immediate reach case PriorityTier::INSTAKILL: //Take towns / kill heroes in immediate reach
{ {
if (evaluationContext.turn > 0) if (evaluationContext.turn > 0)
return 0; return 0;
@@ -1413,14 +1413,14 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
score /= evaluationContext.movementCost; score /= evaluationContext.movementCost;
break; break;
} }
case 2: //Defend immediately threatened towns case PriorityTier::INSTADEFEND: //Defend immediately threatened towns
{ {
if (evaluationContext.isDefend && evaluationContext.threatTurns == 0 && evaluationContext.turn == 0) if (evaluationContext.isDefend && evaluationContext.threatTurns == 0 && evaluationContext.turn == 0)
score = evaluationContext.armyInvolvement; score = evaluationContext.armyInvolvement;
score *= evaluationContext.closestWayRatio; score *= evaluationContext.closestWayRatio;
break; break;
} }
case 3: //Take towns / kill heroes that are further away case PriorityTier::KILL: //Take towns / kill heroes that are further away
{ {
if (evaluationContext.conquestValue > 0) if (evaluationContext.conquestValue > 0)
score = 1000; score = 1000;
@@ -1433,7 +1433,7 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
score /= evaluationContext.movementCost; score /= evaluationContext.movementCost;
break; break;
} }
case 4: //Collect unguarded stuff case PriorityTier::GATHER: //Collect unguarded stuff
{ {
if (evaluationContext.enemyHeroDangerRatio > 1) if (evaluationContext.enemyHeroDangerRatio > 1)
return 0; return 0;
@@ -1463,7 +1463,7 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
score /= evaluationContext.movementCost; score /= evaluationContext.movementCost;
break; break;
} }
case 5: //Collect guarded stuff case PriorityTier::HUNTER_GATHER: //Collect guarded stuff
{ {
if (evaluationContext.enemyHeroDangerRatio > 1 && !evaluationContext.isDefend) if (evaluationContext.enemyHeroDangerRatio > 1 && !evaluationContext.isDefend)
return 0; return 0;
@@ -1489,7 +1489,7 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
} }
break; break;
} }
case 6: //Defend whatever if nothing else is to do case PriorityTier::DEFEND: //Defend whatever if nothing else is to do
{ {
if (evaluationContext.enemyHeroDangerRatio > 1 && evaluationContext.isExchange) if (evaluationContext.enemyHeroDangerRatio > 1 && evaluationContext.isExchange)
return 0; return 0;
@@ -1499,7 +1499,7 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
score /= (evaluationContext.turn + 1); score /= (evaluationContext.turn + 1);
break; break;
} }
case 0: //For buildings and buying army case PriorityTier::BUILDINGS: //For buildings and buying army
{ {
if (maxWillingToLose - evaluationContext.armyLossPersentage < 0) if (maxWillingToLose - evaluationContext.armyLossPersentage < 0)
return 0; return 0;

View File

@@ -104,7 +104,18 @@ public:
~PriorityEvaluator(); ~PriorityEvaluator();
void initVisitTile(); void initVisitTile();
float evaluate(Goals::TSubgoal task, int priorityTier = 0); float evaluate(Goals::TSubgoal task, int priorityTier = BUILDINGS);
enum PriorityTier : int32_t
{
BUILDINGS = 0,
INSTAKILL,
INSTADEFEND,
KILL,
GATHER,
HUNTER_GATHER,
DEFEND
};
private: private:
const Nullkiller * ai; const Nullkiller * ai;