Opening library

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Opening library

Post by lauriet »

Hi,
I want to add a good/big opening library.
In particular, I need to understand the format and how to find the library move.
Unfortunately C examples don't help much because I'm "C blind".
So a good explanation of things would be best.
Can anyone help, or point me in the right direction ?

Thanks.
Dann Corbit
Posts: 12540
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Opening library

Post by Dann Corbit »

What kind of chess engines to you want to connect with?
Are they UCI engines or Chessbase engines or something else?
What GUI will you be using with your chess engines?

What are the goals of your book? Do you want to edit it with NAGs? Do you want to chose moves to always play?

There are lots of book formats and which one is best for you will depend on what you want to do with it'
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: Opening library

Post by lauriet »

This is to use as an opening library for my own program LTchess2
So I just need to know the format and technique so I can write the code to find the next move.
jdart
Posts: 4366
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Opening library

Post by jdart »

Most UCI engines delegate all the book interface to the GUI that is driving them.

If you want a book interface, it would be much simpler to use something like Polyglot, which is open source, vs. building your own book storage/retrieval system. Polyglot basically uses a Zobrist hash of the position to look up moves. This technique is pretty standard. If you want to roll your own, I would look at a key/value database like RocksDB, which has a C++ and Java API (https://rocksdb.org/), and can at least handle all the storage stuff.

Another thing to maybe look at is the online Chess Cloud Database (https://www.chessdb.cn/queryc_en/), which has a REST API. Any REST-capable client can access it.

But all these require some programming work to interface to.
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Opening library

Post by hgm »

Polyglot (.bin) books are just a list of all the moves of the book sorted by position. For each move 16 bytes of data are stored:

* An 8-byte hash key represents the position
* a 2-byte integer represents the move, as toSquareNumber + 64*fromSquareNumber + 4096*promotionPiece
* a 2-byte interer known as the weight (determining the relative probability the move will be chosen)
* two 2-byte numbers known as the 'learn fields', only used for 'book learning' (where they hold the number of plays and number of scored half-points)

The hash key is a normal Zobrist XOR key; the list of basis keys can be obtained from the Polyglot or XBoard source code. The moves are sorted in the order of ascending key (interpreted as unsigned integer).

The promotionPiece is 0 when the move is not a promotion, or 1-4 for N, B, R, Q respectively.

Squares are numbered 0 (for a1) to 63 (h8), with a8 -> 7.
DeanKaawirn
Posts: 1
Joined: Sun Oct 11, 2020 7:14 pm
Full name: Dean Kaawirn

Re: Opening library

Post by DeanKaawirn »

I was once visited by similar thoughts, but I did not dare, although I began to collect materials, information, wrote out a plan and theses
willmorton
Posts: 30
Joined: Thu Sep 17, 2020 9:19 pm
Full name: William Morton

Re: Opening library

Post by willmorton »

here you'll find Michel Van den Bergh's description of the polyglot book format:
https://web.archive.org/web/20120117074 ... ormat.html
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Opening library

Post by hgm »

If I am not mistaken, you are now replying to a SPAM bot.
willmorton
Posts: 30
Joined: Thu Sep 17, 2020 9:19 pm
Full name: William Morton

Re: Opening library

Post by willmorton »

hgm wrote: Tue Oct 20, 2020 1:22 pm If I am not mistaken, you are now replying to a SPAM bot.
My bad, I have not checked the dates.

May I use this avatar HGM? :D
User avatar
Roland Chastain
Posts: 640
Joined: Sat Jun 08, 2013 10:07 am
Location: France
Full name: Roland Chastain

Re: Opening library

Post by Roland Chastain »

@lauriet

Just in case, I put here a Pascal version of the examples from Michel Van den Bergh's tutorial:
polyglot-pascal.zip

Regards.

Roland
Qui trop embrasse mal étreint.