opening book coding

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Robert Bernhard

opening book coding

Post by Robert Bernhard »

Hallo together

I have my program named Stellar,it now plays FIDE chess,
Stellar ist my first schach program,i read the TSCP code & the book code of Stellar that i use now ist inspired from the TSCP code,
The code ist complete rewriten but the book ist like TSCP to get idea,i mean text file with moves 'd2d4' etc,

I am now thinking of moving to better opening book code,
my questions ist what ist the ways that you people do?

what ist the suggested method to do opening book code?I work in ANSI-C

Danke,
Robert
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: opening book coding

Post by sje »

Most authors use a hash of a given position to access the opening book. The book is organized as a transposition table (indexed by hash code) or a tree (also indexed by hash code). Each entry in the table (or tree) contains:

1) The win/lose/draw statistics for the position

Or,

2) A list of moves for the position, with each move having its own win/lose/draw statistics.
Robert Bernhard

Re: opening book coding

Post by Robert Bernhard »

Hallo Steffen,

Danke for the reply,i understood that..

Book ist like presaved hash table which have moves stored,like hash,which i access by probe code like for hash tables?

I have some questions,please..

1)Ist it enough to just store win/loss/draw statistics for position? i think point 2 ist better.
2)ist it enough to have only win/loss/draw statistics & ist it completely trustable with the method?

Ist it a good idea to have a shallow alpha-beta search into best x moves?

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

Re: opening book coding

Post by Edmund »

Robert Bernhard wrote:Hallo Steffen,

Danke for the reply,i understood that..

Book ist like presaved hash table which have moves stored,like hash,which i access by probe code like for hash tables?

I have some questions,please..

1)Ist it enough to just store win/loss/draw statistics for position? i think point 2 ist better.
2)ist it enough to have only win/loss/draw statistics & ist it completely trustable with the method?
There exist different implementations.

One way to go is to let the opening book be automatically generated. Therefor you scan through your game database and add each new move played to the opening book and increase one of 3 counters (win/draw/loss). When finally using the opening book you have to come up with a formula to state the probability a certain move is chosen. This should take into account the outcomes of the games as well as the size of the sample (more people playing a certain move is usually a better option)

Another way to go would be to edit/create your book manually. There it would be enough to just fill the book with entries consisting of <hash> + <move>. Thus for each position you might have several of these pairs. You can as well add another variable: "weight" to set which of the moves should be prefered.
Robert Bernhard wrote: Ist it a good idea to have a shallow alpha-beta search into best x moves?
Opening books are all about avoiding to start searches (and waste time) too early. It is in the interest of the opening book author to make the lines strong enough so that no search is needed afterwards.
Edmund
Posts: 670
Joined: Mon Dec 03, 2007 3:01 pm
Location: Barcelona, Spain

Re: opening book coding

Post by Edmund »

sje wrote:Most authors use a hash of a given position to access the opening book. The book is organized as a transposition table (indexed by hash code) or a tree (also indexed by hash code). Each entry in the table (or tree) contains:

1) The win/lose/draw statistics for the position
Storing statistics per move is always superior than storing it per position.

Eg.
1. e4 e5 2. Bb5 a6 3. Nf3

Most opening books that store per position statistics would play Nc6?? here, just because it sees the transposition into the spanish opening and doesn't know the position after axb5!
rebel777

Re: opening book coding

Post by rebel777 »

http://www.top-5000.nl/tools.htm

Maybe this is something for you.

Ed
Robert Bernhard

Re: opening book coding

Post by Robert Bernhard »

Hallo,

Thankes of you!

Ed this ist nice,i will use your code for now,
but eventually i want to work out my book code,because ist may be a problem for some tournament?

thankes all!
Robert
rebel777

Re: opening book coding

Post by rebel777 »

Robert Bernhard wrote:Hallo,

Thankes of you!

Ed this ist nice,i will use your code for now,
but eventually i want to work out my book code,because ist may be a problem for some tournament?

thankes all!
Robert
There is no tournament problem, it's an open system. The format comes with its own book-editor, see: http://www.top-5000.nl/prodeodos.htm

Ed
Robert Bernhard

Re: opening book coding

Post by Robert Bernhard »

Danke Ed,

I am implementation of yours code for book usage.

Very helpful,it save me a coding for book myself.

MfG,
Robert
Pradu
Posts: 287
Joined: Sat Mar 11, 2006 3:19 am
Location: Atlanta, GA

Re: opening book coding

Post by Pradu »

Codeman wrote: Storing statistics per move is always superior than storing it per position.

Eg.
1. e4 e5 2. Bb5 a6 3. Nf3

Most opening books that store per position statistics would play Nc6?? here, just because it sees the transposition into the spanish opening and doesn't know the position after axb5!
Requiring the current position to exist in the book before using book moves should fix this problem. In addition, storing statistics per position doesn't loose information for different moves that come to the same position.