template<Color Us>
Score evaluate(const Position& pos, Pawns::Entry* e) {
- constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
+ constexpr Color Them = ~Us;
constexpr Direction Up = pawn_push(Us);
Bitboard neighbours, stoppers, support, phalanx, opposed;
e->passedPawns[Us] = 0;
e->kingSquares[Us] = SQ_NONE;
e->pawnAttacks[Us] = e->pawnAttacksSpan[Us] = pawn_attacks_bb<Us>(ourPawns);
+ e->blockedCount[Us] = 0;
// Loop through all pawns of the current color and score each pawn
while ((s = *pl++) != SQ_NONE)
phalanx = neighbours & rank_bb(s);
support = neighbours & rank_bb(s - Up);
+ e->blockedCount[Us] += bool(blocked);
+
// A pawn is backward when it is behind all pawns of the same color on
// the adjacent files and cannot safely advance.
backward = !(neighbours & forward_ranks_bb(Them, s + Up))
// (a) there is no stoppers except some levers
// (b) the only stoppers are the leverPush, but we outnumber them
// (c) there is only one front stopper which can be levered.
+ // (Refined in Evaluation::passed)
passed = !(stoppers ^ lever)
|| ( !(stoppers ^ leverPush)
&& popcount(phalanx) >= popcount(leverPush))
|| ( stoppers == blocked && r >= RANK_5
&& (shift<Up>(support) & ~(theirPawns | doubleAttackThem)));
+ passed &= !(forward_file_bb(Us, s) & ourPawns);
+
// Passed pawns will be properly scored later in evaluation when we have
// full attack info.
if (passed)
// Score this pawn
if (support | phalanx)
{
- int v = Connected[r] * (2 + bool(phalanx) - bool(opposed))
+ int v = Connected[r] * (4 + 2 * bool(phalanx) - 2 * bool(opposed) - bool(blocked)) / 2
+ 21 * popcount(support);
score += make_score(v, v * (r - 2) / 4);
template<Color Us>
Score Entry::evaluate_shelter(const Position& pos, Square ksq) {
- constexpr Color Them = (Us == WHITE ? BLACK : WHITE);
+ constexpr Color Them = ~Us;
Bitboard b = pos.pieces(PAWN) & ~forward_ranks_bb(Them, ksq);
Bitboard ourPawns = b & pos.pieces(Us);
b = theirPawns & file_bb(f);
int theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;
- File d = map_to_queenside(f);
+ File d = File(edge_distance(f));
bonus += make_score(ShelterStrength[d][ourRank], 0);
if (ourRank && (ourRank == theirRank - 1))