From 7756344d5d2b93970e7cd423f8cbf6fb1da11b74 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ste=CC=81phane=20Nicolet?= Date: Mon, 23 Sep 2019 08:52:27 +0200 Subject: [PATCH] Clarify the mapping of files to queenside 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 | 2 +- src/pawns.cpp | 2 +- src/psqt.cpp | 2 +- src/types.h | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/evaluate.cpp b/src/evaluate.cpp index 9521cd10..f37820af 100644 --- a/src/evaluate.cpp +++ b/src/evaluate.cpp @@ -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) diff --git a/src/pawns.cpp b/src/pawns.cpp index f6041199..d822ef4e 100644 --- a/src/pawns.cpp +++ b/src/pawns.cpp @@ -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); + int d = map_to_queenside(f); bonus += make_score(ShelterStrength[d][ourRank], 0); if (ourRank && (ourRank == theirRank - 1)) diff --git a/src/psqt.cpp b/src/psqt.cpp index 36d99feb..13e69499 100644 --- a/src/psqt.cpp +++ b/src/psqt.cpp @@ -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]; diff --git a/src/types.h b/src/types.h index c77d8040..6af03687 100644 --- a/src/types.h +++ b/src/types.h @@ -366,6 +366,10 @@ 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); } -- 2.39.2