From: Fabian Fichter Date: Sat, 15 Dec 2018 15:17:48 +0000 (+0100) Subject: Rewrite bonus for safe and unsafe checks X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=b255986efc42a86d7d5a4538f4e6ff773136953f;p=fairystockfish.git Rewrite bonus for safe and unsafe checks crazyhouse STC LLR: 2.97 (-2.94,2.94) [0.00,10.00] Total: 330 W: 211 L: 107 D: 12 http://35.161.250.236:6543/tests/view/5c14de9f6e23db7639060ce8 shogi LLR: 2.95 (-2.94,2.94) [-10.00,5.00] Total: 736 W: 387 L: 326 D: 23 minishogi LLR: 2.97 (-2.94,2.94) [-10.00,5.00] Total: 1658 W: 820 L: 766 D: 72 euroshogi LLR: 3.00 (-2.94,2.94) [-10.00,5.00] Total: 476 W: 259 L: 196 D: 21 --- diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 9fa6cb6..7bebf7a 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -95,6 +95,7 @@ namespace { constexpr int RookSafeCheck = 880; constexpr int BishopSafeCheck = 435; constexpr int KnightSafeCheck = 790; + constexpr int OtherSafeCheck = 600; #define S(mg, eg) make_score(mg, eg) @@ -468,34 +469,41 @@ namespace { safe = ~pos.pieces(Them); safe &= ~attackedBy[Us][ALL_PIECES] | (weak & attackedBy2[Them]); - 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) - kingDanger += RookSafeCheck; - else - unsafeChecks |= b1; - - // Enemy bishops checks - if (b2 & safe) - kingDanger += BishopSafeCheck; - else - unsafeChecks |= b2; - - // Enemy knights checks - b = pos.attacks_from(Us, ksq) & attackedBy[Them][KNIGHT]; - if (b & safe) - kingDanger += KnightSafeCheck; - else - unsafeChecks |= b; + std::function get_attacks = [this](PieceType pt) { + return attackedBy[Them][pt] | (pos.captures_to_hand() && pos.count_in_hand(Them, pt) ? ~pos.pieces() : 0); + }; + for (PieceType pt : pos.piece_types()) + { + switch (pt) + { + case QUEEN: + b = attacks_bb(Us, pt, ksq, pos.pieces() ^ pos.pieces(Us, QUEEN)) & get_attacks(pt) & safe & ~attackedBy[Us][QUEEN] & pos.board_bb(); + if (b) + kingDanger += QueenSafeCheck; + break; + case ROOK: + case BISHOP: + case KNIGHT: + b = attacks_bb(Us, pt, ksq, pos.pieces() ^ pos.pieces(Us, QUEEN)) & get_attacks(pt) & pos.board_bb(); + if (b & safe) + kingDanger += pt == ROOK ? RookSafeCheck + : pt == BISHOP ? BishopSafeCheck + : KnightSafeCheck; + else + unsafeChecks |= b; + break; + case PAWN: + case SHOGI_PAWN: + case KING: + break; + default: + b = attacks_bb(Us, pt, ksq, pos.pieces()) & get_attacks(pt) & pos.board_bb(); + if (b & safe) + kingDanger += OtherSafeCheck; + else + unsafeChecks |= b; + } + } // Unsafe or occupied checking squares will also be considered, as long as // the square is in the attacker's mobility area. @@ -504,7 +512,7 @@ namespace { kingDanger += kingAttackersCount[Them] * kingAttackersWeight[Them] + 102 * kingAttacksCount[Them] * (1 + pos.captures_to_hand() + !!pos.max_check_count()) + 191 * popcount(kingRing[Us] & weak) * (1 + pos.captures_to_hand() + !!pos.max_check_count()) - + 143 * popcount(pos.blockers_for_king(Us) | unsafeChecks) + + 143 * popcount(pos.blockers_for_king(Us) | unsafeChecks) * 64 / popcount(pos.board_bb()) - 848 * !(pos.count(Them) || pos.captures_to_hand()) - 9 * mg_value(score) / 8 + 100 * (pos.piece_drops() ? pos.count_in_hand(Them, ALL_PIECES) : 0)