bug-gnu-chess
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

book doesn't handle castling moves


From: Pawel Koziol
Subject: book doesn't handle castling moves
Date: Sat, 8 Feb 2014 14:31:23 +0100

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
address@hidden

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;
}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]