Tom Cant wrote:Would someone be able to direct me to a tutorial/article for hashing the opening book?
Thanks for the replies, I really appreciate it!
Tom
Hi Tom,
Here's an easily understood format:
rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq -
d2d4 37802/ e2e4 43715/ c2c4 23456/
The first line is the fen position, the second line contains the book's possible moves and the amount of times each move was played (perhaps from scanned pgn files).
The additional information of side-to-move, castling rights, and possible ep square ensure that illegal opening moves don't get played and permit all the information to be held in a single book file. This is a nice, human-readable format that can be edited by hand. The downside, due to the long fen description, is its non-compact-ness. But, since this format also handles all opening transpositions so that you do not have to repeat the entire move-sequence leading up to the current position, it is probably more compact than your format.
The fen position can easily be replaced by a 64-bit Zobrist hash value.
See:
http://www.brucemo.com/compchess/progra ... obrist.htm
The resulting format would be called a hashed opening book and is a very compact way to store the opening moves. Hashed opening books can never be edited by hand because of the impossibility of starting with a 64-bit number and attempting to create the position that caused it. Zobrist hashing is called a "one-way function".
See:
http://en.wikipedia.org/wiki/One-way_function
There is an extremely small (but measurable) possibility that a hashed opening book could cause an opening book error if two hashed positions happen to resolve to the same 64-bit number.
Edited to add:
All opening books should be pre-sorted (by fen or by Zorbist values) so you can use a fast binary search to fetch your moves.
Best regards,
Ron