From: snicolet Date: Thu, 23 Oct 2014 17:10:11 +0000 (+0800) Subject: Calculate maximum threat for hanging pieces X-Git-Url: https://git.sesse.net/?p=stockfish;a=commitdiff_plain;h=8d62ece9459b8338c27cf1fb52e27ea85d8061d5;hp=480682b67097160bfc25e52ab02facffeec104f0 Calculate maximum threat for hanging pieces Use the max_threat() helper function to estimate more precisely the best hanging piece threat. Also retunes the Threat array using SPSA. STC LLR: 2.95 (-2.94,2.94) [-1.50,4.50] Total: 7598 W: 1596 L: 1468 D: 4534 LTC LLR: 2.97 (-2.94,2.94) [0.00,6.00] Total: 7896 W: 1495 L: 1350 D: 5051 Bench: 6816504 Resolves #73 --- diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 1bfd9dfd..d03ae665 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -141,8 +141,8 @@ namespace { // Threat[attacking][attacked] contains bonuses according to which piece // type attacks which one. const Score Threat[][PIECE_TYPE_NB] = { - { S(0, 0), S( 7, 39), S(24, 49), S(24, 49), S(41,100), S(41,100) }, // Minor - { S(0, 0), S(15, 39), S(15, 45), S(15, 45), S(15, 45), S(24, 49) } // Major + { S(0, 0), S(0, 38), S(32, 45), S(32, 45), S(41,100), S(35,104) }, // Minor + { S(0, 0), S(7, 28), S(20, 49), S(20, 49), S(8 , 42), S(23, 44) } // Major }; // ThreatenedByPawn[PieceType] contains a penalty according to which piece @@ -490,6 +490,23 @@ namespace { return score; } + // max_threat() is a helper function to calculate the score of a set of threats. + // The set of threatened pieces is in the "targets" parameter, and we return + // the value of the threat on the biggest piece. + + template FORCE_INLINE + Score max_threat(const Bitboard targets, const Position& pos, const Score threat_values[]) { + + const Color Them = (Us == WHITE ? BLACK : WHITE); + + PieceType threat = PAWN; + if (targets & pos.pieces(Them, KNIGHT)) threat = KNIGHT; + if (targets & pos.pieces(Them, BISHOP)) threat = BISHOP; + if (targets & pos.pieces(Them, ROOK)) threat = ROOK; + if (targets & pos.pieces(Them, QUEEN)) threat = QUEEN; + + return threat_values[threat]; + } // evaluate_threats() assigns bonuses according to the type of attacking piece // and the type of attacked one. @@ -509,7 +526,8 @@ namespace { & (ei.attackedBy[Us][KNIGHT] | ei.attackedBy[Us][BISHOP]); if (protectedEnemies) - score += Threat[Minor][type_of(pos.piece_on(lsb(protectedEnemies)))]; + score += max_threat(protectedEnemies, pos, Threat[Minor]); + // Enemies not defended by a pawn and under our attack weakEnemies = pos.pieces(Them) @@ -521,11 +539,11 @@ namespace { { b = weakEnemies & (ei.attackedBy[Us][KNIGHT] | ei.attackedBy[Us][BISHOP]); if (b) - score += Threat[Minor][type_of(pos.piece_on(lsb(b)))]; + score += max_threat(b, pos, Threat[Minor]); b = weakEnemies & (ei.attackedBy[Us][ROOK] | ei.attackedBy[Us][QUEEN]); if (b) - score += Threat[Major][type_of(pos.piece_on(lsb(b)))]; + score += max_threat(b, pos, Threat[Major]); b = weakEnemies & ~ei.attackedBy[Them][ALL_PIECES]; if (b)