Polyglot and make-book

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Polyglot and make-book

Post by Rebel »

I am trying to convert my ancient (2 byte per move Spracklen) book format to polyglot (after first having port the book to PGN) but run into the following problem:

[Event "2"]
[Site "?"]
[Date "2016.02.18"]
[Round "1"]
[White "Book"]
[Black "Book"]
[Result "*"]
[BlackElo "?"]
[WhiteElo "?"]

1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6 5. O-O b5 6. Bb3 Bb7 7. Re1 Bc5
8. c3 d6 9. d4 Bb6 10. Bg5 h6 11. Bh4 O-O 12. a4 exd4 13. axb5 axb5 14.
Rxa8 Bxa8 15. cxd4 Re8 16. Nc3 Na5 17. Bxf6 Qxf6 18. Bc2 { - } 18... b4
19. Na4 Ba7 20. Qd3 Nc6 21. e5 dxe5 22. dxe5 Qf4 23. Qh7+ Kf8 24.
Qh8+ Ke7 25. Qxg7 Nd4 26. Qf6+ Qxf6 27. exf6+ Kf8 28. Rxe8+ Kxe8 *

The move 18.Bc2 is marked as "don't play" but of course after conversion the created polyglot book is happy to play 18.Bc2

Has polyglot make-book an option that can skip (marked) moves or set the weight to "0" ?
ZirconiumX
Posts: 1334
Joined: Sun Jul 17, 2011 11:14 am

Re: Polyglot and make-book

Post by ZirconiumX »

Rebel wrote:I am trying to convert my ancient (2 byte per move Spracklen) book format to polyglot (after first having port the book to PGN) but run into the following problem:

[Event "2"]
[Site "?"]
[Date "2016.02.18"]
[Round "1"]
[White "Book"]
[Black "Book"]
[Result "*"]
[BlackElo "?"]
[WhiteElo "?"]

1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 4. Ba4 Nf6 5. O-O b5 6. Bb3 Bb7 7. Re1 Bc5
8. c3 d6 9. d4 Bb6 10. Bg5 h6 11. Bh4 O-O 12. a4 exd4 13. axb5 axb5 14.
Rxa8 Bxa8 15. cxd4 Re8 16. Nc3 Na5 17. Bxf6 Qxf6 18. Bc2 { - } 18... b4
19. Na4 Ba7 20. Qd3 Nc6 21. e5 dxe5 22. dxe5 Qf4 23. Qh7+ Kf8 24.
Qh8+ Ke7 25. Qxg7 Nd4 26. Qf6+ Qxf6 27. exf6+ Kf8 28. Rxe8+ Kxe8 *

The move 18.Bc2 is marked as "don't play" but of course after conversion the created polyglot book is happy to play 18.Bc2

Has polyglot make-book an option that can skip (marked) moves or set the weight to "0" ?
I believe because of the way the Polyglot system works (hash-key, move pairs), the only solution is to not include the "don't play" moves, so it won't play them.

Matthew:out
Some believe in the almighty dollar.

I believe in the almighty printf statement.
Zenmastur
Posts: 919
Joined: Sat May 31, 2014 8:28 am

Re: Polyglot and make-book

Post by Zenmastur »

I think if you make the black and white books separately and then combine them this problem is solved. This will require some pre-processing of the PGN file I think.

Regards,

Forrest
Only 2 defining forces have ever offered to die for you.....Jesus Christ and the American Soldier. One died for your soul, the other for your freedom.
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Polyglot and make-book

Post by hgm »

I am surprised any of the moves get into the book. I was under the impression that Polyglot kept statistics on (position, move) pairs as the number of half-points scored with it. Your PGN does not specify a result, so I would expect that to count as 0 half points. Does it count it as a draw instead? What is the weight this move eventually gets in the book?

BTW, it is easy enough to make a Polyglot-book creator that would pay attention to {-} comments, and ignore the preceding move. Just modify WinBoard's 'Save games as book' command. The existing code to add a game to the book is:

Code: Select all

