From 3f7ec977cdae7a59c58342f3752bccb293d4e206 Mon Sep 17 00:00:00 2001 From: Vizvezdenec Date: Fri, 1 Feb 2019 09:21:23 +0300 Subject: [PATCH] More precise checks evaluation in king danger Remove overlapping safe checks from kingdanger: - rook and queen checks from the same square: rook check is preferred - bishop and queen checks form the same square: queen check is preferred Increase bishop and rook check values as a compensation. STC LLR: 2.95 (-2.94,2.94) [0.50,4.50] Total: 27480 W: 6111 L: 5813 D: 15556 http://tests.stockfishchess.org/tests/view/5c521d050ebc593af5d4e66a LTC LLR: 2.95 (-2.94,2.94) [0.00,3.50] Total: 78500 W: 13145 L: 12752 D: 52603 http://tests.stockfishchess.org/tests/view/5c52b9460ebc592fc7baecc5 Closes https://github.com/official-stockfish/Stockfish/pull/1983 ------------------------------------------ I have quite a few ideas of how to improve this patch. - actually rethinking it now it will maybe be useful to discount queen/bishop checks if there is only one square that they can give check from and it's "occupied" by more valuable check. Right now count of this squares does not really matter. - maybe some small extra bonus can be given for overlapping checks. - some ideas about using popcount() on safechecks can be retried. - tune this safecheck values since they were more or less randomly handcrafted in this patch. Bench: 3216489 --- src/evaluate.cpp | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 6bacb4ed..da90eed9 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) @@ -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 -- 2.39.2