]> git.sesse.net Git - stockfish/commitdiff
Clarify the mapping of files to queenside
authornickpelling <nickpelling@nickpelling.com>
Sat, 21 Sep 2019 07:59:32 +0000 (08:59 +0100)
committerStéphane Nicolet <cassio@free.fr>
Tue, 24 Sep 2019 08:05:54 +0000 (10:05 +0200)
This patch replaces the obscure expressions mapping files ABCDEFGH to ABCDDCBA
by explicite calls 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 check that the current
code for the auxiliary function is optimal.

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

Achieved with a bit of help from Sopel97, snicolet and vondele, thanks everyone!
Closes https://github.com/official-stockfish/Stockfish/pull/2325

No functional change

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

diff --git a/AUTHORS b/AUTHORS
index 455cf6ca62aa1bda2ed9dbd451a5f633d4bdfdd4..aff6a6c93c86fe4cdfb698675779038e183f903a 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -99,6 +99,7 @@ Miroslav Fontán (Hexik)
 Moez Jellouli (MJZ1977)
 Mohammed Li (tthsqe12)
 Nathan Rugg (nmrugg)
+Nick Pelling (nickpelling)
 Nicklas Persson (NicklasPersson)
 Niklas Fiekas (niklasf)
 Ondrej Mosnáček (WOnder93)
index 9521cd100282487f44ba3926f01afde124797bc6..f37820afcef975b2f5bb326b30bbe16588d4b6ea 100644 (file)
@@ -662,7 +662,7 @@ namespace {
             || (pos.pieces(PAWN) & (s + Up)))
             bonus = bonus / 2;
 
-        score += bonus - PassedFile * std::min(f, ~f);
+        score += bonus - PassedFile * map_to_queenside(f);
     }
 
     if (T)
index f60411993fcc0877ed83a8a632f25945018aa9db..ca4156dac522d76eefee8919bad2d9ab5ecf2724 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;
 
-      int d = std::min(f, ~f);
+      File d = map_to_queenside(f);
       bonus += make_score(ShelterStrength[d][ourRank], 0);
 
       if (ourRank && (ourRank == theirRank - 1))
index 2b06931c6f9ed87b69347dbe052b1a5b5cebbe47..83d11cf1c1a8fe4e923e86eccf31fc2771a50733 100644 (file)
@@ -119,7 +119,7 @@ void init() {
 
       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];
index c77d804037ee7a094b54843b1482801baa2c6aed..6d2c09a6010be13631c3fb36ac6e9c571a05b429 100644 (file)
@@ -43,6 +43,7 @@
 #include <climits>
 #include <cstdint>
 #include <cstdlib>
+#include <algorithm>
 
 #if defined(_MSC_VER)
 // Disable some silly and noisy warning from MSVC compiler
@@ -358,14 +359,14 @@ constexpr Square operator~(Square s) {
   return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8
 }
 
-constexpr File operator~(File f) {
-  return File(f ^ FILE_H); // Horizontal flip FILE_A -> FILE_H
-}
-
 constexpr Piece operator~(Piece pc) {
   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);
 }