template for PVS | bench 991332
This commit is contained in:
1 parent
2cbf4ba382
commit
732ad08f01
3 files changed
+12
-9
No files matched your search
@@ -80,7 +80,7 @@ void RunBenchmark() {
|
|||||||
Stopwatch sw;
|
Stopwatch sw;
|
||||||
for (int i = 0; i < fenPositions.size(); i++) {
|
for (int i = 0; i < fenPositions.size(); i++) {
|
||||||
board.SetByFen(fenPositions[i]);
|
board.SetByFen(fenPositions[i]);
|
||||||
PVS(board, depth, -inf, inf, ply);
|
PVS<true>(board, depth, -inf, inf, ply);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << nodes << " nodes " << int(nodes/sw.GetElapsedSec()) << " nps\n";
|
std::cout << nodes << " nodes " << int(nodes/sw.GetElapsedSec()) << " nps\n";
|
||||||
|
|||||||
+9
-8
@@ -161,6 +161,7 @@ static SearchResults Quiescence(Board board, int alpha, int beta, int ply) {
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <bool isPV>
|
||||||
SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
|
SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
|
||||||
if (!benchStarted) {
|
if (!benchStarted) {
|
||||||
if (sw.GetElapsedMS() >= timeToSearch) {
|
if (sw.GetElapsedMS() >= timeToSearch) {
|
||||||
@@ -174,7 +175,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
|
|||||||
|
|
||||||
|
|
||||||
// if NOT PV node then we try to hit the TTable
|
// if NOT PV node then we try to hit the TTable
|
||||||
if (beta - alpha == 1) {
|
if constexpr (!isPV) {
|
||||||
SearchResults entry = TT.ReadEntry(board.hashKey, depth, alpha, beta);
|
SearchResults entry = TT.ReadEntry(board.hashKey, depth, alpha, beta);
|
||||||
if (entry.score != invalidEntry) {
|
if (entry.score != invalidEntry) {
|
||||||
return entry;
|
return entry;
|
||||||
@@ -202,7 +203,7 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
|
|||||||
copy.MakeMove(Move());
|
copy.MakeMove(Move());
|
||||||
|
|
||||||
doingNullMove = true;
|
doingNullMove = true;
|
||||||
int score = -PVS(copy, depth - 3, -beta, -beta + 1, ply + 1).score;
|
int score = -PVS<false>(copy, depth - 3, -beta, -beta + 1, ply + 1).score;
|
||||||
doingNullMove = false;
|
doingNullMove = false;
|
||||||
|
|
||||||
if (searchStopped) return 0;
|
if (searchStopped) return 0;
|
||||||
@@ -240,23 +241,23 @@ SearchResults PVS(Board board, int depth, int alpha, int beta, int ply) {
|
|||||||
// First move (suspected PV node)
|
// First move (suspected PV node)
|
||||||
if (!i) {
|
if (!i) {
|
||||||
// Full search
|
// Full search
|
||||||
score = -PVS(copy, depth - 1, -beta, -alpha, ply + 1).score;
|
score = -PVS<true>(copy, depth - 1, -beta, -alpha, ply + 1).score;
|
||||||
} else if (reductions) {
|
} else if (reductions) {
|
||||||
// Null-window search with reductions
|
// Null-window search with reductions
|
||||||
score = -PVS(copy, depth - 1 - reductions, -alpha-1, -alpha, ply + 1).score;
|
score = -PVS<false>(copy, depth - 1 - reductions, -alpha-1, -alpha, ply + 1).score;
|
||||||
|
|
||||||
if (score > alpha) {
|
if (score > alpha) {
|
||||||
// Null-window search now without the reduction
|
// Null-window search now without the reduction
|
||||||
score = -PVS(copy, depth - 1, -alpha-1, -alpha, ply + 1).score;
|
score = -PVS<false>(copy, depth - 1, -alpha-1, -alpha, ply + 1).score;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Null-window search
|
// Null-window search
|
||||||
score = -PVS(copy, depth - 1, -alpha-1, -alpha, ply + 1).score;
|
score = -PVS<false>(copy, depth - 1, -alpha-1, -alpha, ply + 1).score;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we need to do full window re-search
|
// Check if we need to do full window re-search
|
||||||
if (i && score > alpha && score < beta) {
|
if (i && score > alpha && score < beta) {
|
||||||
score = -PVS(copy, depth - 1, -beta, -alpha, ply + 1).score;
|
score = -PVS<true>(copy, depth - 1, -beta, -alpha, ply + 1).score;
|
||||||
}
|
}
|
||||||
|
|
||||||
positionIndex--;
|
positionIndex--;
|
||||||
@@ -309,7 +310,7 @@ static SearchResults ID(Board &board, SearchParams params) {
|
|||||||
for (int depth = 1; depth <= 99; depth++) {
|
for (int depth = 1; depth <= 99; depth++) {
|
||||||
timeToSearch = (fullTime / 20) + (inc / 2);
|
timeToSearch = (fullTime / 20) + (inc / 2);
|
||||||
|
|
||||||
SearchResults currentResults = PVS(board, depth, alpha, beta, ply);
|
SearchResults currentResults = PVS<true>(board, depth, alpha, beta, ply);
|
||||||
|
|
||||||
// If we fell outside the window, try again with full width
|
// If we fell outside the window, try again with full width
|
||||||
if ((currentResults.score <= alpha)
|
if ((currentResults.score <= alpha)
|
||||||
|
|||||||
@@ -96,7 +96,9 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <bool isPV>
|
||||||
SearchResults PVS(Board board, int depth, int alpha, int beta, int ply);
|
SearchResults PVS(Board board, int depth, int alpha, int beta, int ply);
|
||||||
|
|
||||||
void SearchPosition(Board &board, SearchParams params);
|
void SearchPosition(Board &board, SearchParams params);
|
||||||
void StopSearch();
|
void StopSearch();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user