]> git.sesse.net Git - stockfish/blobdiff - src/endgame.cpp
Do not assume that enum are signed
[stockfish] / src / endgame.cpp
index 94967c25eac588043e0730eabc2c0da5a4a16745..2a1614af09523ffddd725e4c7fc3a1117fcecaf5 100644 (file)
@@ -166,6 +166,7 @@ Value Endgame<KXK>::operator()(const Position& pos) const {
 
   if (   pos.count<QUEEN>(strongSide)
       || pos.count<ROOK>(strongSide)
+      ||(pos.count<BISHOP>(strongSide) && pos.count<KNIGHT>(strongSide))
       || pos.bishop_pair(strongSide))
       result += VALUE_KNOWN_WIN;
 
@@ -245,13 +246,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 +260,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;
 }
@@ -479,7 +479,7 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
   if (   r == RANK_6
       && square_distance(bksq, queeningSq) <= 1
       && rank_of(wksq) + tempo <= RANK_6
-      && (rank_of(brsq) == RANK_1 || (!tempo && abs(file_of(brsq) - f) >= 3)))
+      && (rank_of(brsq) == RANK_1 || (!tempo && dist(file_of(brsq), f) >= 3)))
       return SCALE_FACTOR_DRAW;
 
   if (   r >= RANK_6
@@ -535,7 +535,7 @@ ScaleFactor Endgame<KRPKR>::operator()(const Position& pos) const {
   {
       if (file_of(bksq) == file_of(wpsq))
           return ScaleFactor(10);
-      if (   abs(file_of(bksq) - file_of(wpsq)) == 1
+      if (   dist(file_of(bksq), file_of(wpsq)) == 1
           && square_distance(wksq, bksq) > 2)
           return ScaleFactor(24 - 2 * square_distance(wksq, bksq));
   }
@@ -749,7 +749,7 @@ ScaleFactor Endgame<KBPPKB>::operator()(const Position& pos) const {
         && opposite_colors(ksq, wbsq)
         && (   bbsq == blockSq2
             || (pos.attacks_from<BISHOP>(blockSq2) & pos.pieces(weakSide, BISHOP))
-            || abs(r1 - r2) >= 2))
+            || dist(r1, r2) >= 2))
         return SCALE_FACTOR_DRAW;
 
     else if (   ksq == blockSq2