From c10c04779fa74d6d85844d003705be7f45bc582f Mon Sep 17 00:00:00 2001 From: Xilmi Date: Wed, 14 Aug 2024 22:52:19 +0200 Subject: [PATCH] Adaptive Build-order When not threatened by nearby enemies the AI adds missing gold-income-buildings towards gold-pressure. This impacts the build-order in a way that they try to rush these more and get up a good economy more quickly. --- AI/Nullkiller/Analyzers/BuildAnalyzer.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp b/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp index be50aa6da..8cab129aa 100644 --- a/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp +++ b/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp @@ -149,9 +149,17 @@ void BuildAnalyzer::update() auto towns = ai->cb->getTownsInfo(); + float economyDevelopmentCost = 0; + uint8_t closestThreat = UINT8_MAX; + ai->dangerHitMap->updateHitMap(); + for(const CGTownInstance* town : towns) { - logAi->trace("Checking town %s", town->getNameTranslated()); + for (auto threat : ai->dangerHitMap->getTownThreats(town)) + { + closestThreat = std::min(closestThreat, threat.turn); + } + logAi->trace("Checking town %s closest threat: %u", town->getNameTranslated(), (unsigned int)closestThreat); developmentInfos.push_back(TownDevelopmentInfo(town)); TownDevelopmentInfo & developmentInfo = developmentInfos.back(); @@ -161,6 +169,11 @@ void BuildAnalyzer::update() requiredResources += developmentInfo.requiredResources; totalDevelopmentCost += developmentInfo.townDevelopmentCost; + for(auto building : developmentInfo.toBuild) + { + if (building.dailyIncome[EGameResID::GOLD] > 0) + economyDevelopmentCost += building.buildCostWithPrerequisites[EGameResID::GOLD]; + } armyCost += developmentInfo.armyCost; for(auto bi : developmentInfo.toBuild) @@ -169,6 +182,9 @@ void BuildAnalyzer::update() } } + if (closestThreat < 7) + economyDevelopmentCost = 0; + std::sort(developmentInfos.begin(), developmentInfos.end(), [](const TownDevelopmentInfo & t1, const TownDevelopmentInfo & t2) -> bool { auto val1 = convertToGold(t1.armyCost) - convertToGold(t1.townDevelopmentCost); @@ -180,7 +196,7 @@ void BuildAnalyzer::update() updateDailyIncome(); goldPressure = ai->getLockedResources()[EGameResID::GOLD] / 5000.0f - + (float)armyCost[EGameResID::GOLD] / (1 + 2 * ai->getFreeGold() + (float)dailyIncome[EGameResID::GOLD] * 7.0f); + + ((float)armyCost[EGameResID::GOLD] + economyDevelopmentCost) / (1 + 2 * ai->getFreeGold() + (float)dailyIncome[EGameResID::GOLD] * 7.0f); logAi->trace("Gold pressure: %f", goldPressure); }