-Move Book::get_move(const Position &pos) const {
- if(this->is_open()) {
- int bestMove = 0, bestScore = 0, move, score;
- uint64_t key = book_key(pos);
- BookEntry entry;
-
- for(int i = this->find_key(key); i < bookSize; i++) {
- this->read_entry(entry, i);
- if(entry.key != key)
- break;
- move = entry.move;
- score = entry.count;
+Move Book::get_move(const Position& pos, bool findBestMove) {
+
+ if (!is_open() || bookSize == 0)
+ return MOVE_NONE;
+
+ BookEntry entry;
+ int bookMove = MOVE_NONE;
+ int scoresSum = 0, bestScore = 0;
+ uint64_t key = book_key(pos);
+
+ // Choose a book move among the possible moves for the given position
+ for (int idx = find_key(key); idx < bookSize; idx++)
+ {
+ read_entry(entry, idx);
+ if (entry.key != key)
+ break;
+
+ int score = entry.count;
+