1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-25 21:38:59 +02:00

Update PriorityEvaluator.cpp

Replace float-comparisons with zero by vstd::isAlmostZero
This commit is contained in:
Xilmi 2024-09-05 16:40:06 +02:00
parent 20cfe712c9
commit dafc9cd8a8

View File

@ -1397,7 +1397,7 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
return 0;
if(evaluationContext.conquestValue > 0)
score = 1000;
if (score == 0 || (evaluationContext.enemyHeroDangerRatio > 1 && (evaluationContext.turn > 0 || evaluationContext.isExchange) && !ai->cb->getTownsInfo().empty()))
if (vstd::isAlmostZero(score) || (evaluationContext.enemyHeroDangerRatio > 1 && (evaluationContext.turn > 0 || evaluationContext.isExchange) && !ai->cb->getTownsInfo().empty()))
return 0;
if (maxWillingToLose - evaluationContext.armyLossPersentage < 0)
return 0;
@ -1417,7 +1417,7 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
{
if (evaluationContext.conquestValue > 0)
score = 1000;
if (score == 0 || (evaluationContext.enemyHeroDangerRatio > 1 && (evaluationContext.turn > 0 || evaluationContext.isExchange) && !ai->cb->getTownsInfo().empty()))
if (vstd::isAlmostZero(score) || (evaluationContext.enemyHeroDangerRatio > 1 && (evaluationContext.turn > 0 || evaluationContext.isExchange) && !ai->cb->getTownsInfo().empty()))
return 0;
if (maxWillingToLose - evaluationContext.armyLossPersentage < 0)
return 0;
@ -1524,7 +1524,7 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
{
TResources needed = evaluationContext.buildingCost - resourcesAvailable;
needed.positive();
int turnsTo = needed.div(income);
int turnsTo = needed.maxPurchasableCount(income);
if (turnsTo == INT_MAX)
return 0;
else
@ -1533,7 +1533,7 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
}
else
{
if (evaluationContext.enemyHeroDangerRatio > 1 && !evaluationContext.isDefend && evaluationContext.conquestValue == 0)
if (evaluationContext.enemyHeroDangerRatio > 1 && !evaluationContext.isDefend && vstd::isAlmostZero(evaluationContext.conquestValue))
return 0;
}
break;