No globals #50
No files matched your search
@@ -4,7 +4,6 @@
|
||||
#include "benchmark.h"
|
||||
#include "search.h"
|
||||
#include "stopwatch.h"
|
||||
#include "tt.h"
|
||||
|
||||
using namespace SEARCH;
|
||||
|
||||
@@ -66,12 +65,8 @@ void RunBenchmark() {
|
||||
int depth = BENCH_DEPTH;
|
||||
int ply = 0;
|
||||
|
||||
// Clearing
|
||||
TT.Clear();
|
||||
|
||||
SearchContext ctx;
|
||||
|
||||
|
||||
Stopwatch sw;
|
||||
for (int i = 0; i < fenPositions.size(); i++) {
|
||||
board.SetByFen(fenPositions[i]);
|
||||
@@ -79,5 +74,4 @@ void RunBenchmark() {
|
||||
}
|
||||
|
||||
std::cout << ctx.nodes << " nodes " << int(ctx.nodes/sw.GetElapsedSec()) << " nps" << std::endl;
|
||||
TT.Clear();
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "board.h"
|
||||
#include "movegen.h"
|
||||
#include "tt.h"
|
||||
#include <iostream>
|
||||
#include <ranges>
|
||||
#include <string_view>
|
||||
|
||||
+19
-6
@@ -9,6 +9,19 @@
|
||||
|
||||
namespace SEARCH {
|
||||
|
||||
SearchContext::SearchContext() {
|
||||
pvLine.Clear();
|
||||
history.Clear();
|
||||
TT = new TTable();
|
||||
sw.Restart();
|
||||
killerMoves = {};
|
||||
positionHistory = {};
|
||||
}
|
||||
|
||||
SearchContext::~SearchContext() {
|
||||
delete TT;
|
||||
}
|
||||
|
||||
void InitLMRTable() {
|
||||
for (int depth = 0; depth <= MAX_DEPTH; depth++) {
|
||||
for (int move = 0; move < MAX_MOVES; move++) {
|
||||
@@ -25,7 +38,7 @@ void InitLMRTable() {
|
||||
}
|
||||
|
||||
static int ScoreMove(Board &board, Move &move, int ply, SearchContext& ctx) {
|
||||
TTEntry *current = TT.GetRawEntry(board.hashKey);
|
||||
TTEntry *current = ctx.TT->GetRawEntry(board.hashKey);
|
||||
if (current->bestMove == move) {
|
||||
return 50000;
|
||||
}
|
||||
@@ -148,7 +161,7 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear
|
||||
|
||||
int bestScore = HCE::Evaluate(board);
|
||||
|
||||
TTEntry *entry = TT.GetRawEntry(board.hashKey);
|
||||
TTEntry *entry = ctx.TT->GetRawEntry(board.hashKey);
|
||||
if (entry->hashKey == board.hashKey) {
|
||||
bestScore = entry->score;
|
||||
}
|
||||
@@ -222,7 +235,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
||||
|
||||
// if NOT PV node then we try to hit the TTable
|
||||
if constexpr (!isPV) {
|
||||
SearchResults entry = TT.ReadEntry(board.hashKey, depth, alpha, beta);
|
||||
SearchResults entry = ctx.TT->ReadEntry(board.hashKey, depth, alpha, beta);
|
||||
if (entry.score != invalidEntry) {
|
||||
return entry;
|
||||
}
|
||||
@@ -340,7 +353,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
||||
}
|
||||
}
|
||||
|
||||
TT.WriteEntry(board.hashKey, depth, score, CutNode, Move());
|
||||
ctx.TT->WriteEntry(board.hashKey, depth, score, CutNode, Move());
|
||||
return score;
|
||||
}
|
||||
|
||||
@@ -363,7 +376,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
||||
}
|
||||
|
||||
if (ctx.searchStopped) return 0;
|
||||
TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove);
|
||||
ctx.TT->WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove);
|
||||
return results;
|
||||
}
|
||||
|
||||
@@ -431,7 +444,7 @@ static SearchResults ID(Board &board, SearchParams params, SearchContext& ctx) {
|
||||
std::cout << " time " << elapsed;
|
||||
std::cout << " score cp " << UTILS::ConvertToWhiteRelative(board, safeResults.score);
|
||||
std::cout << " nodes " << ctx.nodes << " nps " << int(ctx.nodes/ctx.sw.GetElapsedSec());
|
||||
std::cout << " hashfull " << TT.GetUsedPercentage();
|
||||
std::cout << " hashfull " << ctx.TT->GetUsedPercentage();
|
||||
std::cout << " pv ";
|
||||
ctx.pvLine.Print(0);
|
||||
std::cout << std::endl;
|
||||
|
||||
+5
-7
@@ -6,6 +6,8 @@
|
||||
#include <algorithm>
|
||||
#include "stopwatch.h"
|
||||
|
||||
class TTable;
|
||||
|
||||
namespace SEARCH {
|
||||
|
||||
enum searchMode {
|
||||
@@ -111,19 +113,15 @@ public:
|
||||
|
||||
PVLine pvLine;
|
||||
History history;
|
||||
TTable* TT;
|
||||
|
||||
std::array<std::array<int, MAX_PLY>, 2> killerMoves{};
|
||||
std::array<U64, 1000> positionHistory;
|
||||
|
||||
Stopwatch sw;
|
||||
|
||||
SearchContext(){
|
||||
pvLine.Clear();
|
||||
history.Clear();
|
||||
sw.Restart();
|
||||
killerMoves = {};
|
||||
positionHistory = {};
|
||||
}
|
||||
SearchContext();
|
||||
~SearchContext();
|
||||
};
|
||||
|
||||
template <bool isPV, searchMode mode>
|
||||
|
||||
@@ -60,5 +60,3 @@ public:
|
||||
|
||||
void WriteEntry(U64 &hashKey, int depth, int score, int nodeType, Move besteMove);
|
||||
};
|
||||
|
||||
inline TTable TT;
|
||||
+4
-4
@@ -92,10 +92,10 @@ static void ParseGo(Board &board, std::string &command, SEARCH::SearchContext& c
|
||||
}
|
||||
}
|
||||
|
||||
static void SetOption(std::string &command) {
|
||||
static void SetOption(std::string &command, SEARCH::SearchContext& ctx) {
|
||||
if (command.find("Hash") != std::string::npos) {
|
||||
hashSize = (ReadParam("value", command) * 1000000) / sizeof(TTEntry);
|
||||
TT.Resize(hashSize);
|
||||
ctx.TT->Resize(hashSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ void UCILoop(Board &board) {
|
||||
board.SetByFen(StartingFen);
|
||||
|
||||
// Clearing
|
||||
TT.Clear();
|
||||
ctx.TT->Clear();
|
||||
|
||||
ctx.killerMoves = {};
|
||||
ctx.history.Clear();
|
||||
@@ -169,7 +169,7 @@ void UCILoop(Board &board) {
|
||||
}
|
||||
|
||||
if (input.find("setoption") != std::string::npos) {
|
||||
SetOption(input);
|
||||
SetOption(input, ctx);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user