From 87638aafc0d374d9d081fb371996f6368a061ff9 Mon Sep 17 00:00:00 2001 From: Andrii Danylchenko Date: Wed, 8 Mar 2023 12:41:14 +0200 Subject: [PATCH] NKAI: improve build behavior --- AI/Nullkiller/AIGateway.cpp | 2 +- AI/Nullkiller/Analyzers/BuildAnalyzer.cpp | 2 +- AI/Nullkiller/Engine/PriorityEvaluator.cpp | 29 +++++++++++++++------- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/AI/Nullkiller/AIGateway.cpp b/AI/Nullkiller/AIGateway.cpp index efabab3e0..37e9d0d0d 100644 --- a/AI/Nullkiller/AIGateway.cpp +++ b/AI/Nullkiller/AIGateway.cpp @@ -1301,7 +1301,7 @@ bool AIGateway::moveHeroToTile(int3 dst, HeroPtr h) if(path.nodes[i - 1].turns) { //blockedHeroes.insert(h); //to avoid attempts of moving heroes with very little MPs - break; + return false; } int3 endpos = path.nodes[i - 1].coord; diff --git a/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp b/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp index 4ae59be8f..4eed21e80 100644 --- a/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp +++ b/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp @@ -158,7 +158,7 @@ void BuildAnalyzer::update() updateDailyIncome(); - if(ai->cb->getDate(Date::EDateType::DAY) == 1) + if(ai->cb->getDate(Date::EDateType::DAY) == 1 && dailyIncome[Res::GOLD] <= 500) { goldPreasure = 1; } diff --git a/AI/Nullkiller/Engine/PriorityEvaluator.cpp b/AI/Nullkiller/Engine/PriorityEvaluator.cpp index 27674f2f4..9374a3dc6 100644 --- a/AI/Nullkiller/Engine/PriorityEvaluator.cpp +++ b/AI/Nullkiller/Engine/PriorityEvaluator.cpp @@ -361,8 +361,8 @@ float RewardEvaluator::getTotalResourceRequirementStrength(int resType) const return 0; float ratio = dailyIncome[resType] == 0 - ? requiredResources[resType] / 50 - : (float)requiredResources[resType] / dailyIncome[resType] / 50; + ? (float)requiredResources[resType] / 50.0f + : (float)requiredResources[resType] / dailyIncome[resType] / 50.0f; return std::min(ratio, 1.0f); } @@ -377,10 +377,12 @@ float RewardEvaluator::getStrategicalValue(const CGObjectInstance * target) cons case Obj::MINE: return target->subID == Res::GOLD ? 0.5f - : 0.02f * getTotalResourceRequirementStrength(target->subID) + 0.02f * getResourceRequirementStrength(target->subID); + : 0.4f * getTotalResourceRequirementStrength(target->subID) + 0.1f * getResourceRequirementStrength(target->subID); case Obj::RESOURCE: - return target->subID == Res::GOLD ? 0 : 0.1f * getResourceRequirementStrength(target->subID); + return target->subID == Res::GOLD + ? 0 + : 0.2f * getTotalResourceRequirementStrength(target->subID) + 0.4f * getResourceRequirementStrength(target->subID); case Obj::CREATURE_BANK: { @@ -800,21 +802,23 @@ public: evaluationContext.goldReward += 7 * bi.dailyIncome[Res::GOLD] / 2; // 7 day income but half we already have evaluationContext.heroRole = HeroRole::MAIN; evaluationContext.movementCostByRole[evaluationContext.heroRole] += bi.prerequisitesCount; - evaluationContext.strategicalValue += buildThis.townInfo.armyStrength / 50000.0; evaluationContext.goldCost += bi.buildCostWithPrerequisits[Res::GOLD]; if(bi.creatureID != CreatureID::NONE) { + evaluationContext.strategicalValue += buildThis.townInfo.armyStrength / 50000.0; + if(bi.baseCreatureID == bi.creatureID) { - evaluationContext.strategicalValue += 0.5f + 0.1f * bi.creatureLevel / (float)bi.prerequisitesCount; + evaluationContext.strategicalValue += (0.5f + 0.1f * bi.creatureLevel) / (float)bi.prerequisitesCount; evaluationContext.armyReward += bi.armyStrength; } else { auto potentialUpgradeValue = evaluationContext.evaluator.getUpgradeArmyReward(buildThis.town, bi); - //evaluationContext.strategicalValue += 0.05f * bi.creatureLevel / (float)bi.prerequisitesCount; - evaluationContext.armyReward += 0.3f * potentialUpgradeValue / (float)bi.prerequisitesCount; + + evaluationContext.strategicalValue += potentialUpgradeValue / 10000.0f / (float)bi.prerequisitesCount; + evaluationContext.armyReward += potentialUpgradeValue / (float)bi.prerequisitesCount; } } else if(bi.id == BuildingID::CITADEL || bi.id == BuildingID::CASTLE) @@ -824,7 +828,14 @@ public: } else { - evaluationContext.strategicalValue += evaluationContext.evaluator.ai->buildAnalyzer->getGoldPreasure() * evaluationContext.goldReward / 2200.0f; + auto goldPreasure = evaluationContext.evaluator.ai->buildAnalyzer->getGoldPreasure(); + + evaluationContext.strategicalValue += evaluationContext.goldReward * goldPreasure / 3500.0f / bi.prerequisitesCount; + } + + if(bi.notEnoughRes && bi.prerequisitesCount == 1) + { + evaluationContext.strategicalValue /= 2; } } };