]> git.sesse.net Git - stockfish/commitdiff
Faster and simplified threat eval
authorGary Linscott <glinscott@gmail.com>
Wed, 18 Dec 2013 19:00:01 +0000 (14:00 -0500)
committerMarco Costalba <mcostalba@gmail.com>
Thu, 19 Dec 2013 17:52:34 +0000 (18:52 +0100)
Add a bonus according if the attacking
pieces are minor or major.

Passed both short TC
LLR: 2.96 (-2.94,2.94) [-1.50,4.50]
Total: 13142 W: 2625 L: 2483 D: 8034

And long TC
LLR: 2.95 (-2.94,2.94) [0.00,6.00]
Total: 18059 W: 3031 L: 2844 D: 12184

bench: 7425809

src/evaluate.cpp

index 7d57dddbe6e62a4701a8bc3c461ad6e84e2056e4..1ee727da59773a5920835db74eb5f6e6bf6ea855 100644 (file)
@@ -150,11 +150,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( 0,  0), S(24, 49), S(41,100), S(41,100) }, // KNIGHT
-    { S(0, 0), S( 7, 39), S(24, 49), S( 0,  0), S(41,100), S(41,100) }, // BISHOP
-    { S(0, 0), S( 0, 22), S(15, 49), S(15, 49), S( 0,  0), S(24, 49) }, // ROOK
-    { S(0, 0), S(15, 39), S(15, 39), S(15, 39), S(15, 39), S( 0,  0) }  // QUEEN
+    { 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
   };
 
   // ThreatenedByPawn[PieceType] contains a penalty according to which piece
@@ -762,18 +759,17 @@ Value do_evaluate(const Position& pos) {
                  & ~ei.attackedBy[Them][PAWN]
                  & ei.attackedBy[Us][ALL_PIECES];
 
-    // Add bonus according to type of attacked enemy piece and to the
-    // type of attacking piece, from knights to queens. Kings are not
-    // considered because they are already handled in king evaluation.
+    // Add a bonus according if the attacking pieces are minor or major
     if (weakEnemies)
-        for (PieceType pt1 = KNIGHT; pt1 < KING; ++pt1)
-        {
-            b = ei.attackedBy[Us][pt1] & weakEnemies;
-            if (b)
-                for (PieceType pt2 = PAWN; pt2 < KING; ++pt2)
-                    if (b & pos.pieces(pt2))
-                        score += Threat[pt1][pt2];
-        }
+    {
+        b = weakEnemies & (ei.attackedBy[Us][KNIGHT] | ei.attackedBy[Us][BISHOP]);
+        if (b)
+            score += Threat[0][type_of(pos.piece_on(lsb(b)))];
+
+        b = weakEnemies & (ei.attackedBy[Us][ROOK] | ei.attackedBy[Us][QUEEN]);
+        if (b)
+            score += Threat[1][type_of(pos.piece_on(lsb(b)))];
+    }
 
     if (Trace)
         Tracing::scores[Us][THREAT] = score;