How to create opening book with statistics

Discussion of chess software programming and technical issues.

Moderator: Ras

anglachow

How to create opening book with statistics

Post by anglachow »

I want to create and read an opening book with statistics for each move, such as 1.e4 (40%) 1.Nf3 (23%). How do I do it and what format and tools for it?
uaf
Posts: 98
Joined: Sat Jul 31, 2010 8:48 pm
Full name: Ubaldo Andrea Farina

Re: How to create opening book with statistics

Post by uaf »

You could use Scid (http://scid.sourceforge.net/) to create and tune opening books in Polyglot format.
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: How to create opening book with statistics

Post by tpetzke »

What is your background ?

Do you want to read it with an engine that you program or with your eyes because you are just interested in what moves are played how often.

Then you can have a look at the opening statistics on the shredder website

http://www.shredderchess.com/online-che ... abase.html

If you need programing tips for a book building app I can provide some.

Thomas...
Edmund
Posts: 670
Joined: Mon Dec 03, 2007 3:01 pm
Location: Barcelona, Spain

Re: How to create opening book with statistics

Post by Edmund »

You might want to have a look at the well documented Glass Opening Book Creation Tool:
http://www.koziol.home.pl/marittima/glass/download.htm
nkg114mc
Posts: 74
Joined: Sat Dec 18, 2010 5:19 pm
Location: Tianjin, China
Full name: Chao M.

Re: How to create opening book with statistics

Post by nkg114mc »

ChessX may be a good choice.

It is really powerful, and it is opensource!

ChessX's site http://chessx.sourceforge.net
anglachow

Re: How to create opening book with statistics

Post by anglachow »

I want to create a book externally and read the book in C++. If I create the book with Scid (or anything else), how should I read it in code?

Thanks,
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: How to create opening book with statistics

Post by tpetzke »

Have you considered to use google to get a basic understanding of the topic first. The community is usually very helpful with specific questions.

"How should I read it in code" is not specific or do you really look for something like this

Code: Select all

        while (!file.eof())
	{	
		file.read((char *)(&entry), sizeof(TBookEntry));
		if (!file.eof())
		{ 
			book.entries->push_back(entry);
		}
	} 
A Beginner's Guide to building a opening book
http://www.horizonchess.com/FAQ/Winboar ... gbook.html

Thomas...
anglachow

Re: How to create opening book with statistics

Post by anglachow »

tpetzke wrote:Have you considered to use google to get a basic understanding of the topic first. The community is usually very helpful with specific questions.

"How should I read it in code" is not specific or do you really look for something like this

Code: Select all

        while (!file.eof())
	{	
		file.read((char *)(&entry), sizeof(TBookEntry));
		if (!file.eof())
		{ 
			book.entries->push_back(entry);
		}
	} 
A Beginner's Guide to building a opening book
http://www.horizonchess.com/FAQ/Winboar ... gbook.html

Thomas...
Sorry if I made my question unclear. I already programmed a chess engine and GUI in C++, and it supports Polyglot opening book without any problems. But I found that the default format for the book doesn't support anything for the statistics, and I'm wondering whether I should extend the book format by myself or give it up for something that supports statistics. I'm not aware of any open format or libraries in C++ that reads an opening book which supports statistics. Basically, I need it for displaying for my GUI.

Similar to the Stockfish GUI which displays the statistics and it's programmed in C++.
tpetzke
Posts: 686
Joined: Thu Mar 03, 2011 4:57 pm
Location: Germany

Re: How to create opening book with statistics

Post by tpetzke »

If you just want to display the move selection probability next to the move (as mentioned in your first post) the polyglot format should be sufficient.

If you want to do more you probably have to write your own book building app that does what you want.

You usually gather a database with games and then create books out of it. The GUI should access the database, the engine the created book

Thomas...
Dave_N
Posts: 153
Joined: Fri Sep 30, 2011 7:48 am

Re: How to create opening book with statistics

Post by Dave_N »

Basically the win/loss/draw stats could be built by looping over each game and classifying the opening, easy way would be to write each game into a tree
(e.g. first move 1.e4 e5 (1...c5 2.Nf3) 2.Nf3 Nc6 3.Bb5 (3.Bc4 Bc5) )

with the result (and hopefully the ECO of the position) stored in the most recent node with at least 2 games and permeated to the root ...

e.g Nc6 has two games so Nf3 has 2 games etc until there are 3 games stored in e4 and 2 games stored in e5. Say for example the Bb5 line is a win for white and the Bc4 line is a win for black, then e5 stores a win and a loss, while for example if c5 is a win for black then it stores 2 wins and a loss (for white). If you went further and had 1.e4 e5 2.Nf3 Nf6 3.Bc4 Nf6 Ng5 (1-0) then you have an extra win on the 3...Bc4 node, not on the 3...Bc5 line.

I have never actually written this code, so perhaps someone with experience in coding how to make Book from PGN databases could be more helpful.