phalanx = neighbours & rank_bb(s);
supported = neighbours & rank_bb(s - Up);
- // A pawn is backward when it is behind all pawns of the same color on the
- // adjacent files and cannot be safely advanced.
- if (!neighbours || lever || relative_rank(Us, s) >= RANK_5)
- backward = false;
- else
- {
- // Find the backmost rank with neighbours or stoppers
- b = rank_bb(backmost_sq(Us, neighbours | stoppers));
-
- // The pawn is backward when it cannot safely progress to that rank:
- // either there is a stopper in the way on this rank, or there is a
- // stopper on adjacent file which controls the way to that rank.
- backward = (b | shift<Up>(b & adjacent_files_bb(f))) & stoppers;
-
- assert(!(backward && (forward_ranks_bb(Them, s + Up) & neighbours)));
- }
+ // A pawn is backward when it is behind all pawns of the same color
+ // on the adjacent files and cannot be safely advanced.
+ backward = !lever && !(ourPawns & pawn_attack_span(Them, s + Up))
+ && (stoppers & (leverPush | (s + Up)));
// Passed pawns will be properly scored in evaluation because we need
// full attack info to evaluate them. Include also not passed pawns
void init() {
- static constexpr int Seed[RANK_NB] = { 0, 13, 24, 18, 76, 100, 175, 330 };
+ static constexpr int Seed[RANK_NB] = { 0, 13, 24, 18, 65, 100, 175, 330 };
for (int opposed = 0; opposed <= 1; ++opposed)
for (int phalanx = 0; phalanx <= 1; ++phalanx)
enum { Unopposed, BlockedByPawn, Unblocked };
constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
- constexpr Direction Up = (Us == WHITE ? NORTH : SOUTH);
- constexpr Bitboard BlockRanks = (Us == WHITE ? Rank2BB | Rank3BB : Rank7BB | Rank6BB);
+ constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH);
+ constexpr Bitboard BlockRanks = (Us == WHITE ? Rank1BB | Rank2BB : Rank8BB | Rank7BB);
Bitboard b = pos.pieces(PAWN) & (forward_ranks_bb(Us, ksq) | rank_bb(ksq));
Bitboard ourPawns = b & pos.pieces(Us);
Value safety = (ourPawns & file_bb(ksq)) ? Value(5) : Value(-5);
- if ((theirPawns & (FileABB | FileHBB) & BlockRanks) & (ksq + Up))
+ if ((shift<Down>(theirPawns) & (FileABB | FileHBB) & BlockRanks) & ksq)
safety += 374;
File center = std::max(FILE_B, std::min(FILE_G, file_of(ksq)));