void
AddGameToBook (int always)
{
    int i, result;

    if(!mcMode && !always) return;

    InitMemBook();
    switch(gameInfo.result) {
      case GameIsDrawn: result = 1; break;
      case WhiteWins:   result = 2; break;
      case BlackWins:   result = 0; break;
      default: return; // don't treat games with unknown result
    }

    if(appData.debugMode) fprintf(debugFP, "add game to book (%d-%d)\n", backwardMostMove, forwardMostMove);
    for&#40;i=backwardMostMove; i<forwardMostMove && i < 2*appData.bookDepth; i++)
        AddToBook&#40;i, WhiteOnMove&#40;i&#41; ? result &#58; 2-result&#41;; // flip result when black moves
&#125;
It would just be a matter of making the execution of AddToBook in the loop over game moves dependent on commentList (or is it [i-1]?), testing if it is NULL, and if not, if commentList[0] == '-'.
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Polyglot and make-book

Post by Rebel »

hgm wrote:I am surprised any of the moves get into the book. I was under the impression that Polyglot kept statistics on (position, move) pairs as the number of half-points scored with it. Your PGN does not specify a result, so I would expect that to count as 0 half points. Does it count it as a draw instead? What is the weight this move eventually gets in the book?
I see, I did not realize the game result had influence. I will add a game result, retry and see what happens.


BTW, it is easy enough to make a Polyglot-book creator that would pay attention to {-} comments, and ignore the preceding move. Just modify WinBoard's 'Save games as book' command. The existing code to add a game to the book is:

Code: Select all

void
AddGameToBook &#40;int always&#41;
&#123;
    int i, result;

    if&#40;!mcMode && !always&#41; return;

    InitMemBook&#40;);
    switch&#40;gameInfo.result&#41; &#123;
      case GameIsDrawn&#58; result = 1; break;
      case WhiteWins&#58;   result = 2; break;
      case BlackWins&#58;   result = 0; break;
      default&#58; return; // don't treat games with unknown result
    &#125;

    if&#40;appData.debugMode&#41; fprintf&#40;debugFP, "add game to book (%d-%d&#41;\n", backwardMostMove, forwardMostMove&#41;;
    for&#40;i=backwardMostMove; i<forwardMostMove && i < 2*appData.bookDepth; i++)
        AddToBook&#40;i, WhiteOnMove&#40;i&#41; ? result &#58; 2-result&#41;; // flip result when black moves
&#125;
It would just be a matter of making the execution of AddToBook in the loop over game moves dependent on commentList (or is it [i-1]?), testing if it is NULL, and if not, if commentList[0] == '-'.

Yes, would be a nice feature :wink:
PK
Posts: 893
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: Polyglot and make-book

Post by PK »

I guess Polyglot treats * in result tag the same way as it would treat a draw.

Perhaps the way to convert the book would be to replace * with 1/2-1/2 when there are no {-} signs, to 1-0 if {-} occurs after a black move and to 0-1 if there is a {-} after a white move (assuming there are no games with {-} moves for both sides)
User avatar
Steve Maughan
Posts: 1221
Joined: Wed Mar 08, 2006 8:28 pm
Location: Florida, USA

Re: Polyglot and make-book

Post by Steve Maughan »

Hi Ed,

My video about creating Polyglot opening books may be helpful.

http://www.chessprogramming.net/create- ... ning-book/

Steve
http://www.chessprogramming.net - Maverick Chess Engine
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Polyglot and make-book

Post by hgm »

PK wrote:Perhaps the way to convert the book would be to replace * with 1/2-1/2 when there are no {-} signs, to 1-0 if {-} occurs after a black move and to 0-1 if there is a {-} after a white move (assuming there are no games with {-} moves for both sides)
The problem is that usually you would want the other moves of that side (not marked with {-}) to appear in the book.
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Polyglot and make-book

Post by Rebel »

PK wrote:I guess Polyglot treats * in result tag the same way as it would treat a draw.

Perhaps the way to convert the book would be to replace * with 1/2-1/2 when there are no {-} signs, to 1-0 if {-} occurs after a black move and to 0-1 if there is a {-} after a white move (assuming there are no games with {-} moves for both sides)
Did exactly that and removed the {-} thing. Seems to work :wink:
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Polyglot and make-book

Post by Rebel »

Steve Maughan wrote:Hi Ed,

My video about creating Polyglot opening books may be helpful.

http://www.chessprogramming.net/create- ... ning-book/

Steve
Nice Steve, liked the Scid part in particular.