this is the same bug I encountered in Toga II 3.0, so I sent the same fix.
Current Polyglot book fromat encodes castling as E1H1 rather than E1G1.

regards,

Pawel Koziol
pp.koz...@gmail.com

int book_move(board_t * board) {

   int best_move;
   int best_score;
   int pos;
   entry_t entry[1];
   int move;
   int score;
   list_t list[1];
   int i;

   ASSERT(board!=NULL);

   if (BookFile != NULL && BookSize != 0) {

      // draw a move according to a fixed probability distribution

      best_move = MoveNone;
      best_score = 0;

      for (pos = find_pos(board->key); pos < BookSize; pos++) {

         read_entry(entry,pos);
         if (entry->key != board->key) break;

         move = entry->move;
         score = entry->count;

         // pick this move?

         ASSERT(score>0);

         best_score += score;
         if (my_random(best_score) < score) best_move = move;
      }

      if (best_move != MoveNone) {

         // convert PolyGlot move into Fruit move; TODO: handle promotes

         gen_legal_moves(list,board);

         for (i = 0; i < list->size; i++) {
            move = list->move[i];

            // fix for correct handling of castling moves - PK
            if (MOVE_FROM(move) == E1     && MOVE_TO(move) == G1
            && MOVE_FROM(best_move) == E1 && MOVE_TO(best_move) == H1 )
return move;
            if (MOVE_FROM(move) == E1     && MOVE_TO(move) == C1
            && MOVE_FROM(best_move) == E1 && MOVE_TO(best_move) == A1 )
return move;
            if (MOVE_FROM(move) == E8     && MOVE_TO(move) == G8
            && MOVE_FROM(best_move) == E8 && MOVE_TO(best_move) == H8 )
return move;
            if (MOVE_FROM(move) == E8     && MOVE_TO(move) == C8
            && MOVE_FROM(best_move) == E8 && MOVE_TO(best_move) == A8 )
return move;

            if ((move & 07777) == best_move) return move;
         }
      }
   }

   return MoveNone;
}
_______________________________________________
Bug-gnu-chess mailing list
Bug-gnu-chess@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-gnu-chess

Reply via email to