]> git.sesse.net Git - stockfish/blobdiff - src/evaluate.cpp
Remove dead code
[stockfish] / src / evaluate.cpp
index d03ae665283219fbb6415a705d48ab001d091950..057fd70c8216ec5fd4cae5d212b76d760a5ca0fc 100644 (file)
@@ -27,7 +27,6 @@
 #include "material.h"
 #include "pawns.h"
 #include "thread.h"
-#include "ucioption.h"
 
 namespace {
 
@@ -490,24 +489,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<Color Us> FORCE_INLINE
-  Score max_threat(const Bitboard targets, const Position& pos, const Score threat_values[]) {
+  // max_piece_type() is a helper function used by evaluate_threats() to get
+  // the value of the biggest PieceType of color C in 'target' bitboard.
 
-    const Color Them = (Us == WHITE ? BLACK : WHITE);
+  template<Color C>
+  inline PieceType max_piece_type(const Position& pos, const Bitboard target) {
+
+    assert(target & (pos.pieces(C) ^ pos.pieces(C, KING)));
+
+    for (PieceType pt = QUEEN; pt > PAWN; --pt)
+        if (target & pos.pieces(C, pt))
+            return pt;
 
-    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];
+    return PAWN;
   }
 
+
   // evaluate_threats() assigns bonuses according to the type of attacking piece
   // and the type of attacked one.
 
@@ -516,34 +514,34 @@ namespace {
 
     const Color Them = (Us == WHITE ? BLACK : WHITE);
 
+    enum { Minor, Major };
+
     Bitboard b, weakEnemies, protectedEnemies;
     Score score = SCORE_ZERO;
-    enum { Minor, Major };
 
-    // Protected enemies
-    protectedEnemies = (pos.pieces(Them) ^ pos.pieces(Them,PAWN))
-                      & ei.attackedBy[Them][PAWN]
+    // Enemies defended by a pawn and under our attack by a minor piece
+    protectedEnemies =  (pos.pieces(Them) ^ pos.pieces(Them, PAWN))
+                      &  ei.attackedBy[Them][PAWN]
                       & (ei.attackedBy[Us][KNIGHT] | ei.attackedBy[Us][BISHOP]);
 
     if (protectedEnemies)
-        score += max_threat<Us>(protectedEnemies, pos, Threat[Minor]);
-
+        score += Threat[Minor][max_piece_type<Them>(pos, protectedEnemies)];
 
     // Enemies not defended by a pawn and under our attack
-    weakEnemies =  pos.pieces(Them)
+    weakEnemies =   pos.pieces(Them)
                  & ~ei.attackedBy[Them][PAWN]
-                 & ei.attackedBy[Us][ALL_PIECES];
+                 &  ei.attackedBy[Us][ALL_PIECES];
 
     // Add a bonus according if the attacking pieces are minor or major
     if (weakEnemies)
     {
         b = weakEnemies & (ei.attackedBy[Us][KNIGHT] | ei.attackedBy[Us][BISHOP]);
         if (b)
-            score += max_threat<Us>(b, pos, Threat[Minor]);
+            score += Threat[Minor][max_piece_type<Them>(pos, b)];
 
         b = weakEnemies & (ei.attackedBy[Us][ROOK] | ei.attackedBy[Us][QUEEN]);
         if (b)
-            score += max_threat<Us>(b, pos, Threat[Major]);
+            score += Threat[Major][max_piece_type<Them>(pos, b)];
 
         b = weakEnemies & ~ei.attackedBy[Them][ALL_PIECES];
         if (b)
@@ -767,27 +765,25 @@ namespace {
     if (    ei.mi->game_phase() < PHASE_MIDGAME
         && (sf == SCALE_FACTOR_NORMAL || sf == SCALE_FACTOR_ONEPAWN))
     {
-        if (pos.opposite_bishops()) {
-            // Ignoring any pawns, do both sides only have a single bishop and no
-            // other pieces?
+        if (pos.opposite_bishops())
+        {
+            // Endgame with opposite-colored bishops and no other pieces (ignoring pawns)
+            // is almost a draw, in case of KBP vs KB is even more a draw.
             if (   pos.non_pawn_material(WHITE) == BishopValueMg
                 && pos.non_pawn_material(BLACK) == BishopValueMg)
-            {
-                // Check for KBP vs KB with only a single pawn that is almost
-                // certainly a draw or at least two pawns.
-                bool one_pawn = (pos.count<PAWN>(WHITE) + pos.count<PAWN>(BLACK) == 1);
-                sf = one_pawn ? ScaleFactor(8) : ScaleFactor(32);
-            }
+                sf = more_than_one(pos.pieces(PAWN)) ? ScaleFactor(32) : ScaleFactor(8);
+
+            // Endgame with opposite-colored bishops, but also other pieces. Still
+            // a bit drawish, but not as drawish as with only the two bishops.
             else
-                // Endgame with opposite-colored bishops, but also other pieces. Still
-                // a bit drawish, but not as drawish as with only the two bishops.
                  sf = ScaleFactor(50 * sf / SCALE_FACTOR_NORMAL);
-        } else if (    abs(eg_value(score)) <= BishopValueEg
-                   &&  ei.pi->pawn_span(strongSide) <= 1
-                   && !pos.pawn_passed(~strongSide, pos.king_square(~strongSide))) {
-            // Endings where weaker side can be place his king in front of the opponent's pawns are drawish.
-            sf = ScaleFactor(ScalePawnSpan[ei.pi->pawn_span(strongSide)]);
         }
+        // Endings where weaker side can place his king in front of the opponent's
+        // pawns are drawish.
+        else if (    abs(eg_value(score)) <= BishopValueEg
+                 &&  ei.pi->pawn_span(strongSide) <= 1
+                 && !pos.pawn_passed(~strongSide, pos.king_square(~strongSide)))
+                 sf = ScaleFactor(ScalePawnSpan[ei.pi->pawn_span(strongSide)]);
     }
 
     // Interpolate between a middlegame and a (scaled by 'sf') endgame score
@@ -906,8 +902,7 @@ namespace Eval {
   }
 
 
-  /// init() computes evaluation weights from the corresponding UCI parameters
-  /// and setup king tables.
+  /// init() computes evaluation weights.
 
   void init() {