From 25f793339fb078ddae47fcf73611b55d24d25202 Mon Sep 17 00:00:00 2001 From: rektdie Date: Wed, 19 Mar 2025 09:36:25 +0100 Subject: [PATCH 1/3] added history class + gravity formula | bench 405930 --- source/benchmark.cpp | 3 ++- source/search.cpp | 5 ++--- source/search.h | 30 ++++++++++++++++++++++++++++-- source/uci.cpp | 3 ++- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/source/benchmark.cpp b/source/benchmark.cpp index 517859d..1f74ec4 100644 --- a/source/benchmark.cpp +++ b/source/benchmark.cpp @@ -69,7 +69,8 @@ void RunBenchmark() { // Clearing TT.Clear(); std::memset(killerMoves, 0, sizeof(killerMoves)); - std::memset(historyMoves, 0, sizeof(historyMoves)); + + history.Clear(); nodes = 0; diff --git a/source/search.cpp b/source/search.cpp index b0f7e22..96ce0ab 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -38,7 +38,7 @@ static int ScoreMove(Board &board, Move &move, int ply) { return 18000; } else { // Max 16384 - return historyMoves[board.sideToMove][move.MoveFrom()][move.MoveTo()]; + return history[board.sideToMove][move.MoveFrom()][move.MoveTo()]; } } @@ -265,8 +265,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) { killerMoves[1][ply] = killerMoves[0][ply]; killerMoves[0][ply] = currMove; - historyMoves[board.sideToMove][currMove.MoveFrom()][currMove.MoveTo()] = - std::min(16384, historyMoves[board.sideToMove][currMove.MoveFrom()][currMove.MoveTo()] + depth * depth); + history.Update(board.sideToMove, currMove, 150 * depth); } TT.WriteEntry(board.hashKey, depth, score, CutNode, Move()); diff --git a/source/search.h b/source/search.h index 93a7ca9..08c2585 100644 --- a/source/search.h +++ b/source/search.h @@ -5,6 +5,7 @@ #include "move.h" constexpr int maxDepth = 64; +constexpr int maxHistory = 16384; extern U64 nodes; extern bool benchStarted; @@ -15,8 +16,6 @@ inline bool searchStopped = false; // [id][ply] inline int killerMoves[2][64]; -// [stm][from][to] -inline int historyMoves[2][64][64]; class SearchResults { public: @@ -35,6 +34,33 @@ public: } }; +class History { +private: + int historyMoves[2][64][64]; +public: + void Update(bool stm, Move move, int bonus) { + int clampedBonus = std::clamp(bonus, -maxHistory, maxHistory); + historyMoves[stm][move.MoveFrom()][move.MoveTo()] += + clampedBonus - historyMoves[stm][move.MoveFrom()][move.MoveTo()] * std::abs(clampedBonus) / maxHistory; + } + + void Clear() { + for (auto &side : historyMoves) { + for (auto &from : side) { + for (auto &to : from) { + to = 0; + } + } + } + } + + auto& operator[](int index) { + return historyMoves[index]; + } +}; + +inline History history; + class PVLine { private: int length[maxDepth] = {}; diff --git a/source/uci.cpp b/source/uci.cpp index 7c59ae8..9b308d6 100644 --- a/source/uci.cpp +++ b/source/uci.cpp @@ -119,7 +119,8 @@ void UCILoop(Board &board) { // Clearing TT.Clear(); std::memset(killerMoves, 0, sizeof(killerMoves)); - std::memset(historyMoves, 0, sizeof(historyMoves)); + + history.Clear(); positionIndex = 0; continue; -- 2.47.3 From ce7c14d31cddf7c407061c4d1898aab8b48276cb Mon Sep 17 00:00:00 2001 From: rektdie Date: Wed, 19 Mar 2025 09:39:13 +0100 Subject: [PATCH 2/3] including algorithm header | bench 405930 --- source/search.h | 1 + 1 file changed, 1 insertion(+) diff --git a/source/search.h b/source/search.h index 08c2585..55cb9bb 100644 --- a/source/search.h +++ b/source/search.h @@ -3,6 +3,7 @@ #include "uci.h" #include #include "move.h" +#include constexpr int maxDepth = 64; constexpr int maxHistory = 16384; -- 2.47.3 From fad8d0ac0599fded1cf9f7374358b780fa636c22 Mon Sep 17 00:00:00 2001 From: rektdie Date: Wed, 19 Mar 2025 14:13:57 +0100 Subject: [PATCH 3/3] bonus is depth * depth | bench 412557 --- source/search.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/search.cpp b/source/search.cpp index 96ce0ab..10364b2 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -265,7 +265,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) { killerMoves[1][ply] = killerMoves[0][ply]; killerMoves[0][ply] = currMove; - history.Update(board.sideToMove, currMove, 150 * depth); + history.Update(board.sideToMove, currMove, depth * depth); } TT.WriteEntry(board.hashKey, depth, score, CutNode, Move()); -- 2.47.3