1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
#include <fstream>
#include <sstream>
#include "IncExternAI.h"
#include "IncGlobalAI.h"
CCommandTracker::~CCommandTracker() {
std::ofstream fs;
std::stringstream ss;
std::string s = ai->GetLogger()->GetLogName() + ".cmdstats";
std::map<int, int>::const_iterator it;
for (it = cmdsPerFrame.begin(); it != cmdsPerFrame.end(); it++) {
ss << it->first << "\t" << it->second << "\n";
}
fs.open(s.c_str(), std::ios::out);
fs << ss.str();
fs.close();
}
void CCommandTracker::Update(int currFrame) {
if (currFrame <= 0)
return;
if ((currFrame % 1800) == 0 && !cmdsPerFrame.empty()) {
const int numFrames = cmdsPerFrame.size();
const float avgCmdsRegFrames = totalNumCmds / float(numFrames);
const float avgCmdsAllFrames = totalNumCmds / float(currFrame);
const float avgCmdSize = totalCmdSize / float(totalNumCmds);
std::stringstream msg;
msg << "[CCommandTracker::Update()][frame=" << currFrame << "]\n";
msg << "\tnumber of frames registered: " << numFrames << "\n";
msg << "\t(avg.) number of commands (registered frames): " << avgCmdsRegFrames << "\n";
msg << "\t(avg.) number of commands (all elapsed frames): " << avgCmdsAllFrames << "\n";
msg << "\t(avg.) number of parameters per command: " << avgCmdSize << "\n";
msg << "\t(max.) number of commands, peak frame: "
<< maxCmdsPerFrame << ", "
<< peakCmdFrame << "\n";
ai->GetLogger()->Log(msg.str());
}
}
void CCommandTracker::GiveOrder(int id, Command* c) {
const int f = ai->cb->GetCurrentFrame();
if (cmdsPerFrame.find(f) == cmdsPerFrame.end()) {
cmdsPerFrame[f] = 1;
} else {
cmdsPerFrame[f] += 1;
}
if (cmdsPerFrame[f] > maxCmdsPerFrame) {
maxCmdsPerFrame = cmdsPerFrame[f];
peakCmdFrame = f;
}
totalNumCmds += 1;
totalCmdSize += c->GetNumParams();
if (!ai->GetUnit(id)->isDead) {
ai->cb->GiveOrder(id, c);
}
}
|