A Chess Opening Book reader that supports Polyglot books of the .bin format. The code is fully documented.
- Well-documented
- Ability to load and read Polyglot books
- Returns the book moves in a standard format so you can integrate it with your projects (see below)
- Can randomly extract a book move using the zobrist hash of a position
- Can convert a book move to the UCI protocol
- Ability to process and return the move weight and learn values as well
- Everything is in the
Reader::namespace, so it won't pollute your namespace
This is a single header library. Just download reader.hpp or copy the source code.
NOTE: It is assumed that you have implemented proper zobrist hashing in your code. If not, it is recommended you do that first, since it is required to access book moves.
The book moves are returned in a single format.
For example, a book move of type Reader::BookMove called book_move can be used as follows:
book_move.toFilereturns the index of the file of the target squarebook_move.toRowreturns the index of the row of the target squarebook_move.fromFilereturns the index of the file of the source squarebook_move.fromRowreturns the index of the row of the source squarebook_move.promotionreturns the type of the promoted piece
FILES: a is 0, b is 1, ... h is 7
ROWS: 0, 1, ... 7
PROMOTIONS: 0 is none, 1 is knight, 2 is bishop, 3 is rook, 4 is queen
Or you can just call Reader::ConvertBookMoveToUci(book_move) and automatically convert a move to the UCI format
Reader::Book book;
book.Load("book.bin");
chess::Board board = chess::Board();
board.makeMove("e2e4");
board.makeMove("e7e5");
Reader::BookMoves book_moves = book.GetBookMoves((uint64_t)board.zobrist());
std::cout << Reader::ConvertBookMoveToUci(Reader::RandomBookMove(book_moves)) << std::endl;
book.Clear();
OUTPUT: g1f3
Please suggest improvements to the library. I have done my best to eradicate all known bugs from the code. However, if you feel you have found a potential bug, please open a pull request.