Is there a program to build opening books based on engines?

Discussion of anything and everything relating to chess playing software and machines.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
Uri Blass
Posts: 8555
Joined: Wed Mar 08, 2006 11:37 pm
Location: Tel-Aviv Israel

Is there a program to build opening books based on engines?

Post by Uri Blass » Fri Feb 23, 2018 10:17 pm

The idea is simply to take a specific engine and use the analysis of it to build an opening book for white and for black when the program that build the books has a limited time to build the book and get as input the time control that the book should be designed for(no database of human games and the idea is only use the engine's own analysis to build the book).

For example you can decide about time control of 1+1(1 minute per game plus 1 seconds per move) and time of 48 hours of computer time to build the book.

After building the book it is possible to test the engine with the book or without the book against different engines at the relevant time control to see how much elo the book gives when the interesting question is what is the best algorithm to build the book.

You can decide using more time for every move that you add to book but the disadvantage is going to be a smaller book and you can decide to use less time for every move that you add to book when the main advantage is going to be saving time on the clock and not better quality of moves in the book.

Rodolfo Leoni
Posts: 544
Joined: Tue Jun 06, 2017 2:49 pm
Location: Italy

Re: Is there a program to build opening books based on engin

Post by Rodolfo Leoni » Fri Feb 23, 2018 10:42 pm

I don't know if such a program exists, but... how would you avoid repetitive lines? Example, if you use Stockfish you'll get lots of Queen's Indians, some French and few Spanish.
F.S.I. Chess Teacher

Ferdy
Posts: 4075
Joined: Sun Aug 10, 2008 1:15 pm
Location: Philippines

Re: Is there a program to build opening books based on engin

Post by Ferdy » Sat Feb 24, 2018 2:39 am

Another idea which I think were already done by others would be to take engine1 play against engine2 where engine1 will not use a book and engine2 will use a wide and bigger book playing the book moves randomly, save the game and separate the games played by engine1 as white and black, the games can then be used to build a book like polyglot book using the moves played by engine1 as white and black.

User avatar
Greg Strong
Posts: 388
Joined: Sun Dec 21, 2008 5:57 pm
Location: Washington, DC

Re: Is there a program to build opening books based on engin

Post by Greg Strong » Sat Feb 24, 2018 4:07 am

Rodolfo Leoni wrote:I don't know if such a program exists, but... how would you avoid repetitive lines?
Probably with multi-pv. This hypothetical program would need to use multi-pv and then carve out only those moves within a delta of the best move. This is an idea I'm interested in pursuing as well for chess variants where no opening books exist. Problem is that engines aren't very good at playing openings. The Sicilian Defense is a great response to 1. e4 - possibly the best - but most engine won't find it (I think.)

Ferdy
Posts: 4075
Joined: Sun Aug 10, 2008 1:15 pm
Location: Philippines

Re: Is there a program to build opening books based on engin

Post by Ferdy » Sat Feb 24, 2018 4:20 am

Another idea is to use bookup program in a clever way.

Create an ebook as white repertoire, say use SF9 to handle all white to move positions and make on the board the suggested move of SF9. Then as a response for black you may enter any moves you like, then make on the board the move considered by SF9 as best for white, and so on. You can then analyze all the leaf nodes, then backsolved it, to get an overview on the scores from the root positions.

Image

You can export all the games as pgn or as epd from this repertoire, but without the score.

User avatar
phhnguyen
Posts: 371
Joined: Wed Apr 21, 2010 2:58 am
Location: Australia
Full name: Nguyen Hong Pham
Contact:

Re: Is there a program to build opening books based on engin

Post by phhnguyen » Sat Feb 24, 2018 6:05 am

Take a look the below paper. IMO it has some limitations and there are some questions for that paper but it may be a good starting point:

https://drive.google.com/file/d/0B2pvWW ... 0tem8/view

Fabian Fichter
Posts: 25
Joined: Mon Dec 12, 2016 1:14 pm
Contact:

Re: Is there a program to build opening books based on engin

Post by Fabian Fichter » Sat Feb 24, 2018 10:55 am

Probably with multi-pv. This hypothetical program would need to use multi-pv and then carve out only those moves within a delta of the best move. This is an idea I'm interested in pursuing as well for chess variants where no opening books exist. Problem is that engines aren't very good at playing openings. The Sicilian Defense is a great response to 1. e4 - possibly the best - but most engine won't find it (I think.)
What you describe is pretty much what I implemented here for Stockfish (for official, multi-variant, Seirawan, Makruk, and Shatranj Stockfish): https://github.com/ianfab/bookgen

I also wrote this due of a lack of opening books for chess variants, since we needed variant opening books for testing multi-variant Stockfish, but it of course also works for standard chess. So far it only generates EPD opening books, so they can basically only be used as starting positions for testing, but not to equip an engine with a book. I would like to extend it to be able to generate PGNs, which should make it easier to convert them to other opening book formats, but that would require a variant-agnostic SAN converter. Reporting coordinate notation would be easier to add, but I do not know whether that is as useful as PGN output.

Uri Blass
Posts: 8555
Joined: Wed Mar 08, 2006 11:37 pm
Location: Tel-Aviv Israel

Re: Is there a program to build opening books based on engin

Post by Uri Blass » Sat Feb 24, 2018 6:13 pm

It is possible to build a book based on fixed depth analysis(or fixed time analysis) or other ideas that may be better.

Maybe get an estimate for probability for every line based on the evaluations and continue next with the best probability is better than what I did in this example but calculating probability for every move manually if we assume that the probability is proportional to some function of the evaluation function is something that I cannot demonstrate easily and is suitable more for computers and I made manually the example to demonstrate what I mean.

I give an example by fixed depth that is not the best.

Here is one idea that is not the best to build a book for 1+1 time control game but is probably better than the empty book because black put moves in the book for black at bigger depths than the depth that it practically reach at 1+1 and stockfish does not get depth 30 in the opening in 1+1 time control.

The variables here are
1)20(depth analysis for white that is important only to choose the positions to add moves for black so quality of moves is relatively less important)
2)30(depth analysis for black and moves that I add for book of black are analyzed at depth 30
3)0.1 number that encourage the program to prefer short lines in the book relative to long lines(I prefer to analyze more options and not to go forward in the analysis as long as there are alternatives that are less than 0.1 pawn weaker than the best move).

