]> git.sesse.net Git - stockfish/commitdiff
Add non-linear threats evaluation
authorMarco Costalba <mcostalba@gmail.com>
Sat, 22 May 2010 10:55:01 +0000 (11:55 +0100)
committerMarco Costalba <mcostalba@gmail.com>
Sat, 22 May 2010 11:01:51 +0000 (12:01 +0100)
Increase threats score according to the number of
threats and to the side to move.

Constants have been balanced after ~34k iterations.

Signed-off-by: Marco Costalba <mcostalba@gmail.com>
src/evaluate.cpp

index e05383ffcbdabe3ee600ddbb6ae24a905b5da202..0153fa95a41c613cba09a4ff5521dc834da5227d 100644 (file)
@@ -148,6 +148,10 @@ namespace {
 
   #undef S
 
+  // Threats weights indexed by sente (side to move has a bigger weight)
+  const int ConcurrentThreatsWeight[2] = { 3, 15 };
+  const int ThreatsWeight[2] = { 249, 267 };
+
   // Bonus for unstoppable passed pawns
   const Value UnstoppablePawnValue = Value(0x500);
 
@@ -636,6 +640,8 @@ namespace {
     const Color Them = (Us == WHITE ? BLACK : WHITE);
 
     Bitboard b;
+    Value mg, eg;
+    int sente, threatCount = 0;
     Score bonus = make_score(0, 0);
 
     // Enemy pieces not defended by a pawn and under our attack
@@ -654,9 +660,20 @@ namespace {
         if (b)
             for (PieceType pt2 = PAWN; pt2 < KING; pt2++)
                 if (b & pos.pieces(pt2))
+                {
                     bonus += ThreatBonus[pt1][pt2];
+                    threatCount++;
+                }
     }
-    ei.value += Sign[Us] * bonus;
+
+    sente = (Us == pos.side_to_move());
+
+    // Non linear threat evaluation. Increase threats score according to the
+    // number of concurrent threats and to the side to move.
+    mg = (mg_value(bonus) + mg_value(bonus) * ConcurrentThreatsWeight[sente] * threatCount / 256) * ThreatsWeight[sente] / 256;
+    eg = (eg_value(bonus) + eg_value(bonus) * ConcurrentThreatsWeight[sente] * threatCount / 256) * ThreatsWeight[sente] / 256;
+
+    ei.value += Sign[Us] * make_score(mg, eg);
   }