Gravity #24

Merged
rektdie merged 3 commits from gravity into main 2025-03-19 19:07:35 +01:00
4 changed files with 35 additions and 7 deletions

No files matched your search

+2 -1
View File
@@ -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;
+2 -3
View File
@@ -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, depth * depth);
}
TT.WriteEntry(board.hashKey, depth, score, CutNode, Move());
+29 -2
View File
@@ -3,8 +3,10 @@
#include "uci.h"
#include <vector>
#include "move.h"
#include <algorithm>
constexpr int maxDepth = 64;
constexpr int maxHistory = 16384;
extern U64 nodes;
extern bool benchStarted;
@@ -15,8 +17,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 +35,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] = {};
+2 -1
View File
@@ -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;