Skip to content

Commit d232a4a

Browse files
nickpellingsnicolet
authored andcommitted
Clarify the mapping of files to queenside
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 #2325 No functional change
1 parent defa1cc commit d232a4a

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Miroslav Fontán (Hexik)
9999
Moez Jellouli (MJZ1977)
100100
Mohammed Li (tthsqe12)
101101
Nathan Rugg (nmrugg)
102+
Nick Pelling (nickpelling)
102103
Nicklas Persson (NicklasPersson)
103104
Niklas Fiekas (niklasf)
104105
Ondrej Mosnáček (WOnder93)

src/evaluate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ namespace {
662662
|| (pos.pieces(PAWN) & (s + Up)))
663663
bonus = bonus / 2;
664664

665-
score += bonus - PassedFile * std::min(f, ~f);
665+
score += bonus - PassedFile * map_to_queenside(f);
666666
}
667667

668668
if (T)

src/pawns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ Score Entry::evaluate_shelter(const Position& pos, Square ksq) {
198198
b = theirPawns & file_bb(f);
199199
int theirRank = b ? relative_rank(Us, frontmost_sq(Them, b)) : 0;
200200

201-
int d = std::min(f, ~f);
201+
File d = map_to_queenside(f);
202202
bonus += make_score(ShelterStrength[d][ourRank], 0);
203203

204204
if (ourRank && (ourRank == theirRank - 1))

src/psqt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void init() {
119119

120120
for (Square s = SQ_A1; s <= SQ_H8; ++s)
121121
{
122-
File f = std::min(file_of(s), ~file_of(s));
122+
File f = map_to_queenside(file_of(s));
123123
psq[ pc][ s] = score + (type_of(pc) == PAWN ? PBonus[rank_of(s)][file_of(s)]
124124
: Bonus[pc][rank_of(s)][f]);
125125
psq[~pc][~s] = -psq[pc][s];

src/types.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <climits>
4444
#include <cstdint>
4545
#include <cstdlib>
46+
#include <algorithm>
4647

4748
#if defined(_MSC_VER)
4849
// Disable some silly and noisy warning from MSVC compiler
@@ -358,14 +359,14 @@ constexpr Square operator~(Square s) {
358359
return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8
359360
}
360361

361-
constexpr File operator~(File f) {
362-
return File(f ^ FILE_H); // Horizontal flip FILE_A -> FILE_H
363-
}
364-
365362
constexpr Piece operator~(Piece pc) {
366363
return Piece(pc ^ 8); // Swap color of piece B_KNIGHT -> W_KNIGHT
367364
}
368365

366+
inline File map_to_queenside(File f) {
367+
return std::min(f, File(FILE_H - f)); // Map files ABCDEFGH to files ABCDDCBA
368+
}
369+
369370
constexpr CastlingRights operator&(Color c, CastlingRights cr) {
370371
return CastlingRights((c == WHITE ? WHITE_CASTLING : BLACK_CASTLING) & cr);
371372
}

0 commit comments

Comments
 (0)