X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=617e33fbe93a2b337b4fd42471a60a619e5b2f48;hp=725ea49ce05ba1d6981ca15f460afae8535169c0;hb=651450023619ddea590f301f040286151004df66;hpb=eb6d7f537d214c4dc8bde7d4fdc2aaead47dd3c3 diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 725ea49c..617e33fb 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -93,8 +93,8 @@ namespace { // Penalties for enemy's safe checks constexpr int QueenSafeCheck = 780; - constexpr int RookSafeCheck = 880; - constexpr int BishopSafeCheck = 435; + constexpr int RookSafeCheck = 1080; + constexpr int BishopSafeCheck = 635; constexpr int KnightSafeCheck = 790; #define S(mg, eg) make_score(mg, eg) @@ -168,7 +168,7 @@ namespace { constexpr Score ThreatByPawnPush = S( 48, 39); constexpr Score ThreatByRank = S( 13, 0); constexpr Score ThreatBySafePawn = S(173, 94); - constexpr Score TrappedRook = S( 96, 4); + constexpr Score TrappedRook = S( 47, 4); constexpr Score WeakQueen = S( 49, 15); constexpr Score WeakUnopposedPawn = S( 12, 23); @@ -377,7 +377,7 @@ namespace { { File kf = file_of(pos.square(Us)); if ((kf < FILE_E) == (file_of(s) < kf)) - score -= (TrappedRook - make_score(mob * 22, 0)) * (1 + !pos.castling_rights(Us)); + score -= TrappedRook * (1 + !pos.castling_rights(Us)); } } @@ -434,27 +434,42 @@ namespace { b1 = attacks_bb(ksq, pos.pieces() ^ pos.pieces(Us, QUEEN)); b2 = attacks_bb(ksq, pos.pieces() ^ pos.pieces(Us, QUEEN)); - // Enemy queen safe checks - if ((b1 | b2) & attackedBy[Them][QUEEN] & safe & ~attackedBy[Us][QUEEN]) - kingDanger += QueenSafeCheck; - - b1 &= attackedBy[Them][ROOK]; - b2 &= attackedBy[Them][BISHOP]; - // Enemy rooks checks - if (b1 & safe) + Bitboard RookCheck = b1 + & safe + & attackedBy[Them][ROOK]; + + if (RookCheck) kingDanger += RookSafeCheck; else - unsafeChecks |= b1; + unsafeChecks |= b1 & attackedBy[Them][ROOK]; + + // Enemy queen safe checks: we count them only if they are from squares from + // which we can't give a rook check, because rook checks are more valuable. + Bitboard QueenCheck = (b1 | b2) + & attackedBy[Them][QUEEN] + & safe + & ~attackedBy[Us][QUEEN] + & ~RookCheck; - // Enemy bishops checks - if (b2 & safe) + if (QueenCheck) + kingDanger += QueenSafeCheck; + + // Enemy bishops checks: we count them only if they are from squares from + // which we can't give a queen check, because queen checks are more valuable. + Bitboard BishopCheck = b2 + & attackedBy[Them][BISHOP] + & safe + & ~QueenCheck; + + if (BishopCheck) kingDanger += BishopSafeCheck; else - unsafeChecks |= b2; + unsafeChecks |= b2 & attackedBy[Them][BISHOP]; // Enemy knights checks b = pos.attacks_from(ksq) & attackedBy[Them][KNIGHT]; + if (b & safe) kingDanger += KnightSafeCheck; else @@ -467,12 +482,13 @@ namespace { kingDanger += kingAttackersCount[Them] * kingAttackersWeight[Them] + 69 * kingAttacksCount[Them] + 185 * popcount(kingRing[Us] & weak) + - 100 * bool(attackedBy[Us][KNIGHT] & attackedBy[Us][KING]) + 150 * popcount(pos.blockers_for_king(Us) | unsafeChecks) - + tropism * tropism / 4 + + 5 * tropism * tropism / 16 - 873 * !pos.count(Them) - 6 * mg_value(score) / 8 + mg_value(mobility[Them] - mobility[Us]) - - 30; + - 25; // Transform the kingDanger units into a Score, and subtract it from the evaluation if (kingDanger > 0) @@ -701,7 +717,8 @@ namespace { if (pos.non_pawn_material() < SpaceThreshold) return SCORE_ZERO; - constexpr Color Them = (Us == WHITE ? BLACK : WHITE); + constexpr Color Them = (Us == WHITE ? BLACK : WHITE); + constexpr Direction Down = (Us == WHITE ? SOUTH : NORTH); constexpr Bitboard SpaceMask = Us == WHITE ? CenterFiles & (Rank2BB | Rank3BB | Rank4BB) : CenterFiles & (Rank7BB | Rank6BB | Rank5BB); @@ -713,8 +730,8 @@ namespace { // Find all squares which are at most three squares behind some friendly pawn Bitboard behind = pos.pieces(Us, PAWN); - behind |= (Us == WHITE ? behind >> 8 : behind << 8); - behind |= (Us == WHITE ? behind >> 16 : behind << 16); + behind |= shift(behind); + behind |= shift(shift(behind)); int bonus = popcount(safe) + popcount(behind & safe); int weight = pos.count(Us) @@ -743,12 +760,12 @@ namespace { && (pos.pieces(PAWN) & KingSide); // Compute the initiative bonus for the attacking side - int complexity = 8 * pe->pawn_asymmetry() - + 12 * pos.count() - + 12 * outflanking - + 16 * pawnsOnBothFlanks - + 48 * !pos.non_pawn_material() - -118 ; + int complexity = 9 * pe->pawn_asymmetry() + + 11 * pos.count() + + 9 * outflanking + + 18 * pawnsOnBothFlanks + + 49 * !pos.non_pawn_material() + -121 ; // Now apply the bonus: note that we find the attacking side by extracting // the sign of the endgame value, and that we carefully cap the bonus so