Looking for pgn format converter tool

Discussion of anything and everything relating to chess playing software and machines.

Moderator: Ras

Ferdy
Posts: 4852
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Looking for pgn format converter tool

Post by Ferdy »

stegemma wrote:How do you want to traslate strings like this one?

Code: Select all

{[%emt 0:00:00] -M-1382/5}
It can be done easly.
For crafty that should be,
-M-1382 = -32766, it is mate in 1. Inverting and dividing by 100 that would be {327.66/5}

The others.
-M-1381 = -32764
-M-1380 = -32762
General formula.
eval = 32766 - (1382-x) * 2
x = 1380
eval = 32766 - (1382-1380) * 2
eval = 32762
User avatar
Ajedrecista
Posts: 2194
Joined: Wed Jul 13, 2011 9:04 pm
Location: Madrid, Spain.

Re: Looking for pgn format converter tool.

Post by Ajedrecista »

Hello Ferdinand:
Ferdy wrote:
stegemma wrote:How do you want to traslate strings like this one?

Code: Select all

{[%emt 0:00:00] -M-1382/5}
It can be done easly.
For crafty that should be,
-M-1382 = -32766, it is mate in 1. Inverting and dividing by 100 that would be {327.66/5}

The others.
-M-1381 = -32764
-M-1380 = -32762
General formula.
eval = 32766 - (1382-x) * 2
x = 1380
eval = 32766 - (1382-1380) * 2
eval = 32762
There are two threads about this issue started by user Les:

PGN notation confusion

Question re evalaution format in a pgn game

------------------------

What about negative values (i.e. -1382) in your proposed general formula? If I am not wrong: 32766 - 2·[1382 - (-1382)] = 38294 =/= -32766. I proposed the following formula:

Code: Select all

eval(cp) = 30000*sign(x) + 2*[x + sign(x)] = 30000*x/abs(x) + 2*[x + x/abs(x)]

eval(pawns) = 0.01*eval(cp) = 300*x/abs(x) + 0.02*[x + x/abs(x)]
In this case: 30000*sign(-1382) + 2*[-1382 + sign(-1382)] = 30000*(-1) + 2*(-1382 -1) = -32766.

If you want to convert evals to white POV is other matter. But if Crafty is white and is losing, then the score is negative, hence my proposed formula.

Regards from Spain.

Ajedrecista.
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: Looking for pgn format converter tool

Post by tpetzke »

Hi,

you can have a look at my current try with a GUI. It is work in progress and not even close to be finished but you can load a PGN and save it back and hopefully it has converted the %emt stuff then. It is not very robust yet (e.g. it fails to load a pgn file if it is not terminated with an empty line like the standard demands)

http://www.fam-petzke.de/downloads/shaker.zip

Thomas...
Thomas...

=======
http://macechess.blogspot.com - iCE Chess Engine
Ferdy
Posts: 4852
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Looking for pgn format converter tool.

Post by Ferdy »

Ajedrecista wrote:Hello Ferdinand:
Ferdy wrote:
stegemma wrote:How do you want to traslate strings like this one?

Code: Select all

{[%emt 0:00:00] -M-1382/5}
It can be done easly.
For crafty that should be,
-M-1382 = -32766, it is mate in 1. Inverting and dividing by 100 that would be {327.66/5}

The others.
-M-1381 = -32764
-M-1380 = -32762
General formula.
eval = 32766 - (1382-x) * 2
x = 1380
eval = 32766 - (1382-1380) * 2
eval = 32762
There are two threads about this issue started by user Les:

PGN notation confusion

Question re evalaution format in a pgn game

------------------------

What about negative values (i.e. -1382) in your proposed general formula? If I am not wrong: 32766 - 2·[1382 - (-1382)] = 38294 =/= -32766. I proposed the following formula:

Code: Select all

eval(cp) = 30000*sign(x) + 2*[x + sign(x)] = 30000*x/abs(x) + 2*[x + x/abs(x)]

eval(pawns) = 0.01*eval(cp) = 300*x/abs(x) + 0.02*[x + x/abs(x)]
In this case: 30000*sign(-1382) + 2*[-1382 + sign(-1382)] = 30000*(-1) + 2*(-1382 -1) = -32766.

If you want to convert evals to white POV is other matter. But if Crafty is white and is losing, then the score is negative, hence my proposed formula.

Regards from Spain.

Ajedrecista.
I knew part of those threads, I actually run crafty on that mate position and it returns 32766 for mate in 1. Then work out some generalization. This is from Frank's pgn file which is coming from Shredder gui.
Yes that formula is intended for positive values, which I believe Stefano will be able to figure out for negative ones. But your formula looks nicer :) .
Ferdy
Posts: 4852
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Looking for pgn format converter tool

Post by Ferdy »

tpetzke wrote:Hi,

you can have a look at my current try with a GUI. It is work in progress and not even close to be finished but you can load a PGN and save it back and hopefully it has converted the %emt stuff then. It is not very robust yet (e.g. it fails to load a pgn file if it is not terminated with an empty line like the standard demands)

Thomas...
Looks good. Tried saving 1 game and its format is white POV. I was looking for side POV which is what GameAnalyser would like to use. The converter should also be capable of converting some games in a pgn file.
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: Looking for pgn format converter tool

Post by tpetzke »

It currently only replaces the %eval and %emt stuff into something more readable, it does not touch the value itself except for centi pawn to pawn conversion. So it will keep the value whatever it is.

Is it standardized that %eval always uses White POV, I was not able to find that somewhere. If so I could change the converter.

Thomas...
Thomas...

