1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

BattleAI: log time to make a decission

This commit is contained in:
Andrii Danylchenko 2023-08-08 18:54:37 +03:00
parent 3f6cbc6312
commit e7394ad20c

View File

@ -254,6 +254,13 @@ void CBattleAI::yourTacticPhase(int distance)
cb->battleMakeTacticAction(BattleAction::makeEndOFTacticPhase(cb->battleGetTacticsSide())); cb->battleMakeTacticAction(BattleAction::makeEndOFTacticPhase(cb->battleGetTacticsSide()));
} }
uint64_t timeElapsed(std::chrono::time_point<std::chrono::high_resolution_clock> start)
{
auto end = std::chrono::high_resolution_clock::now();
return std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
}
void CBattleAI::activeStack( const CStack * stack ) void CBattleAI::activeStack( const CStack * stack )
{ {
LOG_TRACE_PARAMS(logAi, "stack: %s", stack->nodeName()); LOG_TRACE_PARAMS(logAi, "stack: %s", stack->nodeName());
@ -261,6 +268,8 @@ void CBattleAI::activeStack( const CStack * stack )
BattleAction result = BattleAction::makeDefend(stack); BattleAction result = BattleAction::makeDefend(stack);
setCbc(cb); //TODO: make solid sure that AIs always use their callbacks (need to take care of event handlers too) setCbc(cb); //TODO: make solid sure that AIs always use their callbacks (need to take care of event handlers too)
auto start = std::chrono::high_resolution_clock::now();
try try
{ {
if(stack->creatureId() == CreatureID::CATAPULT) if(stack->creatureId() == CreatureID::CATAPULT)
@ -276,6 +285,8 @@ void CBattleAI::activeStack( const CStack * stack )
attemptCastingSpell(); attemptCastingSpell();
logAi->trace("Spellcast attempt completed in %lld", timeElapsed(start));
if(cb->battleIsFinished() || !stack->alive()) if(cb->battleIsFinished() || !stack->alive())
{ {
//spellcast may finish battle or kill active stack //spellcast may finish battle or kill active stack
@ -312,6 +323,8 @@ void CBattleAI::activeStack( const CStack * stack )
movesSkippedByDefense = 0; movesSkippedByDefense = 0;
} }
logAi->trace("BattleAI decission made in %lld", timeElapsed(start));
cb->battleMakeUnitAction(result); cb->battleMakeUnitAction(result);
} }