Se #83

Merged
rektdie merged 3 commits from SE into main 2025-07-29 03:01:05 +02:00
3 changed files with 45 additions and 15 deletions

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once
#include <string>
constexpr int BENCH_DEPTH = 11;
constexpr int BENCH_DEPTH = 16;
void RunBenchmark();
+42 -14
View File
@@ -244,10 +244,12 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear
int bestScore = NNUE::net.Evaluate(board);
ctx->ss[ply].eval = bestScore;
TTEntry *entry = ctx->TT.GetRawEntry(board.hashKey);
if (entry->hashKey == board.hashKey) {
bestScore = entry->score;
if (!ctx->excluded) {
TTEntry *entry = ctx->TT.GetRawEntry(board.hashKey);
if (entry->hashKey == board.hashKey) {
bestScore = entry->score;
}
}
@@ -331,7 +333,10 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
if (ply && (IsDraw(board, ctx))) return 0;
TTEntry entry = ctx->TT.ReadEntry(board.hashKey, depth, alpha, beta);
TTEntry entry = TTEntry(invalidEntry);
if (!ctx->excluded)
entry = ctx->TT.ReadEntry(board.hashKey, depth, alpha, beta);
const bool ttHit = entry.score != invalidEntry;
// if NOT PV node then we try to hit the TTable
@@ -357,7 +362,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
return true;
}();
if (!board.InCheck()) {
if (!board.InCheck() && !ctx->excluded) {
if (ply) {
// Reverse Futility Pruning
int margin = 100 * (depth - improving);
@@ -369,11 +374,10 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
if (!ctx->doingNullMove && staticEval >= beta) {
if (depth > 1 && !board.InPossibleZug()) {
Board copy = board;
bool isLegal = copy.MakeMove(Move());
// Always legal so we dont check it
copy.MakeMove(Move());
const int reduction = 3 + improving;
ctx->doingNullMove = true;
int score = -PVS<false, mode>(copy, depth - reduction, -beta, -beta + 1, ply + 1, ctx, !cutnode).score;
ctx->doingNullMove = false;
@@ -401,6 +405,9 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
for (int i = 0; i < board.currentMoveIndex; i++) {
Move currMove = board.moveList[i];
if (ctx->excluded == currMove)
continue;
bool notMated = results.score > (-MATE_SCORE + MAX_PLY);
// Late move pruning
@@ -428,7 +435,6 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
continue;
}
Board copy = board;
bool isLegal = copy.MakeMove(currMove);
@@ -443,6 +449,26 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
ctx->positionHistory[copy.positionIndex] = copy.hashKey;
ctx->nodes++;
int extension = 0;
if (ply
&& depth >= 8
&& currMove == entry.bestMove
&& ctx->excluded == 0
&& entry.depth >= depth - 3
&& entry.nodeType != AllNode)
{
const int sBeta = std::max(-inf + 1, entry.score - depth * 2);
const int sDepth = (depth - 1) / 2;
ctx->excluded = currMove;
const int score = PVS<false, mode>(board, sDepth, sBeta-1, sBeta, ply, ctx, cutnode).score;
ctx->excluded = Move();
if (score < sBeta)
extension = 1;
}
// PVS SEE
int SEEThreshold = currMove.IsQuiet() ? -80 * depth : -30 * depth * depth;
@@ -451,7 +477,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
int reductions = GetReductions<isPV>(board, currMove, depth, moveSeen, ply, cutnode, ctx);
int newDepth = depth + copy.InCheck() - 1;
int newDepth = depth + copy.InCheck() - 1 + extension;
// First move (suspected PV node)
if (!moveSeen) {
@@ -522,7 +548,8 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
}
}
ctx->TT.WriteEntry(board.hashKey, depth, score, CutNode, currMove);
if (!ctx->excluded)
ctx->TT.WriteEntry(board.hashKey, depth, score, CutNode, currMove);
return score;
}
@@ -545,7 +572,8 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
}
if (ctx->searchStopped) return 0;
ctx->TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove);
if (!ctx->excluded)
ctx->TT.WriteEntry(board.hashKey, depth, results.score, nodeType, results.bestMove);
return results;
}
+2
View File
@@ -121,6 +121,8 @@ public:
int timeToSearch = 0;
int seldepth = 0;
Move excluded = Move();
bool doingNullMove = false;
bool searchStopped = false;