Answers.Body: <p>Sorry, I don't have C# code. Can we do it in C++?</p>
  
  <ul>
  <li><a href="https://github.com/Warpten/Fruit-2.1/blob/master/src/book.cpp" rel="nofollow noreferrer">https://github.com/Warpten/Fruit-2.1/blob/master/src/book.cpp</a></li>
  </ul>
  
  <p>Polyglot book is defined like:</p>
  
  <pre><code>struct entry_t {
     uint64 key;
     uint16 move;
     uint16 count;
     uint16 n;
     uint16 sum;
  };
  </code></pre>
  
  <p>You may want to wrap the C++ code inside your C#. How to do that is out of scope here.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-06T21:17:26.070Z
Answers.Text: Thanks a lot for your reply! I understand that wrapping is out of scope. Well I'm learning C++, so this can be a good learn as you go exercise.
  
  So my plan is:
  
  import book file
  do method to find position on book (parsing moves string, comparing accessing boards list?)
  if found board similar to parsed position, create my own variant format to parse 
  to my move manager so variant can be played out.
Answers.UserDisplayName: Jorge Acuna
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-02-06T21:22:43.210Z
Answers.Text: I didn't want to make my first comment too long, so here are a couple extra questions:
  
  So Polyglot file is just a collection of entry_t objects? I saw in your git link, you have a board class, so you then construct on your own reading the entry_t collection properties the board you need to find the variant? I thought  in the book file you would have like a lot of positions defined as objects, so you can compare to them, am I wrong on this? Thanks for the help btw :)!
Answers.UserDisplayName: Jorge Acuna
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-28T20:30:03.463Z
Answers.LastActivityDate: 2020-01-28T20:30:03.463Z
Answers.UserDisplayName: SmallChess
Body: <p>I would like, if possible, for someone to provide a code snippet of a basic logic to access a Polyglot book file. I'm having trouble finding the file format documentation, so I don't know how to access it and use it in the code. I'm making a chess game and would like to use the books to support features in the game. If not too much trouble, I would rather have a c# code sample, since it's the language I'm fluent with right now. </p>
  
Tags: <opening><engines><software><books>
Title: How to use a Polyglot book in C# with a chess engine
ThreadText: # How to use a Polyglot book in C# with a chess engine
  
  (Asked by: username_0 on 2020-01-27)
  
  I would like, if possible, for someone to provide a code snippet of a basic logic to access a Polyglot book file. I'm having trouble finding the file format documentation, so I don't know how to access it and use it in the code. I'm making a chess game and would like to use the books to support features in the game. If not too much trouble, I would rather have a c# code sample, since it's the language I'm fluent with right now.
  
  **Tags:** opening, engines, software, books
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-01-28. Score: 4 | Accepted answer
  
  Sorry, I don't have C# code. Can we do it in C++?
  
  * <https://github.com/Warpten/Fruit-2.1/blob/master/src/book.cpp>
  
  Polyglot book is defined like:
  
  ```
  struct entry_t {
     uint64 key;
     uint16 move;
     uint16 count;
     uint16 n;
     uint16 sum;
  };
  
  ```
  
  You may want to wrap the C++ code inside your C#. How to do that is out of scope here.
  
  > **Comments:**
  > **username_0**: Thanks a lot for your reply! I understand that wrapping is out of scope. Well I'm learning C++, so this can be a good learn as you go exercise.  So my plan is:  import book file do method to find position on book (parsing moves string, comparing accessing boards list?) if found board similar to parsed position, create my own variant format to parse  to my move manager so variant can be played out.  
  > **username_0**: I didn't want to make my first comment too long, so here are a couple extra questions:  So Polyglot file is just a collection of entry_t objects? I saw in your git link, you have a board class, so you then construct on your own reading the entry_t collection properties the board you need to find the variant? I thought  in the book file you would have like a lot of positions defined as objects, so you can compare to them, am I wrong on this? Thanks for the help btw :)!  
  
  ---
  
  