mirror of
https://github.com/sockspls/badfish
synced 2025-05-01 09:13:08 +00:00
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 https://github.com/official-stockfish/Stockfish/pull/2568 No functional change.
This commit is contained in:
parent
c6839a2615
commit
960d59d541
4 changed files with 12 additions and 9 deletions
|
@ -74,9 +74,9 @@ namespace {
|
||||||
assert(pos.count<PAWN>(strongSide) == 1);
|
assert(pos.count<PAWN>(strongSide) == 1);
|
||||||
|
|
||||||
if (file_of(pos.square<PAWN>(strongSide)) >= FILE_E)
|
if (file_of(pos.square<PAWN>(strongSide)) >= FILE_E)
|
||||||
sq = Square(int(sq) ^ 7); // Mirror SQ_H1 -> SQ_A1
|
sq = flip_file(sq);
|
||||||
|
|
||||||
return strongSide == WHITE ? sq : ~sq;
|
return strongSide == WHITE ? sq : flip_rank(sq);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -114,7 +114,7 @@ void init() {
|
||||||
File f = map_to_queenside(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)]
|
psq[ pc][ s] = score + (type_of(pc) == PAWN ? PBonus[rank_of(s)][file_of(s)]
|
||||||
: Bonus[pc][rank_of(s)][f]);
|
: Bonus[pc][rank_of(s)][f]);
|
||||||
psq[~pc][~s] = -psq[pc][s];
|
psq[~pc][flip_rank(s)] = -psq[pc][s];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,6 @@ enum TBType { KEY, WDL, DTZ }; // Used as template parameter
|
||||||
enum TBFlag { STM = 1, Mapped = 2, WinPlies = 4, LossPlies = 8, Wide = 16, SingleValue = 128 };
|
enum TBFlag { STM = 1, Mapped = 2, WinPlies = 4, LossPlies = 8, Wide = 16, SingleValue = 128 };
|
||||||
|
|
||||||
inline WDLScore operator-(WDLScore d) { return WDLScore(-int(d)); }
|
inline WDLScore operator-(WDLScore d) { return WDLScore(-int(d)); }
|
||||||
inline Square operator^=(Square& s, int i) { return s = Square(int(s) ^ i); }
|
|
||||||
inline Square operator^(Square s, int i) { return Square(int(s) ^ i); }
|
inline Square operator^(Square s, int i) { return Square(int(s) ^ i); }
|
||||||
|
|
||||||
const std::string PieceToChar = " PNBRQK pnbrqk";
|
const std::string PieceToChar = " PNBRQK pnbrqk";
|
||||||
|
@ -743,7 +742,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
|
||||||
// the triangle A1-D1-D4.
|
// the triangle A1-D1-D4.
|
||||||
if (file_of(squares[0]) > FILE_D)
|
if (file_of(squares[0]) > FILE_D)
|
||||||
for (int i = 0; i < size; ++i)
|
for (int i = 0; i < size; ++i)
|
||||||
squares[i] ^= 7; // Horizontal flip: SQ_H1 -> SQ_A1
|
squares[i] = flip_file(squares[i]);
|
||||||
|
|
||||||
// Encode leading pawns starting with the one with minimum MapPawns[] and
|
// Encode leading pawns starting with the one with minimum MapPawns[] and
|
||||||
// proceeding in ascending order.
|
// proceeding in ascending order.
|
||||||
|
@ -762,7 +761,7 @@ Ret do_probe_table(const Position& pos, T* entry, WDLScore wdl, ProbeState* resu
|
||||||
// piece is below RANK_5.
|
// piece is below RANK_5.
|
||||||
if (rank_of(squares[0]) > RANK_4)
|
if (rank_of(squares[0]) > RANK_4)
|
||||||
for (int i = 0; i < size; ++i)
|
for (int i = 0; i < size; ++i)
|
||||||
squares[i] ^= SQ_A8; // Vertical flip: SQ_A8 -> SQ_A1
|
squares[i] = flip_rank(squares[i]);
|
||||||
|
|
||||||
// Look for the first piece of the leading group not on the A1-D4 diagonal
|
// Look for the first piece of the leading group not on the A1-D4 diagonal
|
||||||
// and ensure it is mapped below the diagonal.
|
// and ensure it is mapped below the diagonal.
|
||||||
|
@ -1344,7 +1343,7 @@ void Tablebases::init(const std::string& paths) {
|
||||||
if (leadPawnsCnt == 1)
|
if (leadPawnsCnt == 1)
|
||||||
{
|
{
|
||||||
MapPawns[sq] = availableSquares--;
|
MapPawns[sq] = availableSquares--;
|
||||||
MapPawns[sq ^ 7] = availableSquares--; // Horizontal flip
|
MapPawns[flip_file(sq)] = availableSquares--;
|
||||||
}
|
}
|
||||||
LeadPawnIdx[leadPawnsCnt][sq] = idx;
|
LeadPawnIdx[leadPawnsCnt][sq] = idx;
|
||||||
idx += Binomial[leadPawnsCnt - 1][MapPawns[sq]];
|
idx += Binomial[leadPawnsCnt - 1][MapPawns[sq]];
|
||||||
|
|
|
@ -358,8 +358,12 @@ constexpr Color operator~(Color c) {
|
||||||
return Color(c ^ BLACK); // Toggle color
|
return Color(c ^ BLACK); // Toggle color
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Square operator~(Square s) {
|
constexpr Square flip_rank(Square s) {
|
||||||
return Square(s ^ SQ_A8); // Vertical flip SQ_A1 -> SQ_A8
|
return Square(s ^ SQ_A8);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Square flip_file(Square s) {
|
||||||
|
return Square(s ^ SQ_H1);
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Piece operator~(Piece pc) {
|
constexpr Piece operator~(Piece pc) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue