// Penalize rooks which are trapped inside a king. Penalize more if
// king has lost right to castle.
if ( ((file_of(ksq) < FILE_E) == (file_of(s) < file_of(ksq)))
- && rank_of(ksq) == rank_of(s)
- && relative_rank(Us, ksq) == RANK_1
+ && (rank_of(ksq) == rank_of(s) || relative_rank(Us, ksq) == RANK_1)
&& !ei.pi->half_open_on_side(Us, file_of(ksq), file_of(ksq) < FILE_E))
score -= (TrappedRookPenalty - make_score(mob * 8, 0)) * (pos.can_castle(Us) ? 1 : 2);
}