X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fevaluate.cpp;h=09f06d2983e0b644bf9dadd94fa6efc7baae1051;hp=0f2744d9e4ec42abd243b45527d2ff16dff0537a;hb=3549d98d07a6f0d04e4d020e009903dd82d0fadf;hpb=c73706243672bf36b0fef58e817f843cb341d8ca diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 0f2744d9..09f06d29 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -183,9 +183,11 @@ namespace { const Score BishopPawns = S( 8, 12); const Score RookOnPawn = S( 8, 24); const Score TrappedRook = S(92, 0); - const Score Checked = S(20, 20); + const Score SafeCheck = S(20, 20); + const Score OtherCheck = S(10, 10); const Score ThreatByHangingPawn = S(71, 61); const Score LooseEnemies = S( 0, 25); + const Score WeakQueen = S(35, 0); const Score Hanging = S(48, 27); const Score ThreatByPawnPush = S(38, 22); const Score Unstoppable = S( 0, 20); @@ -209,10 +211,10 @@ namespace { // Penalties for enemy's safe checks const int QueenContactCheck = 89; - const int QueenCheck = 52; - const int RookCheck = 45; - const int BishopCheck = 5; - const int KnightCheck = 17; + const int QueenCheck = 62; + const int RookCheck = 57; + const int BishopCheck = 48; + const int KnightCheck = 78; // eval_init() initializes king and attack bitboards for a given color @@ -366,9 +368,10 @@ namespace { template Score evaluate_king(const Position& pos, const EvalInfo& ei) { - const Color Them = (Us == WHITE ? BLACK : WHITE); + const Color Them = (Us == WHITE ? BLACK : WHITE); + const Square Up = (Us == WHITE ? DELTA_N : DELTA_S); - Bitboard undefended, b, b1, b2, safe; + Bitboard undefended, b, b1, b2, safe, other; int attackUnits; const Square ksq = pos.square(Us); @@ -396,8 +399,8 @@ namespace { // the pawn shelter (current 'score' value). attackUnits = std::min(72, ei.kingAttackersCount[Them] * ei.kingAttackersWeight[Them]) + 9 * ei.kingAdjacentZoneAttacksCount[Them] - + 27 * popcount(undefended) - + 11 * (popcount(b) + !!ei.pinnedPieces[Us]) + + 21 * popcount(undefended) + + 12 * (popcount(b) + !!ei.pinnedPieces[Us]) - 64 * !pos.count(Them) - mg_value(score) / 8; @@ -414,27 +417,42 @@ namespace { attackUnits += QueenContactCheck * popcount(b); } - // Analyse the enemy's safe distance checks for sliders and knights - safe = ~(ei.attackedBy[Us][ALL_PIECES] | pos.pieces(Them)); + // Analyse the safe enemy's checks which are possible on next move... + safe = ~(ei.attackedBy[Us][ALL_PIECES] | pos.pieces(Them)); + + // ... and some other potential checks, only requiring the square to be + // safe from pawn-attacks, and not being occupied by a blocked pawn. + other = ~( ei.attackedBy[Us][PAWN] + | (pos.pieces(Them, PAWN) & shift_bb(pos.pieces(PAWN)))); - b1 = pos.attacks_from(ksq) & safe; - b2 = pos.attacks_from(ksq) & safe; + b1 = pos.attacks_from(ksq); + b2 = pos.attacks_from(ksq); // Enemy queen safe checks - if ((b1 | b2) & ei.attackedBy[Them][QUEEN]) - attackUnits += QueenCheck, score -= Checked; + if ((b1 | b2) & ei.attackedBy[Them][QUEEN] & safe) + attackUnits += QueenCheck, score -= SafeCheck; + + // Enemy rooks safe and other checks + if (b1 & ei.attackedBy[Them][ROOK] & safe) + attackUnits += RookCheck, score -= SafeCheck; - // Enemy rooks safe checks - if (b1 & ei.attackedBy[Them][ROOK]) - attackUnits += RookCheck, score -= Checked; + else if (b1 & ei.attackedBy[Them][ROOK] & other) + score -= OtherCheck; - // Enemy bishops safe checks - if (b2 & ei.attackedBy[Them][BISHOP]) - attackUnits += BishopCheck, score -= Checked; + // Enemy bishops safe and other checks + if (b2 & ei.attackedBy[Them][BISHOP] & safe) + attackUnits += BishopCheck, score -= SafeCheck; - // Enemy knights safe checks - if (pos.attacks_from(ksq) & ei.attackedBy[Them][KNIGHT] & safe) - attackUnits += KnightCheck, score -= Checked; + else if (b2 & ei.attackedBy[Them][BISHOP] & other) + score -= OtherCheck; + + // Enemy knights safe and other checks + b = pos.attacks_from(ksq) & ei.attackedBy[Them][KNIGHT]; + if (b & safe) + attackUnits += KnightCheck, score -= SafeCheck; + + else if (b & other) + score -= OtherCheck; // Finally, extract the king danger score from the KingDanger[] // array and subtract the score from the evaluation. @@ -471,6 +489,13 @@ namespace { & ~(ei.attackedBy[Us][ALL_PIECES] | ei.attackedBy[Them][ALL_PIECES])) score += LooseEnemies; + // Bonus for pin or discovered attack on the opponent queen + if ( pos.count(Them) == 1 + && pos.slider_blockers(pos.pieces(), + pos.pieces(Us, ROOK, BISHOP), + pos.square(Them))) + score += WeakQueen; + // Non-pawn enemies attacked by a pawn weak = (pos.pieces(Them) ^ pos.pieces(Them, PAWN)) & ei.attackedBy[Us][PAWN];