]> git.sesse.net Git - stockfish/commitdiff
Small cleanups
authorJoost VandeVondele <Joost.VandeVondele@gmail.com>
Sat, 14 Mar 2020 16:04:50 +0000 (17:04 +0100)
committerJoost VandeVondele <Joost.VandeVondele@gmail.com>
Sat, 14 Mar 2020 16:04:50 +0000 (17:04 +0100)
closes https://github.com/official-stockfish/Stockfish/pull/2567

No functional change.

src/bitboard.h
src/endgame.cpp
src/position.cpp
src/search.cpp
src/syzygy/tbprobe.cpp
src/tt.h
src/types.h
src/uci.cpp

index f1d14603687fd19ae0d975799154d15ac8058a66..529e3dfe5f44e31e18099dfa85e372a11e31c76e 100644 (file)
@@ -375,14 +375,17 @@ inline Square msb(Bitboard b) {
 /// pop_lsb() finds and clears the least significant bit in a non-zero bitboard
 
 inline Square pop_lsb(Bitboard* b) {
 /// pop_lsb() finds and clears the least significant bit in a non-zero bitboard
 
 inline Square pop_lsb(Bitboard* b) {
+  assert(*b);
   const Square s = lsb(*b);
   *b &= *b - 1;
   return s;
 }
 
 
   const Square s = lsb(*b);
   *b &= *b - 1;
   return s;
 }
 
 
-/// frontmost_sq() returns the most advanced square for the given color
+/// frontmost_sq() returns the most advanced square for the given color,
+/// requires a non-zero bitboard.
 inline Square frontmost_sq(Color c, Bitboard b) {
 inline Square frontmost_sq(Color c, Bitboard b) {
+  assert(b);
   return c == WHITE ? msb(b) : lsb(b);
 }
 
   return c == WHITE ? msb(b) : lsb(b);
 }
 
index 0a2b02ad6c96305dcb6833e5ccdc97c20859c91e..56583c58890ffb6f7aac25979987719388407477 100644 (file)
@@ -24,8 +24,6 @@
 #include "endgame.h"
 #include "movegen.h"
 
 #include "endgame.h"
 #include "movegen.h"
 
-using std::string;
-
 namespace {
 
   // Used to drive the king towards the edge of the board
 namespace {
 
   // Used to drive the king towards the edge of the board
@@ -326,23 +324,23 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
   // No assertions about the material of weakSide, because we want draws to
   // be detected even when the weaker side has some pawns.
 
   // No assertions about the material of weakSide, because we want draws to
   // be detected even when the weaker side has some pawns.
 
-  Bitboard strongpawns = pos.pieces(strongSide, PAWN);
-  Bitboard allpawns = pos.pieces(PAWN);
+  Bitboard strongPawns = pos.pieces(strongSide, PAWN);
+  Bitboard allPawns = pos.pieces(PAWN);
 
   // All strongSide pawns are on a single rook file?
 
   // All strongSide pawns are on a single rook file?
-  if (!(strongpawns & ~FileABB) || !(strongpawns & ~FileHBB))
+  if (!(strongPawns & ~FileABB) || !(strongPawns & ~FileHBB))
   {
       Square bishopSq = pos.square<BISHOP>(strongSide);
   {
       Square bishopSq = pos.square<BISHOP>(strongSide);
-      Square queeningSq = relative_square(strongSide, make_square(file_of(lsb(strongpawns)), RANK_8));
-      Square weakkingSq = pos.square<KING>(weakSide);
+      Square queeningSq = relative_square(strongSide, make_square(file_of(lsb(strongPawns)), RANK_8));
+      Square weakKingSq = pos.square<KING>(weakSide);
 
       if (   opposite_colors(queeningSq, bishopSq)
 
       if (   opposite_colors(queeningSq, bishopSq)
-          && distance(queeningSq, weakkingSq) <= 1)
+          && distance(queeningSq, weakKingSq) <= 1)
           return SCALE_FACTOR_DRAW;
   }
 
   // If all the pawns are on the same B or G file, then it's potentially a draw
           return SCALE_FACTOR_DRAW;
   }
 
   // If all the pawns are on the same B or G file, then it's potentially a draw
-  if ((!(allpawns & ~FileBBB) || !(allpawns & ~FileGBB))
+  if ((!(allPawns & ~FileBBB) || !(allPawns & ~FileGBB))
       && pos.non_pawn_material(weakSide) == 0
       && pos.count<PAWN>(weakSide) >= 1)
   {
       && pos.non_pawn_material(weakSide) == 0
       && pos.count<PAWN>(weakSide) >= 1)
   {
@@ -356,8 +354,8 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
       // There's potential for a draw if our pawn is blocked on the 7th rank,
       // the bishop cannot attack it or they only have one pawn left
       if (   relative_rank(strongSide, weakPawnSq) == RANK_7
       // There's potential for a draw if our pawn is blocked on the 7th rank,
       // the bishop cannot attack it or they only have one pawn left
       if (   relative_rank(strongSide, weakPawnSq) == RANK_7
-          && (strongpawns & (weakPawnSq + pawn_push(weakSide)))
-          && (opposite_colors(bishopSq, weakPawnSq) || !more_than_one(strongpawns)))
+          && (strongPawns & (weakPawnSq + pawn_push(weakSide)))
+          && (opposite_colors(bishopSq, weakPawnSq) || !more_than_one(strongPawns)))
       {
           int strongKingDist = distance(weakPawnSq, strongKingSq);
           int weakKingDist = distance(weakPawnSq, weakKingSq);
       {
           int strongKingDist = distance(weakPawnSq, strongKingSq);
           int weakKingDist = distance(weakPawnSq, weakKingSq);
@@ -588,11 +586,9 @@ ScaleFactor Endgame<KPsK>::operator()(const Position& pos) const {
   Square ksq = pos.square<KING>(weakSide);
   Bitboard pawns = pos.pieces(strongSide, PAWN);
 
   Square ksq = pos.square<KING>(weakSide);
   Bitboard pawns = pos.pieces(strongSide, PAWN);
 
-  // If all pawns are ahead of the king, on a single rook file and
-  // the king is within one file of the pawns, it's a draw.
-  if (   !(pawns & ~forward_ranks_bb(weakSide, ksq))
-      && !((pawns & ~FileABB) && (pawns & ~FileHBB))
-      &&  distance<File>(ksq, lsb(pawns)) <= 1)
+  // If all pawns are ahead of the king on a single rook file, it's a draw.
+  if (!((pawns & ~FileABB) || (pawns & ~FileHBB)) &&
+      !(pawns & ~passed_pawn_span(weakSide, ksq)))
       return SCALE_FACTOR_DRAW;
 
   return SCALE_FACTOR_NONE;
       return SCALE_FACTOR_DRAW;
 
   return SCALE_FACTOR_NONE;
@@ -615,8 +611,7 @@ ScaleFactor Endgame<KBPKB>::operator()(const Position& pos) const {
   Square weakKingSq = pos.square<KING>(weakSide);
 
   // Case 1: Defending king blocks the pawn, and cannot be driven away
   Square weakKingSq = pos.square<KING>(weakSide);
 
   // Case 1: Defending king blocks the pawn, and cannot be driven away
-  if (   file_of(weakKingSq) == file_of(pawnSq)
-      && relative_rank(strongSide, pawnSq) < relative_rank(strongSide, weakKingSq)
+  if (   (forward_file_bb(strongSide, pawnSq) & weakKingSq)
       && (   opposite_colors(weakKingSq, strongBishopSq)
           || relative_rank(strongSide, weakKingSq) <= RANK_6))
       return SCALE_FACTOR_DRAW;
       && (   opposite_colors(weakKingSq, strongBishopSq)
           || relative_rank(strongSide, weakKingSq) <= RANK_6))
       return SCALE_FACTOR_DRAW;
index 0ac450570b91b28ac468373995b42033ef0f3164..fefce56e2aa1088621a755f393e390cca534acae 100644 (file)
@@ -1121,10 +1121,7 @@ bool Position::is_draw(int ply) const {
 
   // Return a draw score if a position repeats once earlier but strictly
   // after the root, or repeats twice before or at the root.
 
   // Return a draw score if a position repeats once earlier but strictly
   // after the root, or repeats twice before or at the root.
-  if (st->repetition && st->repetition < ply)
-      return true;
-
-  return false;
+  return st->repetition && st->repetition < ply;
 }
 
 
 }
 
 
index 70520ac9ff74049b534cbf720abd857bd3ac3b40..a54e181a2a906e1033848d9983655a7805eb24cf 100644 (file)
@@ -1193,10 +1193,16 @@ moves_loop: // When in check, search starts from here
 
           value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
 
 
           value = -search<NonPV>(pos, ss+1, -(alpha+1), -alpha, d, true);
 
-          doFullDepthSearch = (value > alpha && d != newDepth), didLMR = true;
+          doFullDepthSearch = value > alpha && d != newDepth;
+
+          didLMR = true;
       }
       else
       }
       else
-          doFullDepthSearch = !PvNode || moveCount > 1, didLMR = false;
+      {
+          doFullDepthSearch = !PvNode || moveCount > 1;
+
+          didLMR = false;
+      }
 
       // Step 17. Full depth search when LMR is skipped or fails high
       if (doFullDepthSearch)
 
       // Step 17. Full depth search when LMR is skipped or fails high
       if (doFullDepthSearch)
index 2532bbd34fc0a871c498e1b91df103c284b7c007..34e4331da1c39c5dfeb3a4385255506558c7bbab 100644 (file)
@@ -769,7 +769,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
         if (!off_A1H8(squares[i]))
             continue;
 
         if (!off_A1H8(squares[i]))
             continue;
 
-        if (off_A1H8(squares[i]) > 0) // A1-H8 diagonal flip: SQ_A3 -> SQ_C3
+        if (off_A1H8(squares[i]) > 0) // A1-H8 diagonal flip: SQ_A3 -> SQ_C1
             for (int j = i; j < size; ++j)
                 squares[j] = Square(((squares[j] >> 3) | (squares[j] << 3)) & 63);
         break;
             for (int j = i; j < size; ++j)
                 squares[j] = Square(((squares[j] >> 3) | (squares[j] << 3)) & 63);
         break;
index 142afd90e56ca63e1b79691f27b6c51a5a19f966..8b70f79787619ca4c1b6326f55cfa456a2dcf04f 100644 (file)
--- a/src/tt.h
+++ b/src/tt.h
@@ -41,7 +41,7 @@ struct TTEntry {
   Value value() const { return (Value)value16; }
   Value eval()  const { return (Value)eval16; }
   Depth depth() const { return (Depth)depth8 + DEPTH_OFFSET; }
   Value value() const { return (Value)value16; }
   Value eval()  const { return (Value)eval16; }
   Depth depth() const { return (Depth)depth8 + DEPTH_OFFSET; }
-  bool is_pv() const { return (bool)(genBound8 & 0x4); }
+  bool is_pv()  const { return (bool)(genBound8 & 0x4); }
   Bound bound() const { return (Bound)(genBound8 & 0x3); }
   void save(Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev);
 
   Bound bound() const { return (Bound)(genBound8 & 0x3); }
   void save(Key k, Value v, bool pv, Bound b, Depth d, Move m, Value ev);
 
index 71893c0ffd644acef9d5611b7591e40f57b1de95..bfcd3f23f11cf07b16d1366495c4afdd74530ace 100644 (file)
@@ -220,7 +220,7 @@ enum : int {
   DEPTH_QS_RECAPTURES = -5,
 
   DEPTH_NONE   = -6,
   DEPTH_QS_RECAPTURES = -5,
 
   DEPTH_NONE   = -6,
-  DEPTH_OFFSET = DEPTH_NONE,
+  DEPTH_OFFSET = DEPTH_NONE
 };
 
 enum Square : int {
 };
 
 enum Square : int {
index 8b35e6fdd56a96869de49aa2c8c925cf9cbc2e3a..33577a4eca3dac2c9fab4edb7e486bf5c14007db 100644 (file)
@@ -260,7 +260,7 @@ string UCI::value(Value v) {
 
   stringstream ss;
 
 
   stringstream ss;
 
-  if (abs(v) < VALUE_MATE - MAX_PLY)
+  if (abs(v) < VALUE_MATE_IN_MAX_PLY)
       ss << "cp " << v * 100 / PawnValueEg;
   else
       ss << "mate " << (v > 0 ? VALUE_MATE - v + 1 : -VALUE_MATE - v) / 2;
       ss << "cp " << v * 100 / PawnValueEg;
   else
       ss << "mate " << (v > 0 ? VALUE_MATE - v + 1 : -VALUE_MATE - v) / 2;