1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-10 22:31:40 +02:00

Merge pull request #5229 from IvanSavenko/ai_optimize_test

[1.6.3] AI performance-related changes
This commit is contained in:
Ivan Savenko
2025-01-09 12:57:37 +02:00
committed by GitHub
9 changed files with 44 additions and 41 deletions

View File

@@ -285,8 +285,8 @@ void AIGateway::tileRevealed(const std::unordered_set<int3> & pos)
addVisitableObj(obj); addVisitableObj(obj);
} }
if (nullkiller->settings->isUpdateHitmapOnTileReveal()) if (nullkiller->settings->isUpdateHitmapOnTileReveal() && !pos.empty())
nullkiller->dangerHitMap->reset(); nullkiller->dangerHitMap->resetTileOwners();
} }
void AIGateway::heroExchangeStarted(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID query) void AIGateway::heroExchangeStarted(ObjectInstanceID hero1, ObjectInstanceID hero2, QueryID query)
@@ -389,9 +389,10 @@ void AIGateway::objectRemoved(const CGObjectInstance * obj, const PlayerColor &
} }
if(obj->ID == Obj::HERO && cb->getPlayerRelations(obj->tempOwner, playerID) == PlayerRelations::ENEMIES) if(obj->ID == Obj::HERO && cb->getPlayerRelations(obj->tempOwner, playerID) == PlayerRelations::ENEMIES)
{ nullkiller->dangerHitMap->resetHitmap();
nullkiller->dangerHitMap->reset();
} if(obj->ID == Obj::TOWN)
nullkiller->dangerHitMap->resetTileOwners();
} }
void AIGateway::showHillFortWindow(const CGObjectInstance * object, const CGHeroInstance * visitor) void AIGateway::showHillFortWindow(const CGObjectInstance * object, const CGHeroInstance * visitor)
@@ -507,7 +508,7 @@ void AIGateway::objectPropertyChanged(const SetObjectProperty * sop)
else if(relations == PlayerRelations::SAME_PLAYER && obj->ID == Obj::TOWN) else if(relations == PlayerRelations::SAME_PLAYER && obj->ID == Obj::TOWN)
{ {
// reevaluate defence for a new town // reevaluate defence for a new town
nullkiller->dangerHitMap->reset(); nullkiller->dangerHitMap->resetHitmap();
} }
} }
} }
@@ -1246,7 +1247,7 @@ void AIGateway::addVisitableObj(const CGObjectInstance * obj)
if(obj->ID == Obj::HERO && cb->getPlayerRelations(obj->tempOwner, playerID) == PlayerRelations::ENEMIES) if(obj->ID == Obj::HERO && cb->getPlayerRelations(obj->tempOwner, playerID) == PlayerRelations::ENEMIES)
{ {
nullkiller->dangerHitMap->reset(); nullkiller->dangerHitMap->resetHitmap();
} }
} }

View File

@@ -119,7 +119,7 @@ void DangerHitMapAnalyzer::updateHitMap()
PathfinderSettings ps; PathfinderSettings ps;
ps.scoutTurnDistanceLimit = ps.mainTurnDistanceLimit = ai->settings->getMainHeroTurnDistanceLimit(); ps.scoutTurnDistanceLimit = ps.mainTurnDistanceLimit = ai->settings->getThreatTurnDistanceLimit();
ps.useHeroChain = false; ps.useHeroChain = false;
ai->pathfinder->updatePaths(pair.second, ps); ai->pathfinder->updatePaths(pair.second, ps);
@@ -345,10 +345,4 @@ std::set<const CGObjectInstance *> DangerHitMapAnalyzer::getOneTurnAccessibleObj
return result; return result;
} }
void DangerHitMapAnalyzer::reset()
{
hitMapUpToDate = false;
tileOwnersUpToDate = false;
}
} }

View File

@@ -87,7 +87,7 @@ public:
const HitMapNode & getObjectThreat(const CGObjectInstance * obj) const; const HitMapNode & getObjectThreat(const CGObjectInstance * obj) const;
const HitMapNode & getTileThreat(const int3 & tile) const; const HitMapNode & getTileThreat(const int3 & tile) const;
std::set<const CGObjectInstance *> getOneTurnAccessibleObjects(const CGHeroInstance * enemy) const; std::set<const CGObjectInstance *> getOneTurnAccessibleObjects(const CGHeroInstance * enemy) const;
void reset(); void resetHitmap() {hitMapUpToDate = false;}
void resetTileOwners() { tileOwnersUpToDate = false; } void resetTileOwners() { tileOwnersUpToDate = false; }
PlayerColor getTileOwner(const int3 & tile) const; PlayerColor getTileOwner(const int3 & tile) const;
const CGTownInstance * getClosestTown(const int3 & tile) const; const CGTownInstance * getClosestTown(const int3 & tile) const;

View File

