Merge pull request #37 from rektdie/lmr_table

Lmr table bench 3761943
This commit was merged in pull request #37.
This commit is contained in:
rektdie authored and GitHub committed 2025-03-28 02:42:35 +01:00
commit d049a6096d
6 files changed
+39 -19

No files matched your search

+1 -1
View File
@@ -63,7 +63,7 @@ constexpr std::array<std::string_view, 50> fenPositions = {
void RunBenchmark() {
Board board;
int depth = 6;
int depth = 8;
int ply = 0;
benchStarted = true;
searchStopped = false;
+1 -1
View File
@@ -22,7 +22,7 @@ void Board::Reset() {
pieceThreats = std::array<Bitboard, 6>();
colorThreats = std::array<Bitboard, 2>();
moveList = std::array<Move, 218>();
moveList = std::array<Move, MAX_MOVES>();
currentMoveIndex = 0;
+3 -1
View File
@@ -7,6 +7,8 @@
constexpr int nullPieceType = 100;
constexpr int noEPTarget = -1;
constexpr int MAX_MOVES = 218;
inline int positionIndex = 0;
inline U64 positionHistory[1000];
@@ -24,7 +26,7 @@ public:
std::array<Bitboard, 6> pieceThreats;
std::array<Bitboard, 2> colorThreats;
std::array<Move, 218> moveList;
std::array<Move, MAX_MOVES> moveList;
int currentMoveIndex = 0;
bool sideToMove = White;
+2
View File
@@ -3,11 +3,13 @@
#include "uci.h"
#include "utils.h"
#include "benchmark.h"
#include "search.h"
int main(int argc, char* argv[]) {
MOVEGEN::initLeaperAttacks();
MOVEGEN::initSliderAttacks();
UTILS::InitZobrist();
SEARCH::InitLMRTable();
Board board;
+20 -8
View File
@@ -18,6 +18,21 @@ inline PVLine pvLine;
Stopwatch sw;
void InitLMRTable() {
for (int depth = 0; depth <= MAX_DEPTH; depth++) {
for (int move = 0; move < MAX_MOVES; move++) {
if (depth == 0 || move == 0) {
lmrTable[depth][move] = 0;
} else {
double base = 0.77;
double divisor = 2.36;
lmrTable[depth][move] = std::floor(base + std::log(depth) * std::log(move) / divisor);
}
}
}
}
static int ScoreMove(Board &board, Move &move, int ply) {
TTEntry *current = TT.GetRawEntry(board.hashKey);
if (current->bestMove == move) {
@@ -48,8 +63,8 @@ static int ScoreMove(Board &board, Move &move, int ply) {
}
static void SortMoves(Board &board, int ply) {
std::array<int, 218> scores;
std::array<int, 218> indices;
std::array<int, MAX_MOVES> scores;
std::array<int, MAX_MOVES> indices;
// Initialize scores and indices
for (int i = 0; i < board.currentMoveIndex; i++) {
@@ -64,7 +79,7 @@ static void SortMoves(Board &board, int ply) {
});
// Create a temporary move list and reorder the moveList based on the sorted indices
std::array<Move, 218> sortedMoves;
std::array<Move, MAX_MOVES> sortedMoves;
for (int i = 0; i < board.currentMoveIndex; i++) {
sortedMoves[i] = board.moveList[indices[i]];
}
@@ -107,10 +122,7 @@ static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int
// Late Move Reduction
if (depth >= 3 && moveSeen >= 3 && !move.IsCapture()) {
double base = 0.77;
double divisor = 2.36;
reduction = std::floor(base + std::log(depth) * std::log(moveSeen) / divisor);
reduction = lmrTable[depth][moveSeen];
}
return reduction;
@@ -329,7 +341,7 @@ static SearchResults ID(Board &board, SearchParams params) {
int elapsed = 0;
sw.Restart();
for (int depth = 1; depth <= 99; depth++) {
for (int depth = 1; depth <= MAX_DEPTH; depth++) {
timeToSearch = std::max((fullTime / 20) + (inc / 2), 4);
int softTime = timeToSearch * 0.65;
+12 -8
View File
@@ -8,8 +8,8 @@
namespace SEARCH {
constexpr int MATE_SCORE = -99000;
constexpr int maxDepth = 64;
constexpr int maxHistory = 16384;
constexpr int MAX_DEPTH = 64;
constexpr int MAX_HISTORY = 16384;
extern U64 nodes;
extern bool benchStarted;
@@ -21,6 +21,10 @@ inline bool searchStopped = false;
// [id][ply]
inline int killerMoves[2][64];
inline int lmrTable[MAX_DEPTH+1][MAX_MOVES];
void InitLMRTable();
class SearchResults {
public:
int score = 0;
@@ -43,9 +47,9 @@ private:
int historyMoves[2][64][64];
public:
void Update(bool stm, Move move, int bonus) {
int clampedBonus = std::clamp(bonus, -maxHistory, maxHistory);
int clampedBonus = std::clamp(bonus, -MAX_HISTORY, MAX_HISTORY);
historyMoves[stm][move.MoveFrom()][move.MoveTo()] +=
clampedBonus - historyMoves[stm][move.MoveFrom()][move.MoveTo()] * std::abs(clampedBonus) / maxHistory;
clampedBonus - historyMoves[stm][move.MoveFrom()][move.MoveTo()] * std::abs(clampedBonus) / MAX_HISTORY;
}
void Clear() {
@@ -67,8 +71,8 @@ inline History history;
class PVLine {
private:
int length[maxDepth] = {};
Move table[maxDepth][maxDepth] = {};
int length[MAX_DEPTH] = {};
Move table[MAX_DEPTH][MAX_DEPTH] = {};
public:
void SetLength(int ply) {
length[ply] = ply;
@@ -92,8 +96,8 @@ public:
}
void Clear() {
length[maxDepth - 1] = {};
table[maxDepth - 1][maxDepth - 1] = {};
length[MAX_DEPTH - 1] = {};
table[MAX_DEPTH - 1][MAX_DEPTH - 1] = {};
}
};