Browse Source

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.
Xilmi 1 year ago
parent
commit
c10c04779f
1 changed files with 18 additions and 2 deletions
  1. 18 2
      AI/Nullkiller/Analyzers/BuildAnalyzer.cpp

+ 18 - 2
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);
 }