@@ -229,7 +229,7 @@ void Nullkiller::resetAiState()
lockedResources = TResources(); lockedResources = TResources();
scanDepth = ScanDepth::MAIN_FULL; scanDepth = ScanDepth::MAIN_FULL;
lockedHeroes.clear(); lockedHeroes.clear();
dangerHitMap->reset(); dangerHitMap->resetHitmap();
useHeroChain = true; useHeroChain = true;
objectClusterizer->reset(); objectClusterizer->reset();

View File

@@ -28,6 +28,7 @@ namespace NKAI
: maxRoamingHeroes(8), : maxRoamingHeroes(8),
mainHeroTurnDistanceLimit(10), mainHeroTurnDistanceLimit(10),
scoutHeroTurnDistanceLimit(5), scoutHeroTurnDistanceLimit(5),
threatTurnDistanceLimit(5),
maxGoldPressure(0.3f), maxGoldPressure(0.3f),
retreatThresholdRelative(0.3), retreatThresholdRelative(0.3),
retreatThresholdAbsolute(10000), retreatThresholdAbsolute(10000),

View File

@@ -24,6 +24,7 @@ namespace NKAI
int maxRoamingHeroes; int maxRoamingHeroes;
int mainHeroTurnDistanceLimit; int mainHeroTurnDistanceLimit;
int scoutHeroTurnDistanceLimit; int scoutHeroTurnDistanceLimit;
int threatTurnDistanceLimit;
int maxPass; int maxPass;
int maxPriorityPass; int maxPriorityPass;
int pathfinderBucketsCount; int pathfinderBucketsCount;
@@ -52,6 +53,7 @@ namespace NKAI
int getMaxRoamingHeroes() const { return maxRoamingHeroes; } int getMaxRoamingHeroes() const { return maxRoamingHeroes; }
int getMainHeroTurnDistanceLimit() const { return mainHeroTurnDistanceLimit; } int getMainHeroTurnDistanceLimit() const { return mainHeroTurnDistanceLimit; }
int getScoutHeroTurnDistanceLimit() const { return scoutHeroTurnDistanceLimit; } int getScoutHeroTurnDistanceLimit() const { return scoutHeroTurnDistanceLimit; }
int getThreatTurnDistanceLimit() const { return threatTurnDistanceLimit; }
int getPathfinderBucketsCount() const { return pathfinderBucketsCount; } int getPathfinderBucketsCount() const { return pathfinderBucketsCount; }
int getPathfinderBucketSize() const { return pathfinderBucketSize; } int getPathfinderBucketSize() const { return pathfinderBucketSize; }
bool isObjectGraphAllowed() const { return allowObjectGraph; } bool isObjectGraphAllowed() const { return allowObjectGraph; }

View File

