- File pawnFile = square_file(pos.pawn_list(strongerSide, 0));
-
- if((pawnFile == FILE_A || pawnFile == FILE_H) &&
- (pawns & ~file_bb(pawnFile)) == EmptyBoardBB) {
- // All pawns are on a single rook file.
-
- Square bishopSq = pos.bishop_list(strongerSide, 0);
- Square queeningSq =
- relative_square(strongerSide, make_square(pawnFile, RANK_8));
- Square kingSq = pos.king_square(weakerSide);
-
- if(square_color(queeningSq) != square_color(bishopSq) &&
- file_distance(square_file(kingSq), pawnFile) <= 1) {
- // The bishop has the wrong color, and the defending king is on the
- // file of the pawn(s) or the neighboring file. Find the rank of the
- // frontmost pawn:
-
- Rank rank;
- if(strongerSide == WHITE) {
- for(rank = RANK_7; (rank_bb(rank) & pawns) == EmptyBoardBB; rank--);
- assert(rank >= RANK_2 && rank <= RANK_7);
- }
- else {
- for(rank = RANK_2; (rank_bb(rank) & pawns) == EmptyBoardBB; rank++);
- rank = Rank(rank^7); // HACK
- assert(rank >= RANK_2 && rank <= RANK_7);
+ File pawnFile = square_file(pos.piece_list(strongerSide, PAWN, 0));
+
+ // All pawns are on a single rook file ?
+ if ( (pawnFile == FILE_A || pawnFile == FILE_H)
+ && (pawns & ~file_bb(pawnFile)) == EmptyBoardBB)
+ {
+ Square bishopSq = pos.piece_list(strongerSide, BISHOP, 0);
+ Square queeningSq = relative_square(strongerSide, make_square(pawnFile, RANK_8));
+ Square kingSq = pos.king_square(weakerSide);
+
+ if ( square_color(queeningSq) != square_color(bishopSq)
+ && file_distance(square_file(kingSq), pawnFile) <= 1)
+ {
+ // The bishop has the wrong color, and the defending king is on the
+ // file of the pawn(s) or the neighboring file. Find the rank of the
+ // frontmost pawn.
+
+ Rank rank;
+ if (strongerSide == WHITE)
+ {
+ for (rank = RANK_7; (rank_bb(rank) & pawns) == EmptyBoardBB; rank--) {}
+ assert(rank >= RANK_2 && rank <= RANK_7);
+ }
+ else
+ {
+ for(rank = RANK_2; (rank_bb(rank) & pawns) == EmptyBoardBB; rank++) {}
+ rank = Rank(rank^7); // HACK to get the relative rank
+ assert(rank >= RANK_2 && rank <= RANK_7);
+ }
+ // If the defending king has distance 1 to the promotion square or
+ // is placed somewhere in front of the pawn, it's a draw.
+ if ( square_distance(kingSq, queeningSq) <= 1
+ || relative_rank(strongerSide, kingSq) >= rank)
+ return ScaleFactor(0);