How to use Polyglot opening book bin file 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 =&gt; 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!
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:



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:


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





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