@@ -38,13 +38,14 @@
"maxPriorityPass" : 10, "maxPriorityPass" : 10,
"mainHeroTurnDistanceLimit" : 10, "mainHeroTurnDistanceLimit" : 10,
"scoutHeroTurnDistanceLimit" : 5, "scoutHeroTurnDistanceLimit" : 5,
"threatTurnDistanceLimit" : 1,
"maxGoldPressure" : 0.3, "maxGoldPressure" : 0.3,
"updateHitmapOnTileReveal" : false, "updateHitmapOnTileReveal" : true,
"useTroopsFromGarrisons" : true, "useTroopsFromGarrisons" : true,
"openMap": true, "openMap": true,
"allowObjectGraph": true, "allowObjectGraph": false,
"pathfinderBucketsCount" : 4, // old value: 3, "pathfinderBucketsCount" : 3,
"pathfinderBucketSize" : 8, // old value: 7, "pathfinderBucketSize" : 7,
"retreatThresholdRelative" : 0, "retreatThresholdRelative" : 0,
"retreatThresholdAbsolute" : 0, "retreatThresholdAbsolute" : 0,
"safeAttackRatio" : 1.1, "safeAttackRatio" : 1.1,
@@ -58,13 +59,14 @@
"maxPriorityPass" : 10, "maxPriorityPass" : 10,
"mainHeroTurnDistanceLimit" : 10, "mainHeroTurnDistanceLimit" : 10,
"scoutHeroTurnDistanceLimit" : 5, "scoutHeroTurnDistanceLimit" : 5,
"threatTurnDistanceLimit" : 4,
"maxGoldPressure" : 0.3, "maxGoldPressure" : 0.3,
"updateHitmapOnTileReveal" : false, "updateHitmapOnTileReveal" : true,
"useTroopsFromGarrisons" : true, "useTroopsFromGarrisons" : true,
"openMap": true, "openMap": true,
"allowObjectGraph": true, "allowObjectGraph": false,
"pathfinderBucketsCount" : 4, // old value: 3, "pathfinderBucketsCount" : 3,
"pathfinderBucketSize" : 8, // old value: 7, "pathfinderBucketSize" : 7,
"retreatThresholdRelative" : 0.1, "retreatThresholdRelative" : 0.1,
"retreatThresholdAbsolute" : 5000, "retreatThresholdAbsolute" : 5000,
"safeAttackRatio" : 1.1, "safeAttackRatio" : 1.1,
@@ -78,13 +80,14 @@
"maxPriorityPass" : 10, "maxPriorityPass" : 10,
"mainHeroTurnDistanceLimit" : 10, "mainHeroTurnDistanceLimit" : 10,
"scoutHeroTurnDistanceLimit" : 5, "scoutHeroTurnDistanceLimit" : 5,
"threatTurnDistanceLimit" : 5,
"maxGoldPressure" : 0.3, "maxGoldPressure" : 0.3,
"updateHitmapOnTileReveal" : false, "updateHitmapOnTileReveal" : true,
"useTroopsFromGarrisons" : true, "useTroopsFromGarrisons" : true,
"openMap": true, "openMap": true,
"allowObjectGraph": true, "allowObjectGraph": false,
"pathfinderBucketsCount" : 4, // old value: 3, "pathfinderBucketsCount" : 3,
"pathfinderBucketSize" : 8, // old value: 7, "pathfinderBucketSize" : 7,
"retreatThresholdRelative" : 0.3, "retreatThresholdRelative" : 0.3,
"retreatThresholdAbsolute" : 10000, "retreatThresholdAbsolute" : 10000,
"safeAttackRatio" : 1.1, "safeAttackRatio" : 1.1,
@@ -98,13 +101,14 @@
"maxPriorityPass" : 10, "maxPriorityPass" : 10,
"mainHeroTurnDistanceLimit" : 10, "mainHeroTurnDistanceLimit" : 10,
"scoutHeroTurnDistanceLimit" : 5, "scoutHeroTurnDistanceLimit" : 5,
"threatTurnDistanceLimit" : 5,
"maxGoldPressure" : 0.3, "maxGoldPressure" : 0.3,
"updateHitmapOnTileReveal" : false, "updateHitmapOnTileReveal" : true,
"useTroopsFromGarrisons" : true, "useTroopsFromGarrisons" : true,
"openMap": true, "openMap": true,
"allowObjectGraph": true, "allowObjectGraph": false,
"pathfinderBucketsCount" : 4, // old value: 3, "pathfinderBucketsCount" : 3,
"pathfinderBucketSize" : 8, // old value: 7, "pathfinderBucketSize" : 7,
"retreatThresholdRelative" : 0.3, "retreatThresholdRelative" : 0.3,
"retreatThresholdAbsolute" : 10000, "retreatThresholdAbsolute" : 10000,
"safeAttackRatio" : 1.1, "safeAttackRatio" : 1.1,
@@ -118,13 +122,14 @@
"maxPriorityPass" : 10, "maxPriorityPass" : 10,
"mainHeroTurnDistanceLimit" : 10, "mainHeroTurnDistanceLimit" : 10,
"scoutHeroTurnDistanceLimit" : 5, "scoutHeroTurnDistanceLimit" : 5,
"threatTurnDistanceLimit" : 5,
"maxGoldPressure" : 0.3, "maxGoldPressure" : 0.3,
"updateHitmapOnTileReveal" : false, "updateHitmapOnTileReveal" : true,
"useTroopsFromGarrisons" : true, "useTroopsFromGarrisons" : true,
"openMap": true, "openMap": true,
"allowObjectGraph": true, "allowObjectGraph": false,
"pathfinderBucketsCount" : 4, // old value: 3, "pathfinderBucketsCount" : 3,
"pathfinderBucketSize" : 8, // old value: 7, "pathfinderBucketSize" : 7,
"retreatThresholdRelative" : 0.3, "retreatThresholdRelative" : 0.3,
"retreatThresholdAbsolute" : 10000, "retreatThresholdAbsolute" : 10000,
"safeAttackRatio" : 1.1, "safeAttackRatio" : 1.1,

View File

@@ -4115,12 +4115,10 @@ void CGameHandler::changeFogOfWar(const std::unordered_set<int3> &tiles, PlayerC
for (auto tile : observedTiles) for (auto tile : observedTiles)
vstd::erase_if_present (fow.tiles, tile); vstd::erase_if_present (fow.tiles, tile);
if (fow.tiles.empty())
return;
} }
sendAndApply(fow); if (!fow.tiles.empty())
sendAndApply(fow);
} }
const CGHeroInstance * CGameHandler::getVisitingHero(const CGObjectInstance *obj) const CGHeroInstance * CGameHandler::getVisitingHero(const CGObjectInstance *obj)

View File

@@ -618,7 +618,9 @@ void PlayerMessageProcessor::cheatMapReveal(PlayerColor player, bool reveal)
fc.tiles.insert(hlp_tab, hlp_tab + lastUnc); fc.tiles.insert(hlp_tab, hlp_tab + lastUnc);
delete [] hlp_tab; delete [] hlp_tab;
gameHandler->sendAndApply(fc);
if (!fc.tiles.empty())
gameHandler->sendAndApply(fc);
} }
void PlayerMessageProcessor::cheatPuzzleReveal(PlayerColor player) void PlayerMessageProcessor::cheatPuzzleReveal(PlayerColor player)