From: Alain SAVARD Date: Fri, 6 May 2016 13:40:56 +0000 (-0400) Subject: Unsafe checks X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=4b9ed6566a7ed026160fc79b778f95e62fde22a1;ds=sidebyside Unsafe checks Introducing a new multi-purpose penalty related to King safety, which includes all kind of potential checks (from unsafe or unavailable squares currently occupied by some other piece) This will indirectly detect and reward some pins, discovered checks, and motifs such as square vacation, or rook behind its pawn and aligned with King (example Black Rg8, g7 against Kg1), and penalize some pawn blockers (if they move, it allows a discovered check by the pawn). And since it looks also at protected squares, it detects some potential defense overloading. Finally, the rook contact checks had been removed some time ago. This test will give a small bonus for them, as well as for bishop contact checks. Passed STC http://tests.stockfishchess.org/tests/view/5729ec740ebc59301a354b36 LLR: 2.94 (-2.94,2.94) [0.00,5.00] Total: 13306 W: 2477 L: 2296 D: 8533 and LTC http://tests.stockfishchess.org/tests/view/572a5be00ebc59301a354b65 LLR: 2.97 (-2.94,2.94) [0.00,5.00] Total: 20369 W: 2750 L: 2565 D: 15054 bench: 9298175 --- diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 0f2744d9..4a52e626 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -183,7 +183,8 @@ 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 Hanging = S(48, 27); @@ -366,9 +367,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); @@ -414,27 +416,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; + + else if (b1 & ei.attackedBy[Them][ROOK] & other) + score -= OtherCheck; + + // Enemy bishops safe and other checks + if (b2 & ei.attackedBy[Them][BISHOP] & safe) + attackUnits += BishopCheck, score -= SafeCheck; - // Enemy rooks safe checks - if (b1 & ei.attackedBy[Them][ROOK]) - attackUnits += RookCheck, score -= Checked; + else if (b2 & ei.attackedBy[Them][BISHOP] & other) + score -= OtherCheck; - // Enemy bishops safe checks - if (b2 & ei.attackedBy[Them][BISHOP]) - attackUnits += BishopCheck, score -= Checked; + // Enemy knights safe and other checks + b = pos.attacks_from(ksq) & ei.attackedBy[Them][KNIGHT]; + if (b & safe) + attackUnits += KnightCheck, score -= SafeCheck; - // Enemy knights safe checks - if (pos.attacks_from(ksq) & ei.attackedBy[Them][KNIGHT] & safe) - attackUnits += KnightCheck, score -= Checked; + else if (b & other) + score -= OtherCheck; // Finally, extract the king danger score from the KingDanger[] // array and subtract the score from the evaluation.