mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
A bit of clean-up for merge
Set back trace level to 0 Removed EvaluationContexts that weren't used Encapsulated many debug-messages behinde trace-levels
This commit is contained in:
@@ -350,6 +350,11 @@ void Nullkiller::makeTurn()
|
||||
|
||||
const int MAX_DEPTH = 10;
|
||||
|
||||
resetAiState();
|
||||
|
||||
Goals::TGoalVec bestTasks;
|
||||
|
||||
#if NKAI_TRACE_LEVEL >= 1
|
||||
float totalHeroStrength = 0;
|
||||
int totalTownLevel = 0;
|
||||
for (auto heroInfo : cb->getHeroesInfo())
|
||||
@@ -360,12 +365,8 @@ void Nullkiller::makeTurn()
|
||||
{
|
||||
totalTownLevel += townInfo->getTownLevel();
|
||||
}
|
||||
|
||||
resetAiState();
|
||||
|
||||
Goals::TGoalVec bestTasks;
|
||||
|
||||
logAi->info("Beginning: Strength: %f Townlevel: %d Resources: %s", totalHeroStrength, totalTownLevel, cb->getResourceAmount().toString());
|
||||
#endif
|
||||
for(int i = 1; i <= settings->getMaxPass() && cb->getPlayerStatus(playerID) == EPlayerStatus::INGAME; i++)
|
||||
{
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
@@ -385,7 +386,9 @@ void Nullkiller::makeTurn()
|
||||
|
||||
if(bestTask->priority > 0)
|
||||
{
|
||||
#if NKAI_TRACE_LEVEL >= 1
|
||||
logAi->info("Pass %d: Performing task %s with prio: %d", i, bestTask->toString(), bestTask->priority);
|
||||
#endif
|
||||
if(!executeTask(bestTask))
|
||||
return;
|
||||
|
||||
@@ -485,7 +488,9 @@ void Nullkiller::makeTurn()
|
||||
|
||||
continue;
|
||||
}
|
||||
#if NKAI_TRACE_LEVEL >= 1
|
||||
logAi->info("Pass %d: Performing prio %d task %s with prio: %d", i, prioOfTask, bestTask->toString(), bestTask->priority);
|
||||
#endif
|
||||
if(!executeTask(bestTask))
|
||||
{
|
||||
if(hasAnySuccess)
|
||||
@@ -501,6 +506,17 @@ void Nullkiller::makeTurn()
|
||||
if(!hasAnySuccess)
|
||||
{
|
||||
logAi->trace("Nothing was done this turn. Ending turn.");
|
||||
#if NKAI_TRACE_LEVEL >= 1
|
||||
for (auto heroInfo : cb->getHeroesInfo())
|
||||
{
|
||||
totalHeroStrength += heroInfo->getTotalStrength();
|
||||
}
|
||||
for (auto townInfo : cb->getTownsInfo())
|
||||
{
|
||||
totalTownLevel += townInfo->getTownLevel();
|
||||
}
|
||||
logAi->info("End: Strength: %f Townlevel: %d Resources: %s", totalHeroStrength, totalTownLevel, cb->getResourceAmount().toString());
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -509,15 +525,6 @@ void Nullkiller::makeTurn()
|
||||
logAi->warn("Maxpass exceeded. Terminating AI turn.");
|
||||
}
|
||||
}
|
||||
for (auto heroInfo : cb->getHeroesInfo())
|
||||
{
|
||||
totalHeroStrength += heroInfo->getTotalStrength();
|
||||
}
|
||||
for (auto townInfo : cb->getTownsInfo())
|
||||
{
|
||||
totalTownLevel += townInfo->getTownLevel();
|
||||
}
|
||||
logAi->info("End: Strength: %f Townlevel: %d Resources: %s", totalHeroStrength, totalTownLevel, cb->getResourceAmount().toString());
|
||||
}
|
||||
|
||||
bool Nullkiller::areAffectedObjectsPresent(Goals::TTask task) const
|
||||
@@ -611,10 +618,10 @@ bool Nullkiller::handleTrading()
|
||||
TResources required = buildAnalyzer->getTotalResourcesRequired();
|
||||
TResources income = buildAnalyzer->getDailyIncome();
|
||||
TResources available = cb->getResourceAmount();
|
||||
|
||||
#if NKAI_TRACE_LEVEL >= 2
|
||||
logAi->debug("Available %s", available.toString());
|
||||
logAi->debug("Required %s", required.toString());
|
||||
|
||||
#endif
|
||||
int mostWanted = -1;
|
||||
int mostExpendable = -1;
|
||||
float minRatio = std::numeric_limits<float>::max();
|
||||
@@ -660,9 +667,9 @@ bool Nullkiller::handleTrading()
|
||||
mostExpendable = i;
|
||||
}
|
||||
}
|
||||
|
||||
#if NKAI_TRACE_LEVEL >= 2
|
||||
logAi->debug("mostExpendable: %d mostWanted: %d", mostExpendable, mostWanted);
|
||||
|
||||
#endif
|
||||
if (mostExpendable == mostWanted || mostWanted == -1 || mostExpendable == -1)
|
||||
return false;
|
||||
|
||||
@@ -674,7 +681,9 @@ bool Nullkiller::handleTrading()
|
||||
if (toGive && toGive <= available[mostExpendable]) //don't try to sell 0 resources
|
||||
{
|
||||
cb->trade(m->getObjInstanceID(), EMarketMode::RESOURCE_RESOURCE, GameResID(mostExpendable), GameResID(mostWanted), toGive);
|
||||
#if NKAI_TRACE_LEVEL >= 1
|
||||
logAi->info("Traded %d of %s for %d of %s at %s", toGive, mostExpendable, toGet, mostWanted, obj->getObjectName());
|
||||
#endif
|
||||
haveTraded = true;
|
||||
shouldTryToTrade = true;
|
||||
}
|
||||
|
||||
@@ -62,8 +62,6 @@ EvaluationContext::EvaluationContext(const Nullkiller* ai)
|
||||
threatTurns(INT_MAX),
|
||||
involvesSailing(false),
|
||||
isTradeBuilding(false),
|
||||
isChain(false),
|
||||
isEnemy(false),
|
||||
isExchange(false)
|
||||
{
|
||||
}
|
||||
@@ -1031,7 +1029,6 @@ public:
|
||||
vstd::amax(evaluationContext.danger, path.getTotalDanger());
|
||||
evaluationContext.movementCost += path.movementCost();
|
||||
evaluationContext.closestWayRatio = chain.closestWayRatio;
|
||||
evaluationContext.isChain = true;
|
||||
|
||||
std::map<const CGHeroInstance *, float> costsPerHero;
|
||||
|
||||
@@ -1069,8 +1066,6 @@ public:
|
||||
evaluationContext.conquestValue += evaluationContext.evaluator.getConquestValue(target);
|
||||
evaluationContext.goldCost += evaluationContext.evaluator.getGoldCost(target, hero, army);
|
||||
evaluationContext.armyInvolvement += army->getArmyCost();
|
||||
if (target->tempOwner != PlayerColor::NEUTRAL)
|
||||
evaluationContext.isEnemy = true;
|
||||
}
|
||||
|
||||
vstd::amax(evaluationContext.armyLossPersentage, path.getTotalArmyLoss() / (double)path.getHeroStrength());
|
||||
@@ -1119,9 +1114,6 @@ public:
|
||||
evaluationContext.movementCostByRole[role] += objInfo.second.movementCost / boost;
|
||||
evaluationContext.movementCost += objInfo.second.movementCost / boost;
|
||||
|
||||
if (target->tempOwner != PlayerColor::NEUTRAL)
|
||||
evaluationContext.isEnemy = true;
|
||||
|
||||
vstd::amax(evaluationContext.turn, objInfo.second.turn / boost);
|
||||
|
||||
boost <<= 1;
|
||||
@@ -1372,7 +1364,7 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
|
||||
{
|
||||
float score = 0;
|
||||
float maxWillingToLose = ai->cb->getTownsInfo().empty() ? 1 : 0.25;
|
||||
|
||||
#if NKAI_TRACE_LEVEL >= 2
|
||||
logAi->trace("BEFORE: priorityTier %d, Evaluated %s, loss: %f, turn: %d, turns main: %f, scout: %f, gold: %f, cost: %d, army gain: %f, army growth: %f skill: %f danger: %d, threatTurns: %d, threat: %d, role: %s, strategical value: %f, conquest value: %f cwr: %f, fear: %f, isDefend: %d, fuzzy: %f",
|
||||
priorityTier,
|
||||
task->toString(),
|
||||
@@ -1395,6 +1387,7 @@ float PriorityEvaluator::evaluate(Goals::TSubgoal task, int priorityTier)
|
||||
evaluationContext.enemyHeroDangerRatio,
|
||||
evaluationContext.isDefend,
|
||||
fuzzyResult);
|
||||
#endif
|
||||
|
||||
switch (priorityTier)
|
||||
{
|
||||
|
||||
@@ -79,8 +79,6 @@ struct DLL_EXPORT EvaluationContext
|
||||
TResources buildingCost;
|
||||
bool involvesSailing;
|
||||
bool isTradeBuilding;
|
||||
bool isChain;
|
||||
bool isEnemy;
|
||||
bool isExchange;
|
||||
|
||||
EvaluationContext(const Nullkiller * ai);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
#define NKAI_PATHFINDER_TRACE_LEVEL 0
|
||||
constexpr int NKAI_GRAPH_TRACE_LEVEL = 0;
|
||||
#define NKAI_TRACE_LEVEL 2
|
||||
#define NKAI_TRACE_LEVEL 0
|
||||
|
||||
#include "../../../lib/pathfinder/CGPathNode.h"
|
||||
#include "../../../lib/pathfinder/INodeStorage.h"
|
||||
|
||||
Reference in New Issue
Block a user