=======
http://macechess.blogspot.com - iCE Chess Engine
Ferdy
Posts: 4852
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Looking for pgn format converter tool

Post by Ferdy »

tpetzke wrote:It currently only replaces the %eval and %emt stuff into something more readable, it does not touch the value itself except for centi pawn to pawn conversion. So it will keep the value whatever it is.
Since you are designing a gui, would suggest to separate the eval and the depth to make it more readable like, [%eval 50][%depth 18], and not [%eval 50,18]. The pgn specs and guide supplement, was actually good and can still be human readable if the embeded command operand is not abused. That operand '50,18' is inhuman.
Is it standardized that %eval always uses White POV, I was not able to find that somewhere. If so I could change the converter.

Thomas...
I believe it is not standard.
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: Looking for pgn format converter tool

Post by tpetzke »

Since you are designing a gui, would suggest to separate the eval and the depth to make it more readable like, [%eval 50][%depth 18], and not [%eval 50,18]
I actually replace it into { +0.50/18 0.14s }

This is the format cutechess-cli outputs, I think Arena does it too in this form. And my future GUI will also write it in this form. I want to get rid of those %tag and not just replace it with something else.

I have written a small parser for this format a while back and it is actually not so difficult to parse.
Thomas...

=======
http://macechess.blogspot.com - iCE Chess Engine
User avatar
hgm
Posts: 28461
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Looking for pgn format converter tool

Post by hgm »

You should beware that there is no general formula for the M-nnn nonsense. It is not part of the [%eval] format, but a situation-dependent error in it. It arises from having defined a wrong mating score in the WB2UCI adapter, i.e. with a value smaller than what the engine is actually using. So it is not even reproducible with the same engine; when you run Crafty in another situation (with other WB2UCI settings) the conversion to real mating scores would have to be completely different.

As to the score POV, it might be worth noting that last time I looked, Crafty was non-compliant in this respect: unlike other engines, it reports scores from white POV. WinBoard has a work-around option first/secondScoreAbs to corract that, but I am not sure WB2UCI can do that too, and even if it can, people producing the %eval PGNs might not have set it properly. So this could be a Crafty-specific problem.
tpetzke wrote: I actually replace it into { +0.50/18 0.14s }

This is the format cutechess-cli outputs, I think Arena does it too in this form. And my future GUI will also write it in this form. I want to get rid of those %tag and not just replace it with something else.
.
WinBoard/XBoard uses a format like that too, although I am not sure about the padding with spaces, and the 's' for seconds. It seems to me that, when embedded between moves, the spaces would actually decrease readability. The use of a unit on the time seems redundant, and just wastes space. a plain real or integer number there could always be taken to mean seconds, as for minutes the notation min:sec could be used. There is also no unit (Pawn or cP) on the score...
User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 10:05 pm
Location: Italy
Full name: Stefano Gemma

Re: Looking for pgn format converter tool.

Post by stegemma »

It seems that there's not a standard for mate values. I will change somehow my preprocessor. Just for reference, here's the relevant part of the code:

Code: Select all

  }else if(sOptions[0]=='X')
  {
    clsString sFileIn  = argv[++p];
    clsString sFileOut = argv[++p];
    if(sOptions.Is("1", tscContains))
    {
      bool bTrimNewLine = sOptions.Is("T", tscContains);
      // ... 71. Nd2 {[%eval -331,19] [%emt 0:00:10]} Kg6 {[%eval -670,33] [%emt 0:00:11] (Kg5)}
      // ... 71. Nd2 {-3.31/19} Kg6 {+6.70/33}
      clsString sIn;   sIn.LoadFromFile(sFileIn);
      int iFound = 0;
      const clsString sTag("[%eval");
      const int taglen = sTag.Length();
      while(true)
      {
        iFound = sIn.FindString(sTag, iFound, true);
        if(iFound>=0)
        {
          int iStart = iFound, iEnd=iFound;
          clsString sVal = sIn.Token(']', iEnd);
          sIn.Token('}', iEnd);
          if(iEnd<0) iEnd = sIn.Length() - 1;
          sIn.Remove(iStart, iEnd-iStart-1);
          bool bWhite = true;
          for(int i=iStart-1; i>=0; i--)
          {
            if(sIn[i]=='}') // 1. e4 {} e5 {}
            {
              bWhite = false;
              break;
            }
            if(sIn[i]=='.' && sIn[i-1]>='0' && sIn[i-1]<='9')
            {
              bWhite = sIn[i+1]!='.';  // 1... e5
              break;
            }
          }
          clsString sNum = sVal.xMid(taglen).Replace("\r", "").Replace("\n", "").Trim();
          double val = sNum.TokenLeft(',').GetDouble(0)/100.0;
          if(!bWhite && val!=0.0) val = -val;
          sIn.Insert(iStart, clsString(val, 2) + "/" + sNum.TokenRight(',').Trim());
          iFound = iStart;
        }else break;
      }
      if(bTrimNewLine)
      {
        int delta = 5;
        int iFound = sIn.FindString("]\r\n\r\n");
        if(iFound<0) { iFound = sIn.FindString("] \r\n\r\n"); delta = 6; }
        if(iFound>=0)
        {
          iFound += delta;
          sIn = sIn.xLeft(iFound) + sIn.xMid(iFound).Replace("\r\n", "");
        }
      }
      sIn.Replace("{ ", "{").Replace("{ ", "{").SaveToFile(sFileOut);
    }
  }
As you can see, I've done a fast function while working and it's very far to be a good programming example. ;)

My class clsString should be easly converted to std::string but maybe it's faster to rewrite all the code.