2
0
Эх сурвалжийг харах

Moved retreat decision-making constants to config

Ivan Savenko 1 жил өмнө
parent
commit
00492a60a7

+ 1 - 3
AI/Nullkiller/AIGateway.cpp

@@ -36,8 +36,6 @@ namespace NKAI
 
 // our to enemy strength ratio constants
 const float SAFE_ATTACK_CONSTANT = 1.1f;
-const float RETREAT_THRESHOLD = 0.3f;
-const double RETREAT_ABSOLUTE_THRESHOLD = 10000.;
 
 //one thread may be turn of AI and another will be handling a side effect for AI2
 thread_local CCallback * cb = nullptr;
@@ -553,7 +551,7 @@ std::optional<BattleAction> AIGateway::makeSurrenderRetreatDecision(const Battle
 	double fightRatio = ourStrength / (double)battleState.getEnemyStrength();
 
 	// if we have no towns - things are already bad, so retreat is not an option.
-	if(cb->getTownsInfo().size() && ourStrength < RETREAT_ABSOLUTE_THRESHOLD && fightRatio < RETREAT_THRESHOLD && battleState.canFlee)
+	if(cb->getTownsInfo().size() && ourStrength < nullkiller->settings->getRetreatThresholdAbsoolute() && fightRatio < nullkiller->settings->getRetreatThresholdRelative() && battleState.canFlee)
 	{
 		return BattleAction::makeRetreat(battleState.ourSide);
 	}

+ 5 - 1
AI/Nullkiller/Engine/Settings.cpp

@@ -28,7 +28,9 @@ namespace NKAI
 		: maxRoamingHeroes(8),
 		mainHeroTurnDistanceLimit(10),
 		scoutHeroTurnDistanceLimit(5),
-		maxGoldPressure(0.3f), 
+		maxGoldPressure(0.3f),
+		retreatThresholdRelative(0.3),
+		retreatThresholdAbsoolute(10000),
 		maxpass(10),
 		pathfinderBucketsCount(1),
 		pathfinderBucketSize(32),
@@ -48,6 +50,8 @@ namespace NKAI
 		pathfinderBucketsCount = node["pathfinderBucketsCount"].Integer();
 		pathfinderBucketSize = node["pathfinderBucketSize"].Integer();
 		maxGoldPressure = node["maxGoldPressure"].Float();
+		retreatThresholdRelative = node["retreatThresholdRelative"].Float();
+		retreatThresholdAbsoolute = node["retreatThresholdAbsoolute"].Float();
 		allowObjectGraph = node["allowObjectGraph"].Bool();
 		openMap = node["openMap"].Bool();
 		useFuzzy = node["useFuzzy"].Bool();

+ 4 - 0
AI/Nullkiller/Engine/Settings.h

@@ -28,6 +28,8 @@ namespace NKAI
 		int pathfinderBucketsCount;
 		int pathfinderBucketSize;
 		float maxGoldPressure;
+		float retreatThresholdRelative;
+		float retreatThresholdAbsoolute;
 		bool allowObjectGraph;
 		bool useTroopsFromGarrisons;
 		bool openMap;
@@ -38,6 +40,8 @@ namespace NKAI
 
 		int getMaxPass() const { return maxpass; }
 		float getMaxGoldPressure() const { return maxGoldPressure; }
+		float getRetreatThresholdRelative() const { return retreatThresholdRelative; }
+		float getRetreatThresholdAbsoolute() const { return retreatThresholdAbsoolute; }
 		int getMaxRoamingHeroes() const { return maxRoamingHeroes; }
 		int getMainHeroTurnDistanceLimit() const { return mainHeroTurnDistanceLimit; }
 		int getScoutHeroTurnDistanceLimit() const { return scoutHeroTurnDistanceLimit; }

+ 10 - 0
config/ai/nkai/nkai-settings.json

@@ -10,6 +10,8 @@
 		"allowObjectGraph": false,
 		"pathfinderBucketsCount" : 1, // old value: 3,
 		"pathfinderBucketSize" : 32, // old value: 7,
+		"retreatThresholdRelative" : 0.3,
+		"retreatThresholdAbsoolute" : 10000,
 		"useFuzzy" : false
 	},
 	
@@ -24,6 +26,8 @@
 		"allowObjectGraph": false,
 		"pathfinderBucketsCount" : 1, // old value: 3,
 		"pathfinderBucketSize" : 32, // old value: 7,
+		"retreatThresholdRelative" : 0.3,
+		"retreatThresholdAbsoolute" : 10000,
 		"useFuzzy" : false
 	},
 	
@@ -38,6 +42,8 @@
 		"allowObjectGraph": false,
 		"pathfinderBucketsCount" : 1, // old value: 3,
 		"pathfinderBucketSize" : 32, // old value: 7,
+		"retreatThresholdRelative" : 0.3,
+		"retreatThresholdAbsoolute" : 10000,
 		"useFuzzy" : false
 	},
 	
@@ -52,6 +58,8 @@
 		"allowObjectGraph": false,
 		"pathfinderBucketsCount" : 1, // old value: 3,
 		"pathfinderBucketSize" : 32, // old value: 7,
+		"retreatThresholdRelative" : 0.3,
+		"retreatThresholdAbsoolute" : 10000,
 		"useFuzzy" : false
 	},
 	
@@ -66,6 +74,8 @@
 		"allowObjectGraph": false,
 		"pathfinderBucketsCount" : 1, // old value: 3,
 		"pathfinderBucketSize" : 32, // old value: 7,
+		"retreatThresholdRelative" : 0.3,
+		"retreatThresholdAbsoolute" : 10000,
 		"useFuzzy" : false
 	}
 }