4

I previously asked how to use polyglot in c# with a chess engine. My question then was not accurate. What I want to know is, what property(ies) of the bin file object I need to do the following:

I will parse a FEN string, then, I will access a property of this bin file that will allow me to generate a FEN string that's hopefully linked to a move, whether this move is in a pgn string of a game, or saved as a specific data struct.

Then I will compare my parsed string with such FEN string obtained by accessing a property of the bin file object.

Then, when I find a match, I will use another method to obtain the next immediate move, which is the one the computer should do, according to the game from which the move was obtained after finding a FEN matching the one I parsed in the first place.

So, I guess a pseudo code would look like:

 string extractedMove;
 string parsedFEN = "...";
 object bookBytes = File.Read(pathofthebookfile);

  string GetFENOutOfBook (string FENvalue)
{ 
   return  bookBytes.Find(FENproperty/Fenkey => FENvalue);
}

  public void GetMove ()
{
   extractedMove = bookBytes.moves[GetFENOutOfBook(parsedFEN)].ToString();
}

So can someone point me in the right direction to do this? I just need to know what properties I need to work with of the polyglot book bin file so I can create the logic to extract the move. Thanks in advance!

4

I have every reason to believe your approach is wrong and will lead to disaster. I'm saying it as someone who make softwares to work on Polyglot books (www.smallchess.com).

You are strongly advised NOT to do all the hard works like what I did before. Just wrap the C++ Polyglot code in your C#! Your time should be on your C# engine, not this.

Polyglot, although open source is not something you would like to port to C# unless you are super motivated. Why? Polyglot has bunch of hash keys. Screenshot on my source code:

enter image description here

There was never any good documentation on Polyglot, it existed mainly in source code. Today, not many people really know how that does (including myself). I understand only part of it, by reading source code.

That was the comment I wrote to myself when I started using Polyglot many years ago:

    /*
     * A PolyGlot book move is encoded as follows:
     *
     * bit  0- 5: destination square (from 0 to 63)
     * bit  6-11: origin square (from 0 to 63)
     * bit 12-13-14: promotion piece (from KNIGHT == 1 to QUEEN == 4)
     *
     * Castling moves follow "king captures rook" representation. So in case
     * book move is a promotion we have to convert to our representation, in
     * all other cases we can directly compare with a Move after having
     * masked out special Move's flags that are not supported by PolyGlot.
     */

Polyglot works like this:

  1. Given a position, convert to a hash key. I have my screenshot for the conversion

enter image description here

  1. Use the key to locate an entry in the book using binary search
  2. Read the entry from (2)
  3. Extract the chess move like:

enter image description here

| improve this answer | |
  • Hi thanks for the reply. I don't know c++. so that's why I wanted information on the data structure of the bin files, so I can read them and use them like that, compiled as they are, inside my code. So please let me know if you can provide me with info on the bin file data structure for the opening book files , or the link where you read and understood part of the code then. – Jorge Acuna Mar 16 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.