- // Evaluate pawns for each color
- evaluate_passed_pawns_of_color<WHITE>(pos, movesToGo, pawnToGo, ei);
- evaluate_passed_pawns_of_color<BLACK>(pos, movesToGo, pawnToGo, ei);
+ for (Color c = WHITE; c <= BLACK; c++)
+ {
+ // Skip evaluation if other side has non-pawn pieces
+ if (pos.non_pawn_material(opposite_color(c)))
+ continue;
+
+ Bitboard b = ei.pi->passed_pawns() & pos.pieces_of_color(c);
+
+ while (b)
+ {
+ Square s = pop_1st_bit(&b);
+ Square queeningSquare = relative_square(c, make_square(square_file(s), RANK_8));
+ int d = square_distance(s, queeningSquare)
+ - square_distance(pos.king_square(opposite_color(c)), queeningSquare)
+ + int(c != pos.side_to_move());
+
+ if (d < 0)
+ {
+ int mtg = RANK_8 - relative_rank(c, s);
+ int blockerCount = count_1s_max_15(squares_in_front_of(c, s) & pos.occupied_squares());
+ mtg += blockerCount;
+ d += blockerCount;
+ if (d < 0 && (!movesToGo[c] || movesToGo[c] > mtg))
+ {
+ movesToGo[c] = mtg;
+ pawnToGo[c] = s;
+ }
+ }
+ }
+ }