-/// K, rook and two pawns vs K, rook and one pawn. There is only a single
-/// pattern: If the stronger side has no passed pawns and the defending king
-/// is actively placed, the position is drawish.
+ // Test for a rook pawn
+ if (pos.pieces(PAWN) & (FileABB | FileHBB))
+ {
+ Square ksq = pos.square<KING>(weakSide);
+ Square bsq = pos.square<BISHOP>(weakSide);
+ Square psq = pos.square<PAWN>(strongSide);
+ Rank rk = relative_rank(strongSide, psq);
+ Direction push = pawn_push(strongSide);
+
+ // If the pawn is on the 5th rank and the pawn (currently) is on
+ // the same color square as the bishop then there is a chance of
+ // a fortress. Depending on the king position give a moderate
+ // reduction or a stronger one if the defending king is near the
+ // corner but not trapped there.
+ if (rk == RANK_5 && !opposite_colors(bsq, psq))
+ {
+ int d = distance(psq + 3 * push, ksq);
+
+ if (d <= 2 && !(d == 0 && ksq == pos.square<KING>(strongSide) + 2 * push))
+ return ScaleFactor(24);
+ else
+ return ScaleFactor(48);
+ }
+
+ // When the pawn has moved to the 6th rank we can be fairly sure
+ // it's drawn if the bishop attacks the square in front of the
+ // pawn from a reasonable distance and the defending king is near
+ // the corner
+ if ( rk == RANK_6
+ && distance(psq + 2 * push, ksq) <= 1
+ && (PseudoAttacks[BISHOP][bsq] & (psq + push))
+ && distance<File>(bsq, psq) >= 2)
+ return ScaleFactor(8);
+ }
+
+ return SCALE_FACTOR_NONE;
+}
+
+/// KRPP vs KRP. There is just a single rule: if the stronger side has no passed
+/// pawns and the defending king is actively placed, the position is drawish.