Skip to content

Commit 960d59d

Browse files
protonspringvondele
authored andcommitted
Consolidate Square Flipping
Add a flip_rank() and flip_file() so that all of the square flipping can be consolidated. STC LLR: 2.94 (-2.94,2.94) {-1.50,0.50} Total: 57234 W: 11064 L: 10969 D: 35201 Ptnml(0-2): 822, 6562, 13801, 6563, 869 http://tests.stockfishchess.org/tests/view/5e5d2f2aafe6254521f2ffaa closes #2568 No functional change.
1 parent c6839a2 commit 960d59d

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

src/endgame.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ namespace {
7474
assert(pos.count<PAWN>(strongSide) == 1);
7575

7676
if (file_of(pos.square<PAWN>(strongSide)) >= FILE_E)
77-
sq = Square(int(sq) ^ 7); // Mirror SQ_H1 -> SQ_A1
77+
sq = flip_file(sq);
7878

79-
return strongSide == WHITE ? sq : ~sq;
79+
return strongSide == WHITE ? sq : flip_rank(sq);
8080
}
8181

8282
} // namespace

src/psqt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void init() {
114114
File f = map_to_queenside(file_of(s));
115115
psq[ pc][ s] = score + (type_of(pc) == PAWN ? PBonus[rank_of(s)][file_of(s)]
116116
: Bonus[pc][rank_of(s)][f]);
117-
psq[~pc][~s] = -psq[pc][s];
117+
psq[~pc][flip_rank(s)] = -psq[pc][s];
118118
}
119119
}
120120
}

src/syzygy/tbprobe.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ enum TBType { KEY, WDL, DTZ }; // Used as template parameter
6666
enum TBFlag { STM = 1, Mapped = 2, WinPlies = 4, LossPlies = 8, Wide = 16, SingleValue = 128 };
6767

6868
inline WDLScore operator-(WDLScore d) { return WDLScore(-int(d)); }
69-
inline Square operator^=(Square& s, int i) { return s = Square(int(s) ^ i); }
7069
inline Square operator^(Square s, int i) { return Square(int(s) ^ i); }
7170

7271
const std::string PieceToChar = " PNBRQK pnbrqk";
@@ -743,7 +742,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
743742
// the triangle A1-D1-D4.
744743
if (file_of(squares[0]) > FILE_D)
745744
for (int i = 0; i < size; ++i)
746-
squares[i] ^= 7; // Horizontal flip: SQ_H1 -> SQ_A1
745+
squares[i] = flip_file(squares[i]);
747746

748747
// Encode leading pawns starting with the one with minimum MapPawns[] and
749748
// proceeding in ascending order.
@@ -762,7 +761,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
762761
// piece is below RANK_5.
763762
if (rank_of(squares[0]) > RANK_4)
764763
for (int i = 0; i < size; ++i)
765-
squares[i] ^= SQ_A8; // Vertical flip: SQ_A8 -> SQ_A1
764+
squares[i] = flip_rank(squares[i]);
766765

767766
// Look for the first piece of the leading group not on the A1-D4 diagonal
768767
// and ensure it is mapped below the diagonal.
@@ -1344,7 +1343,7 @@ void Tablebases::init(const std::string& paths) {
13441343
if (leadPawnsCnt == 1)
13451344
{
13461345
MapPawns[sq] = availableSquares--;
1347-
MapPawns[sq ^ 7] = availableSquares--; // Horizontal flip
1346+
MapPawns[flip_file(sq)] = availableSquares--;
13481347
}
13491348
LeadPawnIdx[leadPawnsCnt][sq] = idx;
13501349
idx += Binomial[leadPawnsCnt - 1][MapPawns[sq]];

src/types.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,12 @@ constexpr Color operator~(Color c) {
358358
return Color(c ^ BLACK); // Toggle color
359359
}
360360

361-
constexpr Square operator~(Square s) {
362-
return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8
361+
constexpr Square flip_rank(Square s) {
362+
return Square(s ^ SQ_A8);
363+
}
364+
365+
constexpr Square flip_file(Square s) {
366+
return Square(s ^ SQ_H1);
363367
}
364368

365369
constexpr Piece operator~(Piece pc) {

0 commit comments

Comments
 (0)