]> git.sesse.net Git - stockfish/commitdiff
We can add an integer to a Value
authorMarco Costalba <mcostalba@gmail.com>
Sun, 27 Apr 2014 08:13:59 +0000 (10:13 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Sun, 27 Apr 2014 09:25:42 +0000 (11:25 +0200)
We have defined corresponding operators,
so rely on them to streamline the code
and increase readibility.

No functional change.

src/endgame.cpp
src/evaluate.cpp
src/pawns.cpp
src/search.cpp
src/types.h

index 94967c25eac588043e0730eabc2c0da5a4a16745..9e60503e98f5e07602ec1335956de559b01df181 100644 (file)
@@ -245,13 +245,13 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
 
   // If the stronger side's king is in front of the pawn, it's a win
   if (wksq < psq && file_of(wksq) == file_of(psq))
-      result = RookValueEg - Value(square_distance(wksq, psq));
+      result = RookValueEg - square_distance(wksq, psq);
 
   // If the weaker side's king is too far from the pawn and the rook,
   // it's a win.
   else if (   square_distance(bksq, psq) >= 3 + (pos.side_to_move() == weakSide)
            && square_distance(bksq, rsq) >= 3)
-      result = RookValueEg - Value(square_distance(wksq, psq));
+      result = RookValueEg - square_distance(wksq, psq);
 
   // If the pawn is far advanced and supported by the defending king,
   // the position is drawish
@@ -259,13 +259,12 @@ Value Endgame<KRKP>::operator()(const Position& pos) const {
            && square_distance(bksq, psq) == 1
            && rank_of(wksq) >= RANK_4
            && square_distance(wksq, psq) > 2 + (pos.side_to_move() == strongSide))
-      result = Value(80 - square_distance(wksq, psq) * 8);
+      result = Value(80) - 8 * square_distance(wksq, psq);
 
   else
-      result =  Value(200)
-              - Value(square_distance(wksq, psq + DELTA_S) * 8)
-              + Value(square_distance(bksq, psq + DELTA_S) * 8)
-              + Value(square_distance(psq, queeningSq) * 8);
+      result =  Value(200) - 8 * (  square_distance(wksq, psq + DELTA_S)
+                                  - square_distance(bksq, psq + DELTA_S)
+                                  - square_distance(psq, queeningSq));
 
   return strongSide == pos.side_to_move() ? result : -result;
 }
