diff --git a/src/evaluate.cpp b/src/evaluate.cpp index da4b9c30..d00b862f 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -384,14 +384,17 @@ namespace { // Main king safety evaluation if (ei.kingAttackersCount[Them]) { - // Find the attacked squares around the king which have no defenders - // apart from the king itself. + // Find the attacked squares which are defended only by the king... undefended = ei.attackedBy[Them][ALL_PIECES] & ei.attackedBy[Us][KING] & ~( ei.attackedBy[Us][PAWN] | ei.attackedBy[Us][KNIGHT] | ei.attackedBy[Us][BISHOP] | ei.attackedBy[Us][ROOK] | ei.attackedBy[Us][QUEEN]); + // ... and those which are not defended at all in the larger king ring + b = ei.attackedBy[Them][ALL_PIECES] & ~ei.attackedBy[Us][ALL_PIECES] + & ei.kingRing[Us] & ~pos.pieces(Them); + // Initialize the 'attackUnits' variable, which is used later on as an // index into the KingDanger[] array. The initial value is based on the // number and types of the enemy's attacking pieces, the number of @@ -400,7 +403,7 @@ namespace { attackUnits = std::min(72, ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them]) + 9 * ei.kingAdjacentZoneAttacksCount[Them] + 27 * popcount(undefended) - + 11 * !!ei.pinnedPieces[Us] + + 11 * (popcount(b) + !!ei.pinnedPieces[Us]) - 64 * !pos.count(Them) - mg_value(score) / 8;