Trouble scanning/parsing log file

Discussion of chess software programming and technical issues.

Moderator: Ras

Hart

Trouble scanning/parsing log file

Post by Hart »

I am looking for some simple C++ code that will parse a log file, specifically Analyses.log created by Arena, and give scores in percentages for the positions solved / total position, for all engines in the log file. Here is how I think it should work:

Read lines 1 - n_Lines
For every line check to see if last two words are "matching moves"
If true, it will be in this format: "Engine Name: 8 of 10 matching moves"
Check if "Engine Name" already exists in struct, and if not create, increment n_matched, and pTotal for this engine.

If I had this portion I could write the remaining that would output the results to a new log file. Any help would be greatly appreciated.
Hart

Re: Trouble scanning/parsing log file

Post by Hart »

Here it is. This will output statistics from Analyses.log, created by Arena.
Output format is:

Engine Solved Positions %
--------------------------------------------------------
Rybka 3 769 1212 63.45
Naum 742 1212 61.22
Cyclone 3.0 900 1500 60.00
Glaurung-w64 896 1500 59.73


Anyways, these are the results I have so far for the engines. I had them auto-analyzing 6 (pseudo random) moves from 250 random high level correspondence games, each. I know the sample size is small (total engines), but when I input their scores, and their ratings from CCRL 40/4, a quadratic regression yields r2=.998. I will be testing Fruit and Spike when Rybka and Naum both reach 1500 positions. All engines run at threads=2 so I can run two concurrently on my quad.



#include <fstream>
#include <string>
#include <iomanip>
#include <iostream>

using namespace std;

int main() {

double d;

int i, j, k,
n_engines=0,
scores[64][2]={0};

ifstream in;

string tmp, str, engines[64], name;

in.open("Analyses.log");
if (!in) {
cout << "Error: Cannot open Analyses.log. Exiting...\n";
return 1;
}

getline(in,str);
while (in) {

if (str.find("matching moves", 0) != string::npos) {

tmp = str;
str.erase(str.find(":", 0), str.size() - str.find(":", 0));

name = str;
str = tmp;

str.erase(0, str.find(":",0) + 2);
str.erase(str.find(" m",0), str.size() - str.find(" m",0));

tmp = str;

str.erase(str.find(" ",0), str.size() - str.find(" ",0));
tmp.erase(0, tmp.find(" of ", 0) + 4);

j = atoi(str.c_str());
k = atoi(tmp.c_str());

int found = 0;
for (i=0; i < n_engines; i++) {
if (engines == name) {
found = 1;
scores[0] += j; scores[1] += k;
}
}

if (!found) {
engines[n_engines] = name;
scores[n_engines][0] += j; scores[n_engines][1] += k;
n_engines++;

}
}

getline(in,str);
}

cout << "\nEngine Solved Positions %\n"
<< "--------------------------------------------------------\n";

for (i=0; i<n_engines; i++) {
d = (float) 100 * scores[0] / scores[1];
cout << setw(21) << left << engines << setw(10) << right << scores[0]
<< setw(13) << scores[1] << " " << setiosflags(ios::fixed)
<< setprecision(2) << setw(9) << d << endl;
}

return 0;
}