]> git.sesse.net Git - stockfish/commitdiff
Use frontmost_sq() and backmost_sq helpers
authorMarco Costalba <mcostalba@gmail.com>
Fri, 30 Aug 2013 05:05:25 +0000 (07:05 +0200)
committerMarco Costalba <mcostalba@gmail.com>
Fri, 30 Aug 2013 14:22:22 +0000 (16:22 +0200)
Should easier to read than the lsb() / msb() low
level functions.

No functional change.

src/bitboard.h
src/endgame.cpp
src/pawns.cpp

index e0e2fe64545ececedd4acf53852b9fd7e3b7dbf0..3afbeedfbab42ee086000de51a4964350b34bea5 100644 (file)
@@ -319,9 +319,10 @@ extern Square pop_lsb(Bitboard* b);
 
 #endif
 
 
 #endif
 
-/// lsb() overload finds least significant bit relative to the given color
-inline Square lsb(Color c, Bitboard b) {
-  return c == WHITE ? lsb(b) : msb(b);
-}
+/// frontmost_sq() and backmost_sq() find the square corresponding to the
+/// most/least advanced bit relative to the given color.
+
+inline Square frontmost_sq(Color c, Bitboard b) { return c == WHITE ? msb(b) : lsb(b); }
+inline Square  backmost_sq(Color c, Bitboard b) { return c == WHITE ? lsb(b) : msb(b); }
 
 #endif // #ifndef BITBOARD_H_INCLUDED
 
 #endif // #ifndef BITBOARD_H_INCLUDED
index 65b858613dd8f74ae6ad73674187473e059afe25..9c1c56f11d445504e4bcb735ef60548b12ea4d87 100644 (file)
@@ -443,11 +443,12 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
           // The bishop has the wrong color, and the defending king is on the
           // file of the pawn(s) or the adjacent file. Find the rank of the
           // frontmost pawn.
           // The bishop has the wrong color, and the defending king is on the
           // file of the pawn(s) or the adjacent file. Find the rank of the
           // frontmost pawn.
-          Rank rank = relative_rank(strongerSide, lsb(weakerSide, pawns));
+          Square pawnSq = frontmost_sq(strongerSide, pawns);
+
           // If the defending king has distance 1 to the promotion square or
           // is placed somewhere in front of the pawn, it's a draw.
           if (   square_distance(kingSq, queeningSq) <= 1
           // If the defending king has distance 1 to the promotion square or
           // is placed somewhere in front of the pawn, it's a draw.
           if (   square_distance(kingSq, queeningSq) <= 1
-              || relative_rank(strongerSide, kingSq) >= rank)
+              || relative_rank(weakerSide, kingSq) <= relative_rank(weakerSide, pawnSq))
               return SCALE_FACTOR_DRAW;
       }
   }
               return SCALE_FACTOR_DRAW;
       }
   }
@@ -459,7 +460,7 @@ ScaleFactor Endgame<KBPsK>::operator()(const Position& pos) const {
       && pos.count<PAWN>(weakerSide) >= 1)
   {
       // Get weakerSide pawn that is closest to home rank
       && pos.count<PAWN>(weakerSide) >= 1)
   {
       // Get weakerSide pawn that is closest to home rank
-      Square weakerPawnSq = lsb(weakerSide, pos.pieces(weakerSide, PAWN));
+      Square weakerPawnSq = backmost_sq(weakerSide, pos.pieces(weakerSide, PAWN));
 
       Square strongerKingSq = pos.king_square(strongerSide);
       Square weakerKingSq = pos.king_square(weakerSide);
 
       Square strongerKingSq = pos.king_square(strongerSide);
       Square weakerKingSq = pos.king_square(weakerSide);
index fece246b1c999a31611a8b8661b4e97d8e9520e2..c5fda17221deebb0086b8cece72ab8308908a10a 100644 (file)
@@ -229,11 +229,11 @@ Value Entry::shelter_storm(const Position& pos, Square ksq) {
   for (int f = kf - 1; f <= kf + 1; f++)
   {
       b = ourPawns & FileBB[f];
   for (int f = kf - 1; f <= kf + 1; f++)
   {
       b = ourPawns & FileBB[f];
-      rkUs = b ? relative_rank(Us, lsb(Us, b)) : RANK_1;
+      rkUs = b ? relative_rank(Us, backmost_sq(Us, b)) : RANK_1;
       safety -= ShelterWeakness[rkUs];
 
       b  = theirPawns & FileBB[f];
       safety -= ShelterWeakness[rkUs];
 
       b  = theirPawns & FileBB[f];
-      rkThem = b ? relative_rank(Us, lsb(Us, b)) : RANK_1;
+      rkThem = b ? relative_rank(Us, frontmost_sq(Them, b)) : RANK_1;
       safety -= StormDanger[rkUs == RANK_1 ? 0 : rkThem == rkUs + 1 ? 2 : 1][rkThem];
   }
 
       safety -= StormDanger[rkUs == RANK_1 ? 0 : rkThem == rkUs + 1 ? 2 : 1][rkThem];
   }