To build a book for black
I start by analyzing the opening position at depth 20
I get the following analysis:


[D]rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1

Stockfish_18022413_x64_modern:

20/31 00:40 111,989k 2,762k -0.69 1.f3 e5 2.e3 d5 3.d4 exd4 4.exd4 Bd6 5.Nc3 c6 6.g3 Ne7 7.Bg2 h5 8.f4 Bg4 9.Nge2 h4 10.h3 Bxe2 11.Qxe2 hxg3 12.Bd2
20/31 00:40 111,989k 2,762k -0.61 1.g4 d5 2.Bg2 Bxg4 3.c4 Nf6 4.h3 Bd7 5.cxd5 c6 6.dxc6 Bxc6 7.Nf3 e6 8.Nc3 Nbd7 9.d3 Bb4 10.0-0 0-0 11.Bd2 Kh8 12.Kh1
20/31 00:40 111,989k 2,762k -0.44 1.Nh3 e5 2.c3 d5 3.d4 Nc6 4.dxe5 Nxe5 5.Bf4 Ng6 6.Bg3 c6 7.e3 N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e3 e6 2.d4 Nf6 3.c4 d5 4.Nc3 Be7 5.Nf3 0-0 6.Be2 dxc4 7.0-0 a6 8.Bxc4 b5 9.Bd3 Bb7 10.e4 c5 11.dxc5 Bxc5
20/28 00:40 111,989k 2,762k +0.39 1.d4 d5 2.Nf3 e6 3.c4 Nf6 4.Nc3 Be7 5.Bg5 Nc6 6.e3 h6 7.Bxf6 Bxf6 8.cxd5 exd5 9.Qb3 Ne7 10.e4 dxe4 11.Nxe4 Nc6
20/35 00:40 111,989k 2,762k +0.40 1.e4 e5 2.Nf3 Nc6 3.Bb5 Nf6 4.0-0 Nxe4 5.d4 a6 6.Bxc6 dxc6 7.Re1 Nf6 8.Nxe5 Be6 9.c4 Bd6 10.Bf4 0-0 11.Qd3 Nd7 12.Nc3 Re8 13.h3 Nxe5 14.Bxe5 h6 15.Bxd6 Qxd6 16.Rad1



It means I have the following scores relative to best move
1.e4 0
1.d4 -0.01
1.e3 -0.03
1.Nf3 -0.04
1.c4 -0.08
1.Nc3 -0.17
1.b3 -0.3
1.d3 -0.3
1.h3 -0.33
1.c3 -0.35
1.a3 -0.37
1.g3 -0.40
...

I analyze after the best move 1.e4 and
I get at depth 30 the move 1...e6 and I do not use multi-pv because I want the book for black to have one option for black at every node and many options for white to be ready for many options the opponents can play.