index ea65ab3862a57627559c97db1f754feb14aac9ed..0fef0258b1de329d7d6bede6a11d933cb6ba6f69 100644 (file)
@@ -583,24 +583,23 @@ namespace {
 
         assert(pos.pawn_passed(Us, s));
 
-        int r = int(relative_rank(Us, s) - RANK_2);
-        int rr = r * (r - 1);
+        Rank r = relative_rank(Us, s) - RANK_2;
+        Rank rr = r * (r - 1);
 
         // Base bonus based on rank
-        Value mbonus = Value(17 * rr);
-        Value ebonus = Value(7 * (rr + r + 1));
+        Value mbonus = Value(17 * rr), ebonus = Value(7 * (rr + r + 1));
 
         if (rr)
         {
             Square blockSq = s + pawn_push(Us);
 
             // Adjust bonus based on the king's proximity
-            ebonus +=  Value(square_distance(pos.king_square(Them), blockSq) * 5 * rr)
-                     - Value(square_distance(pos.king_square(Us  ), blockSq) * 2 * rr);
+            ebonus +=  square_distance(pos.king_square(Them), blockSq) * 5 * rr
+                     - square_distance(pos.king_square(Us  ), blockSq) * 2 * rr;
 
             // If blockSq is not the queening square then consider also a second push
             if (relative_rank(Us, blockSq) != RANK_8)
-                ebonus -= Value(rr * square_distance(pos.king_square(Us), blockSq + pawn_push(Us)));
+                ebonus -= rr * square_distance(pos.king_square(Us), blockSq + pawn_push(Us));
 
             // If the pawn is free to advance, then increase the bonus
             if (pos.empty(blockSq))
@@ -634,7 +633,7 @@ namespace {
                 else if (defendedSquares & blockSq)
                     k += 4;
 
-                mbonus += Value(k * rr), ebonus += Value(k * rr);
+                mbonus += k * rr, ebonus += k * rr;
             }
         } // rr != 0
 
index 5d7aa4e3c203a45dc25a2e9a6a90433f526e0844..5768eb3e8107e86ad50d518027dc216e8a4aa21c 100644 (file)
@@ -270,7 +270,7 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) {
       if (   (MiddleEdges & make_square(f, rkThem))
           && file_of(ksq) == f
           && relative_rank(Us, ksq) == rkThem - 1)
-          safety += Value(200);
+          safety += 200;
       else
           safety -= ShelterWeakness[rkUs]
                   + StormDanger[rkUs == RANK_1 ? 0 : rkThem == rkUs + 1 ? 2 : 1][rkThem];
index 216964ab43d5434678695f1f9c88d076cb084243..2f7ed7be09127428341fc7cb0564bb1ff67ba8f6 100644 (file)
@@ -61,13 +61,13 @@ namespace {
   enum NodeType { Root, PV, NonPV, SplitPointRoot, SplitPointPV, SplitPointNonPV };
 
   // Dynamic razoring margin based on depth
-  inline Value razor_margin(Depth d) { return Value(512 + 16 * int(d)); }
+  inline Value razor_margin(Depth d) { return Value(512 + 16 * d); }
 
   // Futility lookup tables (initialized at startup) and their access functions
   int FutilityMoveCounts[2][32]; // [improving][depth]
 
   inline Value futility_margin(Depth d) {
-    return Value(100 * int(d));
+    return Value(100 * d);
   }
 
   // Reduction lookup tables (initialized at startup) and their access function
@@ -683,7 +683,7 @@ namespace {
     // Step 10. Internal iterative deepening (skipped when in check)
     if (    depth >= (PvNode ? 5 * ONE_PLY : 8 * ONE_PLY)
         && !ttMove
-        && (PvNode || ss->staticEval + Value(256) >= beta))
+        && (PvNode || ss->staticEval + 256 >= beta))
     {
         Depth d = depth - 2 * ONE_PLY - (PvNode ? DEPTH_ZERO : depth / 4);
 
@@ -823,7 +823,7 @@ moves_loop: // When in check and at SpNode search starts from here
           if (predictedDepth < 7 * ONE_PLY)
           {
               futilityValue = ss->staticEval + futility_margin(predictedDepth)
-                            + Value(128) + Gains[pos.moved_piece(move)][to_sq(move)];
+                            + 128 + Gains[pos.moved_piece(move)][to_sq(move)];
 
               if (futilityValue <= alpha)
               {
@@ -1128,7 +1128,7 @@ moves_loop: // When in check and at SpNode search starts from here
         if (PvNode && bestValue > alpha)
             alpha = bestValue;
 
-        futilityBase = bestValue + Value(128);
+        futilityBase = bestValue + 128;
     }
 
     // Initialize a MovePicker object for the current position, and prepare
index 02b651dd9b124df4fc66d4e8c15dddd36afa2d76..f74ba8d52fedd04b798c9528141e5420456e61cb 100644 (file)
@@ -289,7 +289,7 @@ inline Value eg_value(Score s) {
 
 #endif
 
-#define ENABLE_SAFE_OPERATORS_ON(T)                                         \
+#define ENABLE_BASE_OPERATORS_ON(T)                                         \
 inline T operator+(const T d1, const T d2) { return T(int(d1) + int(d2)); } \
 inline T operator-(const T d1, const T d2) { return T(int(d1) - int(d2)); } \
 inline T operator*(int i, const T d) { return T(i * int(d)); }              \
@@ -299,26 +299,32 @@ inline T& operator+=(T& d1, const T d2) { return d1 = d1 + d2; }            \
 inline T& operator-=(T& d1, const T d2) { return d1 = d1 - d2; }            \
 inline T& operator*=(T& d, int i) { return d = T(int(d) * i); }
 
-#define ENABLE_OPERATORS_ON(T) ENABLE_SAFE_OPERATORS_ON(T)                  \
+ENABLE_BASE_OPERATORS_ON(Score)
+
+#define ENABLE_FULL_OPERATORS_ON(T)                                         \
+ENABLE_BASE_OPERATORS_ON(T)                                                 \
 inline T& operator++(T& d) { return d = T(int(d) + 1); }                    \
 inline T& operator--(T& d) { return d = T(int(d) - 1); }                    \
 inline T operator/(const T d, int i) { return T(int(d) / i); }              \
 inline T& operator/=(T& d, int i) { return d = T(int(d) / i); }
 
-ENABLE_OPERATORS_ON(Value)
-ENABLE_OPERATORS_ON(PieceType)
-ENABLE_OPERATORS_ON(Piece)
-ENABLE_OPERATORS_ON(Color)
-ENABLE_OPERATORS_ON(Depth)
-ENABLE_OPERATORS_ON(Square)
-ENABLE_OPERATORS_ON(File)
-ENABLE_OPERATORS_ON(Rank)
+ENABLE_FULL_OPERATORS_ON(Value)
+ENABLE_FULL_OPERATORS_ON(PieceType)
+ENABLE_FULL_OPERATORS_ON(Piece)
+ENABLE_FULL_OPERATORS_ON(Color)
+ENABLE_FULL_OPERATORS_ON(Depth)
+ENABLE_FULL_OPERATORS_ON(Square)
+ENABLE_FULL_OPERATORS_ON(File)
+ENABLE_FULL_OPERATORS_ON(Rank)
+
+#undef ENABLE_FULL_OPERATORS_ON
+#undef ENABLE_BASE_OPERATORS_ON
 
 /// Additional operators to add integers to a Value
 inline Value operator+(Value v, int i) { return Value(int(v) + i); }
 inline Value operator-(Value v, int i) { return Value(int(v) - i); }
-
-ENABLE_SAFE_OPERATORS_ON(Score)
+inline Value& operator+=(Value& v, int i) { return v = v + i; }
+inline Value& operator-=(Value& v, int i) { return v = v - i; }
 
 /// Only declared but not defined. We don't want to multiply two scores due to
 /// a very high risk of overflow. So user should explicitly convert to integer.
@@ -329,9 +335,6 @@ inline Score operator/(Score s, int i) {
   return make_score(mg_value(s) / i, eg_value(s) / i);
 }
 
-#undef ENABLE_OPERATORS_ON
-#undef ENABLE_SAFE_OPERATORS_ON
-
 extern Value PieceValue[PHASE_NB][PIECE_NB];
 
 struct ExtMove {