encapsualted position index and array | bench 1857933

This commit is contained in:
rektdie committed 2025-04-12 20:39:00 +02:00
1 parent b669fa329e
commit 3225b9c665
8 files changed
+19 -28

No files matched your search

+8 -8
View File
@@ -92,9 +92,9 @@ void ListScores(Board &board, int ply, SearchContext& ctx) {
}
}
static bool IsThreefold(Board &board) {
for (int i = 0; i < positionIndex; i++) {
if (positionHistory[i] == board.hashKey) {
static bool IsThreefold(Board &board, SearchContext& ctx) {
for (int i = 0; i < board.positionIndex; i++) {
if (ctx.positionHistory[i] == board.hashKey) {
// repetition found
return true;
}
@@ -113,8 +113,8 @@ static bool IsInsuffMat(Board &board) {
&& !(board.pieces[Pawn] | board.pieces[Queen] | board.pieces[Rook]));
}
bool IsDraw(Board &board) {
return IsFifty(board) || IsInsuffMat(board) || IsThreefold(board);
bool IsDraw(Board &board, SearchContext& ctx) {
return IsFifty(board) || IsInsuffMat(board) || IsThreefold(board, ctx);
}
static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int ply) {
@@ -172,9 +172,9 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear
Board copy = board;
int isLegal = copy.MakeMove(board.moveList[i]);
if (!isLegal) continue;
ctx.positionHistory[copy.positionIndex] = copy.hashKey;
ctx.nodes++;
int score = -Quiescence<mode>(copy, -beta, -alpha, ply + 1, ctx).score;
positionIndex--;
if (score >= beta) {
return score;
@@ -217,7 +217,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
}
ctx.pvLine.SetLength(ply);
if (ply && (IsThreefold(board) || IsFifty(board) || IsInsuffMat(board))) return 0;
if (ply && (IsDraw(board, ctx))) return 0;
// if NOT PV node then we try to hit the TTable
@@ -287,6 +287,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
bool isLegal = copy.MakeMove(currMove);
if (!isLegal) continue;
ctx.positionHistory[copy.positionIndex] = copy.hashKey;
ctx.nodes++;
int reductions = GetReductions(board, currMove, depth, moveSeen, ply);
@@ -316,7 +317,6 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
}
moveSeen++;
positionIndex--;
if (ctx.searchStopped) return 0;