X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=5ceb9ae145cab0234ac8127c7ec3ea7868670bc5;hp=26fd20bba5d577e6d5022c62adfdc0cb1691f57e;hb=41bc0d56608c01adf104d2bd0213342c82fa4ab5;hpb=062eb074c8a7353f151aa324a21d5d25bc33e431 diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 26fd20bb..5ceb9ae1 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -140,47 +140,41 @@ namespace { S(0, 0), S(0, 24), S(38, 71), S(38, 61), S(0, 38), S(36, 38) }; - // ThreatByKing[on one/on many] contains bonuses for king attacks on - // pawns or pieces which are not pawn-defended. - constexpr Score ThreatByKing[] = { S(25, 57), S(4, 139) }; - // PassedRank[Rank] contains a bonus according to the rank of a passed pawn constexpr Score PassedRank[RANK_NB] = { - S(0, 0), S(7, 10), S(7, 26), S(14, 31), S(42, 63), S(178, 167), S(279, 244) + S(0, 0), S(5, 18), S(12, 23), S(10, 31), S(57, 62), S(163, 167), S(271, 250) }; // PassedFile[File] contains a bonus according to the file of a passed pawn constexpr Score PassedFile[FILE_NB] = { - S( 17, 6), S(-4, 7), S( 2,-12), S(-17,-14), - S(-17,-14), S( 2,-12), S(-4, 7), S( 17, 6) + S( -1, 7), S( 0, 9), S(-9, -8), S(-30,-14), + S(-30,-14), S(-9, -8), S( 0, 9), S( -1, 7) }; // PassedDanger[Rank] contains a term to weight the passed score - constexpr int PassedDanger[RANK_NB] = { 0, 0, 0, 3, 6, 12, 21 }; - - // KingProtector[PieceType-2] contains a penalty according to distance from king - constexpr Score KingProtector[] = { S(3, 5), S(5, 3), S(3, 0), S(0, -2) }; + constexpr int PassedDanger[RANK_NB] = { 0, 0, 0, 3, 7, 11, 20 }; // Assorted bonuses and penalties - constexpr Score BishopPawns = S( 3, 5); - constexpr Score CloseEnemies = S( 8, 0); - constexpr Score Connectivity = S( 3, 1); + constexpr Score BishopPawns = S( 3, 7); + constexpr Score CloseEnemies = S( 6, 0); constexpr Score CorneredBishop = S( 50, 50); constexpr Score Hanging = S( 52, 30); - constexpr Score HinderPassedPawn = S( 5, 2); + constexpr Score HinderPassedPawn = S( 4, 0); + constexpr Score KingProtector = S( 6, 6); constexpr Score KnightOnQueen = S( 21, 11); constexpr Score LongDiagonalBishop = S( 22, 0); constexpr Score MinorBehindPawn = S( 16, 0); - constexpr Score Overload = S( 10, 5); + constexpr Score Overload = S( 16, 7); constexpr Score PawnlessFlank = S( 20, 80); constexpr Score RookOnPawn = S( 8, 24); constexpr Score SliderOnQueen = S( 42, 21); - constexpr Score ThreatByPawnPush = S( 49, 30); + constexpr Score ThreatByKing = S( 23, 76); + constexpr Score ThreatByPawnPush = S( 45, 40); constexpr Score ThreatByRank = S( 16, 3); - constexpr Score ThreatBySafePawn = S(186,140); + constexpr Score ThreatBySafePawn = S(173,102); constexpr Score TrappedRook = S( 92, 0); constexpr Score WeakQueen = S( 50, 10); - constexpr Score WeakUnopposedPawn = S( 14, 19); + constexpr Score WeakUnopposedPawn = S( 5, 29); #undef S @@ -330,9 +324,6 @@ namespace { mobility[Us] += MobilityBonus[Pt - 2][mob]; - // Penalty if the piece is far from the king - score -= KingProtector[Pt - 2] * distance(s, pos.square(Us)); - if (Pt == BISHOP || Pt == KNIGHT) { // Bonus if piece is on an outpost square or can reach one @@ -343,11 +334,13 @@ namespace { else if (bb &= b & ~pos.pieces(Us)) score += Outpost[Pt == BISHOP][bool(attackedBy[Us][PAWN] & bb)]; - // Bonus when behind a pawn - if ( relative_rank(Us, s) < RANK_5 - && (pos.pieces(PAWN) & (s + pawn_push(Us)))) + // Knight and Bishop bonus for being right behind a pawn + if (shift(pos.pieces(PAWN)) & s) score += MinorBehindPawn; + // Penalty if the piece is far from the king + score -= KingProtector * distance(s, pos.square(Us)); + if (Pt == BISHOP) { // Penalty according to number of pawns on the same color square as the @@ -428,7 +421,7 @@ namespace { // Main king safety evaluation if (kingAttackersCount[Them] > 1 - pos.count(Them)) { - int kingDanger = -mg_value(score); + int kingDanger = 0; unsafeChecks = 0; // Attacked squares defended at most once by our queen or king @@ -474,11 +467,12 @@ namespace { unsafeChecks &= mobilityArea[Them]; kingDanger += kingAttackersCount[Them] * kingAttackersWeight[Them] - + 64 * kingAttacksCount[Them] - + 182 * popcount(kingRing[Us] & weak) - + 128 * popcount(pos.blockers_for_king(Us) | unsafeChecks) - - 857 * !pos.count(Them) - + 31 ; + + 69 * kingAttacksCount[Them] + + 185 * popcount(kingRing[Us] & weak) + + 129 * popcount(pos.blockers_for_king(Us) | unsafeChecks) + - 873 * !pos.count(Them) + - 6 * mg_value(score) / 8 + - 2 ; // Transform the kingDanger units into a Score, and subtract it from the evaluation if (kingDanger > 0) @@ -557,15 +551,15 @@ namespace { score += ThreatByRank * (int)relative_rank(Them, s); } - b = weak & attackedBy[Us][KING]; - if (b) - score += ThreatByKing[more_than_one(b)]; + // Bonus for king attacks on pawns or pieces which are not pawn-defended + if (weak & attackedBy[Us][KING]) + score += ThreatByKing; score += Hanging * popcount(weak & ~attackedBy[Them][ALL_PIECES]); - // Bonus for overload (non-pawn enemies attacked and defended exactly once) + // Bonus for overload (non-pawn enemies attacked once or more and defended exactly once) b = nonPawnEnemies - & attackedBy[Us][ALL_PIECES] & ~attackedBy2[Us] + & attackedBy[Us][ALL_PIECES] & attackedBy[Them][ALL_PIECES] & ~attackedBy2[Them]; score += Overload * popcount(b); } @@ -612,10 +606,6 @@ namespace { score += SliderOnQueen * popcount(b & safeThreats & attackedBy2[Us]); } - // Connectivity: ensure that knights, bishops, rooks, and queens are protected - b = (pos.pieces(Us) ^ pos.pieces(Us, PAWN, KING)) & attackedBy[Us][ALL_PIECES]; - score += Connectivity * popcount(b); - if (T) Trace::add(THREAT, Us, score); @@ -646,7 +636,7 @@ namespace { assert(!(pos.pieces(Them, PAWN) & forward_file_bb(Us, s + Up))); - bb = forward_file_bb(Us, s) & (attackedBy[Them][ALL_PIECES] | pos.pieces(Them)); + bb = forward_file_bb(Us, s) & pos.pieces(Them); score -= HinderPassedPawn * popcount(bb); int r = relative_rank(Us, s); @@ -770,9 +760,9 @@ namespace { && (pos.pieces(PAWN) & KingSide); // Compute the initiative bonus for the attacking side - int complexity = 8 * outflanking - + 8 * pe->pawn_asymmetry() + int complexity = 8 * pe->pawn_asymmetry() + 12 * pos.count() + + 12 * outflanking + 16 * pawnsOnBothFlanks + 48 * !pos.non_pawn_material() -136 ;