reworked corrhist handling | bench 6409786
This commit is contained in:
1 parent
3e652df8e8
commit
32691d2d65
5 files changed
+23
-11
No files matched your search
@@ -32,6 +32,7 @@ void Board::Reset() {
|
||||
|
||||
hashKey = 0ULL;
|
||||
pawnKey = 0ULL;
|
||||
nonPawnKey = 0ULL;
|
||||
}
|
||||
|
||||
void Board::SetByFen(std::string_view fen) {
|
||||
@@ -275,6 +276,8 @@ void Board::SetPiece(int piece, int square, bool color) {
|
||||
|
||||
if (piece == Pawn) {
|
||||
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) {
|
||||
pawnKey ^= UTILS::zKeys[color][Pawn][square];
|
||||
} else {
|
||||
nonPawnKey ^= UTILS::zKeys[color][piece][square];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ public:
|
||||
|
||||
U64 hashKey = 0ULL;
|
||||
U64 pawnKey = 0ULL;
|
||||
U64 nonPawnKey = 0ULL;
|
||||
|
||||
void Reset();
|
||||
void SetByFen(std::string_view fen);
|
||||
|
||||
+3
-3
@@ -42,11 +42,11 @@ int16_t ContHistory::GetTwoPly(Board& board, Move& move, SearchContext* ctx, int
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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) {
|
||||
@@ -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);
|
||||
|
||||
ctx->corrhist.UpdatePawnHist(board, depth, corrHistBonus);
|
||||
ctx->corrhist.UpdateAll(board, depth, corrHistBonus);
|
||||
}
|
||||
|
||||
ctx->TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove);
|
||||
|
||||
+13
-7
@@ -52,10 +52,9 @@ class CorrHist {
|
||||
private:
|
||||
// indexed by [stm][key]
|
||||
MultiArray<int, 2, CORRHIST_SIZE> pawnHist;
|
||||
//MultiArray<int, 2, CORRHIST_SIZE> nonPawnHist;
|
||||
public:
|
||||
void UpdatePawnHist(Board& board, int depth, int diff) {
|
||||
int* entry = &pawnHist[board.sideToMove][board.pawnKey % CORRHIST_SIZE];
|
||||
|
||||
void Update(Board& board, int depth, int diff, int* entry) {
|
||||
const int scaledDiff = diff * CORRHIST_GRAIN;
|
||||
const int newWeight = std::min(depth * depth + 2 * depth + 1, 128);
|
||||
|
||||
@@ -63,12 +62,19 @@ public:
|
||||
*entry = std::clamp(*entry, -CORRHIST_MAX, CORRHIST_MAX);
|
||||
}
|
||||
|
||||
int GetPawnHist(Board& board) {
|
||||
return pawnHist[board.sideToMove][board.pawnKey % CORRHIST_SIZE];
|
||||
void UpdateAll(Board& board, int depth, int diff) {
|
||||
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(&nonPawnHist[0][0], &nonPawnHist[0][0] + sizeof(nonPawnHist) / sizeof(int), 0);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -188,7 +194,7 @@ public:
|
||||
pvLine.Clear();
|
||||
history.Clear();
|
||||
conthist.Clear();
|
||||
corrhist.ClearPawnHist();
|
||||
corrhist.Clear();
|
||||
TT.Clear();
|
||||
sw.Restart();
|
||||
killerMoves = {};
|
||||
|
||||
+1
-1
@@ -250,7 +250,7 @@ void UCILoop(Board &board) {
|
||||
ctx->killerMoves = {};
|
||||
ctx->history.Clear();
|
||||
ctx->conthist.Clear();
|
||||
ctx->corrhist.ClearPawnHist();
|
||||
ctx->corrhist.Clear();
|
||||
ctx->positionHistory = {};
|
||||
ctx->ss = {};
|
||||
|
||||
|
||||
Reference in new issue
Block a user