]> git.sesse.net Git - stockfish/commitdiff
Clarify the mapping of files to queenside
authorStéphane Nicolet <cassio@free.fr>
Mon, 23 Sep 2019 06:52:27 +0000 (08:52 +0200)
committerStéphane Nicolet <cassio@free.fr>
Mon, 23 Sep 2019 06:54:20 +0000 (08:54 +0200)
Author: @nickpelling

We replace in the code the obscure expressions mapping files ABCDEFGH to ABCDDCBA
by an explicite call to an auxiliary function :

  old:   f = min(f, ~f)
  new:   f = map_to_queenside(f)

We used the Golbolt web site (https://godbolt.org) to find the optimal code
for the auxiliary function.

STC:
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 30292 W: 6756 L: 6651 D: 16885
http://tests.stockfishchess.org/tests/view/5d8676720ebc5971531d6aa1

No functional change

src/evaluate.cpp
src/pawns.cpp
src/psqt.cpp
src/types.h

index 9521cd100282487f44ba3926f01afde124797bc6..f37820afcef975b2f5bb326b30bbe16588d4b6ea 100644 (file)
@@ -662,7 +662,7 @@ namespace {
             || (pos.pieces(PAWN) & (s + Up)))
             bonus = bonus / 2;
 
             || (pos.pieces(PAWN) & (s + Up)))
             bonus = bonus / 2;
 
-        score += bonus - PassedFile * std::min(f, ~f);
+        score += bonus - PassedFile * map_to_queenside(f);
     }
 
     if (T)
     }
 
     if (T)
index f60411993fcc0877ed83a8a632f25945018aa9db..d822ef4ef85e8387d7a206db3f85714646844ee2 100644 (file)
@@ -198,7 +198,7 @@ Score Entry::evaluate_shelter(const Position& pos, Square ksq) {
       b = theirPawns & file_bb(f);
       int theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;
 
       b = theirPawns & file_bb(f);
       int theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;
 
-      int d = std::min(f, ~f);
+      int d = map_to_queenside(f);
       bonus += make_score(ShelterStrength[d][ourRank], 0);
 
       if (ourRank && (ourRank == theirRank - 1))
       bonus += make_score(ShelterStrength[d][ourRank], 0);
 
       if (ourRank && (ourRank == theirRank - 1))
index 36d99feb7e05280ce9ee6aacc9ab84aec8ebd8d8..13e69499b185afd9760d93f4d26edbfec5426f7e 100644 (file)
@@ -119,7 +119,7 @@ void init() {
 
       for (Square s = SQ_A1; s <= SQ_H8; ++s)
       {
 
       for (Square s = SQ_A1; s <= SQ_H8; ++s)
       {
-          File f = std::min(file_of(s), ~file_of(s));
+          File f = map_to_queenside(file_of(s));
           psq[ pc][ s] = score + (type_of(pc) == PAWN ? PBonus[rank_of(s)][file_of(s)]
                                                       : Bonus[pc][rank_of(s)][f]);
           psq[~pc][~s] = -psq[pc][s];
           psq[ pc][ s] = score + (type_of(pc) == PAWN ? PBonus[rank_of(s)][file_of(s)]
                                                       : Bonus[pc][rank_of(s)][f]);
           psq[~pc][~s] = -psq[pc][s];
index c77d804037ee7a094b54843b1482801baa2c6aed..6af0368720313d4c8cb7260566a92726f5256daa 100644 (file)
@@ -366,6 +366,10 @@ constexpr Piece operator~(Piece pc) {
   return Piece(pc ^ 8); // Swap color of piece B_KNIGHT -> W_KNIGHT
 }
 
   return Piece(pc ^ 8); // Swap color of piece B_KNIGHT -> W_KNIGHT
 }
 
+inline File map_to_queenside(File f) {
+  return std::min(f, File(FILE_H - f)); // Map files ABCDEFGH to files ABCDDCBA
+}
+
 constexpr CastlingRights operator&(Color c, CastlingRights cr) {
   return CastlingRights((c == WHITE ? WHITE_CASTLING : BLACK_CASTLING) & cr);
 }
 constexpr CastlingRights operator&(Color c, CastlingRights cr) {
   return CastlingRights((c == WHITE ? WHITE_CASTLING : BLACK_CASTLING) & cr);
 }