Thanks for all the suggestions and feedback.
I was using an earlier version of the driver, many problems I have solved by modifying the code are now part of the official code, so the best solution is just use the official code.
Still it seems that the official code has no support for using an opening book.
My solution is the following.
Open a console window, cd to the parent folder of lichess bot and type:
git clone https://github.com/michaeldv/donna_opening_books
Rename the resulting folder "obooks" for convenience ( I don't like typing in long names when using the console window, so as a habit I rename cloned repo folders to some simple name ).
In main.py add this below the imports:
import chess.polyglot
BOOK_READER = chess.polyglot.open_reader("../obooks/komodo.bin")
In the play_game function make this change:
if is_engine_move(game.is_white, moves):
try:
entry = BOOK_READER.find(board)
book_best_move = entry.move()
print("book move found {0}".format(book_best_move))
li.make_move(game.id, book_best_move)
except IndexError:
best_move = engine.search(board, upd.get("wtime"), upd.get("btime"), upd.get("winc"), upd.get("binc"))
engine.print_stats()
li.make_move(game.id, best_move)
Now the program will play the best move in the komodo book if there is one, otherwise it will play an engine move.
Thanks for all the suggestions and feedback.
I was using an earlier version of the driver, many problems I have solved by modifying the code are now part of the official code, so the best solution is just use the official code.
Still it seems that the official code has no support for using an opening book.
My solution is the following.
Open a console window, cd to the _parent_ folder of lichess bot and type:
git clone https://github.com/michaeldv/donna_opening_books
Rename the resulting folder "obooks" for convenience ( I don't like typing in long names when using the console window, so as a habit I rename cloned repo folders to some simple name ).
In main.py add this below the imports:
import chess.polyglot
BOOK_READER = chess.polyglot.open_reader("../obooks/komodo.bin")
In the play_game function make this change:
if is_engine_move(game.is_white, moves):
try:
entry = BOOK_READER.find(board)
book_best_move = entry.move()
print("book move found {0}".format(book_best_move))
li.make_move(game.id, book_best_move)
except IndexError:
best_move = engine.search(board, upd.get("wtime"), upd.get("btime"), upd.get("winc"), upd.get("binc"))
engine.print_stats()
li.make_move(game.id, best_move)
Now the program will play the best move in the komodo book if there is one, otherwise it will play an engine move.