+
+ // All pawns on same B or G file? Then potential draw
+ if ( (pawnFile == FILE_B || pawnFile == FILE_G)
+ && !(pos.pieces(PAWN) & ~file_bb(pawnFile))
+ && pos.non_pawn_material(weakerSide) == 0
+ && pos.count<PAWN>(weakerSide) >= 1)
+ {
+ // Get weaker pawn closest to opponent's queening square
+ Bitboard wkPawns = pos.pieces(weakerSide, PAWN);
+ Square weakerPawnSq = strongerSide == WHITE ? msb(wkPawns) : lsb(wkPawns);
+
+ Square strongerKingSq = pos.king_square(strongerSide);
+ Square weakerKingSq = pos.king_square(weakerSide);
+ Square bishopSq = pos.list<BISHOP>(strongerSide)[0];
+
+ // Draw if weaker pawn is on rank 7, bishop can't attack the pawn, and
+ // weaker king can stop opposing opponent's king from penetrating.
+ if ( relative_rank(strongerSide, weakerPawnSq) == RANK_7
+ && opposite_colors(bishopSq, weakerPawnSq)
+ && square_distance(weakerPawnSq, weakerKingSq) <= square_distance(weakerPawnSq, strongerKingSq))
+ return SCALE_FACTOR_DRAW;
+ }
+