From 0d3c23ed738a3851229ba34e3dff47a1b85a0e1d Mon Sep 17 00:00:00 2001 From: rektdie Date: Thu, 23 Oct 2025 01:52:57 +0200 Subject: [PATCH] little refactor | bench 5408634 --- source/search.cpp | 28 +++++++++------------------- source/search.h | 3 +-- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/source/search.cpp b/source/search.cpp index d8aa55e..5acde0d 100644 --- a/source/search.cpp +++ b/source/search.cpp @@ -28,22 +28,12 @@ void InitLMRTable() { } } -int16_t ContHistory::GetOnePly(Board& board, Move& move, SearchContext* ctx, int ply) { - int prevType = ctx->ss[ply-1].pieceType; - int prevTo = ctx->ss[ply-1].moveTo; +int16_t ContHistory::GetNPly(Board& board, Move& move, SearchContext* ctx, int ply, int n) { + int prevType = ctx->ss[ply-n].pieceType; + int prevTo = ctx->ss[ply-n].moveTo; int pieceType = board.GetPieceType(move.MoveFrom()); int to = move.MoveTo(); - bool otherColor = ctx->ss[ply-1].side; - - return ctx->conthist[otherColor][prevType][prevTo][board.sideToMove][pieceType][to]; -} - -int16_t ContHistory::GetTwoPly(Board& board, Move& move, SearchContext* ctx, int ply) { - int prevType = ctx->ss[ply-2].pieceType; - int prevTo = ctx->ss[ply-2].moveTo; - int pieceType = board.GetPieceType(move.MoveFrom()); - int to = move.MoveTo(); - bool otherColor = ctx->ss[ply-2].side; + bool otherColor = ctx->ss[ply-n].side; return ctx->conthist[otherColor][prevType][prevTo][board.sideToMove][pieceType][to]; } @@ -84,7 +74,7 @@ static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) { int conthistScore = 0; if (ply > 0) { - conthistScore = ctx->conthist.GetOnePly(board, move, ctx, ply); + conthistScore = ctx->conthist.GetNPly(board, move, ctx, ply, 1); /* if (ply > 1) { conthistScore += ctx->conthist.GetTwoPly(board, move, ctx, ply); @@ -185,10 +175,10 @@ static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int // History LMR int historyReduction = ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()][sourceThreatened][targetThreatened]; if (ply > 0) { - historyReduction += ctx->conthist.GetOnePly(board, move, ctx, ply); + historyReduction += ctx->conthist.GetNPly(board, move, ctx, ply, 1); if (ply > 1) - historyReduction += ctx->conthist.GetTwoPly(board, move, ctx, ply); + historyReduction += ctx->conthist.GetNPly(board, move, ctx, ply, 2); } reduction /= 1024; @@ -571,10 +561,10 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC int historyScore = ctx->history[board.sideToMove][currMove.MoveFrom()][currMove.MoveTo()][sourceThreatened][targetThreatened]; if (ply > 0) { - historyScore += ctx->conthist.GetOnePly(board, currMove, ctx, ply); + historyScore += ctx->conthist.GetNPly(board, currMove, ctx, ply, 1); if (ply > 1) - historyScore += ctx->conthist.GetTwoPly(board, currMove, ctx, ply); + historyScore += ctx->conthist.GetNPly(board, currMove, ctx, ply, 2); } int margin = fpMargin * (depth + improving) + historyScore / 32; diff --git a/source/search.h b/source/search.h index 98ac16d..7d84250 100644 --- a/source/search.h +++ b/source/search.h @@ -96,8 +96,7 @@ public: std::fill(&contHistMoves[0][0][0][0][0][0], &contHistMoves[0][0][0][0][0][0] + sizeof(contHistMoves) / sizeof(int16_t), 0); } - int16_t GetOnePly(Board& board, Move& move, SearchContext* ctx, int ply); - int16_t GetTwoPly(Board& board, Move& move, SearchContext* ctx, int ply); + int16_t GetNPly(Board& board, Move& move, SearchContext* ctx, int ply, int n); auto& operator[](int index) { return contHistMoves[index];