X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fpawns.cpp;h=c89f2d0585891ec2ebe253b89de39eb305f56a8f;hp=1cdeb461d51e2a2e74a56860f3d3e3c65998d70d;hb=26a8b844177ad6abd4aca1bef2ebb7f644bd465c;hpb=1d4e7bbdf5a8b2e87daaa54eea52cbe01d699fdb diff --git a/src/pawns.cpp b/src/pawns.cpp index 1cdeb461..c89f2d05 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -183,7 +183,7 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns, Square s; File f; Rank r; - int bonus; + int bonus, backwardWeight; bool passed, isolated, doubled, opposed, chain, backward, candidate; Score value = make_score(0, 0); const Square* ptr = pos.piece_list_begin(Us, PAWN); @@ -214,7 +214,7 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns, pi->qsStormValue[Us] += QStormTable[relative_square(Us, s)] + bonus; // Our rank plus previous one. Used for chain detection. - b = rank_bb(r) | rank_bb(r + (Us == WHITE ? -1 : 1)); + b = rank_bb(r) | rank_bb(Us == WHITE ? r - 1 : r + 1); // Passed, isolated, doubled or member of a pawn // chain (but not the backward one) ? @@ -226,15 +226,16 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns, // Test for backward pawn // + backward = false; + backwardWeight = 6; + // If the pawn is passed, isolated, or member of a pawn chain // it cannot be backward. If can capture an enemy pawn or if // there are friendly pawns behind on neighboring files it cannot // be backward either. - if ( (passed | isolated | chain) - || (ourPawns & attack_span_mask(opposite_color(Us), s)) - || (pos.attacks_from(s, Us) & theirPawns)) - backward = false; - else + if ( !(passed | isolated | chain) + && !(ourPawns & attack_span_mask(opposite_color(Us), s)) + && !(pos.attacks_from(s, Us) & theirPawns)) { // We now know that there are no friendly pawns beside or behind this // pawn on neighboring files. We now check whether the pawn is @@ -245,7 +246,12 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns, // Note that we are sure to find something because pawn is not passed // nor isolated, so loop is potentially infinite, but it isn't. while (!(b & (ourPawns | theirPawns))) + { Us == WHITE ? b <<= 8 : b >>= 8; + backwardWeight--; + } + + assert(backwardWeight > 0); // The friendly pawn needs to be at least two ranks closer than the enemy // pawn in order to help the potentially backward pawn advance. @@ -274,7 +280,7 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns, if (isolated) { value -= IsolatedPawnPenalty[f]; - if (!(theirPawns & file_bb(f))) + if (!opposed) value -= IsolatedPawnPenalty[f] / 2; } if (doubled) @@ -282,8 +288,8 @@ Score PawnInfoTable::evaluate_pawns(const Position& pos, Bitboard ourPawns, if (backward) { - value -= BackwardPawnPenalty[f]; - if (!(theirPawns & file_bb(f))) + value -= backwardWeight * BackwardPawnPenalty[f] / 4; + if (!opposed) value -= BackwardPawnPenalty[f] / 2; } if (chain)