No globals #50

Merged
rektdie merged 23 commits from no_globals into main 2025-04-12 13:52:41 +02:00
5 changed files with 16 additions and 19 deletions
Showing only changes of commit 91ec9282a0 - Show all commits

No files matched your search

-3
View File
@@ -71,8 +71,6 @@ void RunBenchmark() {
// Clearing
TT.Clear();
std::memset(killerMoves, 0, sizeof(killerMoves));
history.Clear();
SearchContext ctx;
@@ -86,6 +84,5 @@ void RunBenchmark() {
std::cout << ctx.nodes << " nodes " << int(ctx.nodes/sw.GetElapsedSec()) << " nps" << std::endl;
TT.Clear();
std::memset(killerMoves, 0, sizeof(killerMoves));
history.Clear();
positionIndex = 0;
}
-1
View File
@@ -103,7 +103,6 @@ void PlayGame(std::atomic<int>& positions, U64 targetPositions, std::vector<Game
positionIndex = 0;
std::memset(SEARCH::killerMoves, 0, sizeof(SEARCH::killerMoves));
SEARCH::history.Clear();
SEARCH::SearchContext ctx;
+11 -11
View File
@@ -29,7 +29,7 @@ void InitLMRTable() {
}
}
static int ScoreMove(Board &board, Move &move, int ply) {
static int ScoreMove(Board &board, Move &move, int ply, SearchContext& ctx) {
TTEntry *current = TT.GetRawEntry(board.hashKey);
if (current->bestMove == move) {
return 50000;
@@ -51,20 +51,20 @@ static int ScoreMove(Board &board, Move &move, int ply) {
return 18000;
} else {
// Max 16384
return history[board.sideToMove][move.MoveFrom()][move.MoveTo()];
return ctx.history[board.sideToMove][move.MoveFrom()][move.MoveTo()];
}
}
return 0;
}
static void SortMoves(Board &board, int ply) {
static void SortMoves(Board &board, int ply, SearchContext& ctx) {
std::array<int, MAX_MOVES> scores;
std::array<int, MAX_MOVES> indices;
// Initialize scores and indices
for (int i = 0; i < board.currentMoveIndex; i++) {
scores[i] = ScoreMove(board, board.moveList[i], ply);
scores[i] = ScoreMove(board, board.moveList[i], ply, ctx);
indices[i] = i;
}
@@ -86,14 +86,14 @@ static void SortMoves(Board &board, int ply) {
}
}
void ListScores(Board &board, int ply) {
SortMoves(board, ply);
void ListScores(Board &board, int ply, SearchContext& ctx) {
SortMoves(board, ply, ctx);
for (int i = 0; i < board.currentMoveIndex; i++) {
Move currentMove = board.moveList[i];
std::cout << squareCoords[currentMove.MoveFrom()] << squareCoords[currentMove.MoveTo()];
std::cout << ": " << ScoreMove(board, currentMove, ply) << '\n';
std::cout << ": " << ScoreMove(board, currentMove, ply, ctx) << '\n';
}
}
@@ -169,7 +169,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply, Searc
MOVEGEN::GenerateMoves<Noisy>(board);
SortMoves(board, ply);
SortMoves(board, ply, ctx);
SearchResults results;
@@ -265,7 +265,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo
MOVEGEN::GenerateMoves<All>(board);
SortMoves(board, ply);
SortMoves(board, ply, ctx);
int score = -inf;
int nodeType = AllNode;
@@ -338,10 +338,10 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply, SearchCo
int bonus = depth * depth;
history.Update(board.sideToMove, currMove, bonus);
ctx.history.Update(board.sideToMove, currMove, bonus);
for (int moveIndex = 0; moveIndex < seenQuietsCount - 1; moveIndex++) {
history.Update(board.sideToMove, seenQuiets[moveIndex], -bonus);
ctx.history.Update(board.sideToMove, seenQuiets[moveIndex], -bonus);
}
}
+4 -3
View File
@@ -72,8 +72,6 @@ public:
}
};
inline History history;
class PVLine {
private:
int length[MAX_PLY] = {};
@@ -112,10 +110,13 @@ public:
U64 nodesToGo = 0;
bool doingNullMove = false;
PVLine pvLine;
History history;
SearchContext(){
pvLine.Clear();
history.Clear();
}
};
@@ -137,5 +138,5 @@ constexpr int moveScoreTable[6][6] = {
100, 200, 300, 400, 500, 600
};
void ListScores(Board &board);
void ListScores(Board &board, SearchContext& ctx);
}
+1 -1
View File
@@ -138,7 +138,7 @@ void UCILoop(Board &board) {
TT.Clear();
std::memset(SEARCH::killerMoves, 0, sizeof(SEARCH::killerMoves));
SEARCH::history.Clear();
ctx.history.Clear();
positionIndex = 0;
continue;