assert(pos.piece_on(s) == make_piece(Us, PAWN));
File f = file_of(s);
- Rank r = relative_rank(Us, s);
++ Rank r = relative_rank(Us, s, pos.max_rank());
e->semiopenFiles[Us] &= ~(1 << f);
e->pawnAttacksSpan[Us] |= pawn_attack_span(Us, s);
// Flag the pawn
opposed = theirPawns & forward_file_bb(Us, s);
stoppers = theirPawns & passed_pawn_span(Us, s);
- lever = theirPawns & PawnAttacks[Us][s];
- leverPush = theirPawns & PawnAttacks[Us][s + Up];
- doubled = ourPawns & (s - Up);
+ lever = theirPawns & PseudoAttacks[Us][PAWN][s];
+ leverPush = relative_rank(Them, s, pos.max_rank()) > RANK_1 ? theirPawns & PseudoAttacks[Us][PAWN][s + Up] : 0;
- doubled = relative_rank(Us, s, pos.max_rank()) > RANK_1 ? ourPawns & (s - Up) : 0;
++ doubled = r > RANK_1 ? ourPawns & (s - Up) : 0;
neighbours = ourPawns & adjacent_files_bb(f);
phalanx = neighbours & rank_bb(s);
- support = relative_rank(Us, s, pos.max_rank()) > RANK_1 ? neighbours & rank_bb(s - Up) : 0;
- support = neighbours & rank_bb(s - Up);
++ support = r > RANK_1 ? neighbours & rank_bb(s - Up) : 0;
// A pawn is backward when it is behind all pawns of the same color
// on the adjacent files and cannot be safely advanced.
&& popcount(phalanx) >= popcount(leverPush))
e->passedPawns[Us] |= s;
- else if (stoppers == square_bb(s + Up) && r >= RANK_5)
+ else if ( relative_rank(Them, s, pos.max_rank()) > RANK_1
+ && stoppers == square_bb(s + Up)
- && relative_rank(Us, s, pos.max_rank()) >= RANK_5)
++ && r >= RANK_5)
{
b = shift<Up>(support) & ~theirPawns;
while (b)