Now the score of 1.e4 e6 is -0.1 because I have the rule that I substract 0.1 for every move of black from the score so at this point I do not analyze what happens after 1.e4 e6 but analyze what happens after 1.d4 that has a better score of -0.01 and the order of analysis is
1)opening position score multi-pv all options 0
2)best move 1.e4 0(best move at depth 30 is 1...e6 so add it to the book)
3)1.d4 -0.01(best move at depth 30 is 1...Nf6 so add it to the book)
4)1.e3 -0.03(best move at depth 30 is 1...e6 so add it to the book)
5)1.Nf3 -0.04(best move at depth 30 is 1...e6 so add it to the book)
6)1.c4 -0.08(best move at depth 30 is 1...e5 so add it to the book)
7)1.e4 e6 -0.1(all options depth 20)
2.Nc3 was the best move for white at depth 20 and here is part of the analysis with multi-pv=30


20/27 01:04 176,711k 2,735k +0.37 2.Nf3 d5 3.exd5 exd5 4.d4 Nf6 5.Bd3 Bd6 6.Qe2+ Be7 7.0-0 0-0 8.Be3 Nc6 9.c3 Re8 10.Qc2 Bd6 11.Nbd2 Bd7 12.h3 h6 13.Rae1 a6 14.Kh1 Be6 15.Nb3
20/37 01:04 176,711k 2,735k +0.39 2.d4 d5 3.Nc3 Nf6 4.Bg5 Be7 5.e5 Ne4 6.Nxe4 dxe4 7.Be3 c5 8.dxc5 Qc7 9.Qd4 Bd7 10.0-0-0 0-0 11.Qxe4 Bc6 12.Qd4 Nd7 13.Nf3 Bxc5
20/31 01:04 176,711k 2,735k +0.47 2.Nc3 d5 3.d4 Nf6 4.Bg5 Be7 5.e5 Ne4 6.Nxe4 dxe4 7.Bxe7 Qxe7 8.c3 Nd7 9.Ne2 b6 10.Ng3 Bb7 11.Bb5 0-0 12.0-0 c5 13.Re1 Rfd8 14.Nxe4 Nxe5 15.Nxc5 bxc5 16.Rxe5 cxd4

It means
1.e4 e6 2.Nc3 get a score of -0.1
1.e4 e6 2.d4 get a score of -0.18
1.e4 e6 2.Nf3 get a score of -0.2 and other lines after 1.e4 e6 get a worse score


steps to continue are
8)analyze 1.e4 e6 2.Nc3 that has -0.1 score(0 for mistakes of white and -0.1 for number of moves black already played) and find a move for black because this line has the best score

9)analyze all options for white after 1.d4 Nf6 that has -0.11 score (-0.01 for mistakes of white and -0.1 for number of moves black already played)

10)1.d4 Nf6 2.c4 is the best move for white so analyze this line that has score of -0.11 to add a move for black for the book.

User avatar
Greg Strong
Posts: 388
Joined: Sun Dec 21, 2008 5:57 pm
Location: Washington, DC

Re: Is there a program to build opening books based on engin

Post by Greg Strong » Sat Feb 24, 2018 8:32 pm

Fabian Fichter wrote:
Probably with multi-pv. This hypothetical program would need to use multi-pv and then carve out only those moves within a delta of the best move. This is an idea I'm interested in pursuing as well for chess variants where no opening books exist. Problem is that engines aren't very good at playing openings. The Sicilian Defense is a great response to 1. e4 - possibly the best - but most engine won't find it (I think.)
What you describe is pretty much what I implemented here for Stockfish (for official, multi-variant, Seirawan, Makruk, and Shatranj Stockfish): https://github.com/ianfab/bookgen

I also wrote this due of a lack of opening books for chess variants, since we needed variant opening books for testing multi-variant Stockfish, but it of course also works for standard chess. So far it only generates EPD opening books, so they can basically only be used as starting positions for testing, but not to equip an engine with a book. I would like to extend it to be able to generate PGNs, which should make it easier to convert them to other opening book formats, but that would require a variant-agnostic SAN converter. Reporting coordinate notation would be easier to add, but I do not know whether that is as useful as PGN output.
Nice! Thanks for letting me know about this!

User avatar
Ovyron
Posts: 2495
Joined: Tue Jul 03, 2007 2:30 am

Re: Is there a program to build opening books based on engin

Post by Ovyron » Sat Feb 24, 2018 8:42 pm

Greg Strong wrote:The Sicilian Defense is a great response to 1. e4 - possibly the best - but most engine won't find it (I think.)
The Sicilian is probably best if you think black is best getting a draw against white. If you want to keep black's winning chances 1...e5 seems like a better option.
Great spirits have always encountered violent opposition from mediocre minds.

Post Reply