reworked corrhist handling | bench 6409786

This commit is contained in:
rektdie committed 2025-09-10 01:26:42 +02:00
1 parent 3e652df8e8
commit 32691d2d65
5 files changed
+23 -11

No files matched your search

+5
View File
@@ -32,6 +32,7 @@ void Board::Reset() {
hashKey = 0ULL; hashKey = 0ULL;
pawnKey = 0ULL; pawnKey = 0ULL;
nonPawnKey = 0ULL;
} }
void Board::SetByFen(std::string_view fen) { void Board::SetByFen(std::string_view fen) {
@@ -275,6 +276,8 @@ void Board::SetPiece(int piece, int square, bool color) {
if (piece == Pawn) { if (piece == Pawn) {
pawnKey ^= UTILS::zKeys[color][Pawn][square]; pawnKey ^= UTILS::zKeys[color][Pawn][square];
} else {
nonPawnKey ^= UTILS::zKeys[color][piece][square];
} }
} }
@@ -287,6 +290,8 @@ void Board::RemovePiece(int piece, int square, bool color) {
if (piece == Pawn) { if (piece == Pawn) {
pawnKey ^= UTILS::zKeys[color][Pawn][square]; pawnKey ^= UTILS::zKeys[color][Pawn][square];
} else {
nonPawnKey ^= UTILS::zKeys[color][piece][square];
} }
} }
+1
View File
@@ -41,6 +41,7 @@ public:
U64 hashKey = 0ULL; U64 hashKey = 0ULL;
U64 pawnKey = 0ULL; U64 pawnKey = 0ULL;
U64 nonPawnKey = 0ULL;
void Reset(); void Reset();
void SetByFen(std::string_view fen); void SetByFen(std::string_view fen);
+3 -3
View File
@@ -42,11 +42,11 @@ int16_t ContHistory::GetTwoPly(Board& board, Move& move, SearchContext* ctx, int
} }
static int AdjustEval(Board &board, SearchContext* ctx, int eval) { static int AdjustEval(Board &board, SearchContext* ctx, int eval) {
int pawnHist = ctx->corrhist.GetPawnHist(board); int corrhist = ctx->corrhist.GetAllHist(board);
int mateFound = MATE_SCORE - MAX_PLY; int mateFound = MATE_SCORE - MAX_PLY;
return std::clamp(eval + pawnHist / CORRHIST_GRAIN, -mateFound + 1, mateFound - 1); return std::clamp(eval + corrhist / CORRHIST_GRAIN, -mateFound + 1, mateFound - 1);
} }
static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) { static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) {
@@ -666,7 +666,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
int corrHistBonus = std::clamp(results.score - staticEval, -CORRHIST_LIMIT, CORRHIST_LIMIT); int corrHistBonus = std::clamp(results.score - staticEval, -CORRHIST_LIMIT, CORRHIST_LIMIT);
ctx->corrhist.UpdatePawnHist(board, depth, corrHistBonus); ctx->corrhist.UpdateAll(board, depth, corrHistBonus);
} }
ctx->TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove); ctx->TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove);
+13 -7
View File
@@ -52,10 +52,9 @@ class CorrHist {
private: private:
// indexed by [stm][key] // indexed by [stm][key]
MultiArray<int, 2, CORRHIST_SIZE> pawnHist; MultiArray<int, 2, CORRHIST_SIZE> pawnHist;
//MultiArray<int, 2, CORRHIST_SIZE> nonPawnHist;
public: public:
void UpdatePawnHist(Board& board, int depth, int diff) { void Update(Board& board, int depth, int diff, int* entry) {
int* entry = &pawnHist[board.sideToMove][board.pawnKey % CORRHIST_SIZE];
const int scaledDiff = diff * CORRHIST_GRAIN; const int scaledDiff = diff * CORRHIST_GRAIN;
const int newWeight = std::min(depth * depth + 2 * depth + 1, 128); const int newWeight = std::min(depth * depth + 2 * depth + 1, 128);
@@ -63,12 +62,19 @@ public:
*entry = std::clamp(*entry, -CORRHIST_MAX, CORRHIST_MAX); *entry = std::clamp(*entry, -CORRHIST_MAX, CORRHIST_MAX);
} }
int GetPawnHist(Board& board) { void UpdateAll(Board& board, int depth, int diff) {
return pawnHist[board.sideToMove][board.pawnKey % CORRHIST_SIZE]; Update(board, depth, diff, &pawnHist[board.sideToMove][board.pawnKey % CORRHIST_SIZE]);
//Update(board, depth, diff, &nonPawnHist[board.sideToMove][board.nonPawnKey % CORRHIST_SIZE]);
} }
void ClearPawnHist() { int GetAllHist(Board& board) {
return pawnHist[board.sideToMove][board.pawnKey % CORRHIST_SIZE];
// + nonPawnHist[board.sideToMove][board.nonPawnKey % CORRHIST_SIZE];
}
void Clear() {
std::fill(&pawnHist[0][0], &pawnHist[0][0] + sizeof(pawnHist) / sizeof(int), 0); std::fill(&pawnHist[0][0], &pawnHist[0][0] + sizeof(pawnHist) / sizeof(int), 0);
//std::fill(&nonPawnHist[0][0], &nonPawnHist[0][0] + sizeof(nonPawnHist) / sizeof(int), 0);
} }
}; };
@@ -188,7 +194,7 @@ public:
pvLine.Clear(); pvLine.Clear();
history.Clear(); history.Clear();
conthist.Clear(); conthist.Clear();
corrhist.ClearPawnHist(); corrhist.Clear();
TT.Clear(); TT.Clear();
sw.Restart(); sw.Restart();
killerMoves = {}; killerMoves = {};
+1 -1
View File
@@ -250,7 +250,7 @@ void UCILoop(Board &board) {
ctx->killerMoves = {}; ctx->killerMoves = {};
ctx->history.Clear(); ctx->history.Clear();
ctx->conthist.Clear(); ctx->conthist.Clear();
ctx->corrhist.ClearPawnHist(); ctx->corrhist.Clear();
ctx->positionHistory = {}; ctx->positionHistory = {};
ctx->ss = {}; ctx->ss = {};