2 ply conthist #85

Merged
rektdie merged 5 commits from 2-ply-conthist into main 2025-08-05 02:57:49 +02:00
2 changed files with 10 additions and 5 deletions
Showing only changes of commit b74f6f4cbb - Show all commits

No files matched your search

+8 -4
View File
@@ -22,11 +22,12 @@ void InitLMRTable() {
} }
} }
int16_t ContHistory::GetOnePly(Board& board, Move& move, bool otherColor, SearchContext* ctx, int ply) { int16_t ContHistory::GetOnePly(Board& board, Move& move, SearchContext* ctx, int ply) {
int prevType = ctx->ss[ply-1].pieceType; int prevType = ctx->ss[ply-1].pieceType;
int prevTo = ctx->ss[ply-1].moveTo; int prevTo = ctx->ss[ply-1].moveTo;
int pieceType = board.GetPieceType(move.MoveFrom()); int pieceType = board.GetPieceType(move.MoveFrom());
int to = move.MoveTo(); int to = move.MoveTo();
bool otherColor = ctx->ss[ply-1].side;
return ctx->conthist[otherColor][prevType][prevTo][board.sideToMove][pieceType][to]; return ctx->conthist[otherColor][prevType][prevTo][board.sideToMove][pieceType][to];
} }
@@ -56,7 +57,7 @@ static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) {
int conthistScore = 0; int conthistScore = 0;
if (ply > 0) { if (ply > 0) {
conthistScore = ctx->conthist.GetOnePly(board, move, !board.sideToMove, ctx, ply); conthistScore = ctx->conthist.GetOnePly(board, move, ctx, ply);
} }
return 20000 + historyScore + conthistScore; return 20000 + historyScore + conthistScore;
@@ -278,6 +279,7 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear
ctx->ss[ply].pieceType = board.GetPieceType(board.moveList[i].MoveFrom()); ctx->ss[ply].pieceType = board.GetPieceType(board.moveList[i].MoveFrom());
ctx->ss[ply].moveTo = board.moveList[i].MoveTo(); ctx->ss[ply].moveTo = board.moveList[i].MoveTo();
ctx->ss[ply].side = board.sideToMove;
if (!SEE(board, board.moveList[i], 0)) if (!SEE(board, board.moveList[i], 0))
continue; continue;
@@ -446,6 +448,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
ctx->ss[ply].pieceType = board.GetPieceType(currMove.MoveFrom()); ctx->ss[ply].pieceType = board.GetPieceType(currMove.MoveFrom());
ctx->ss[ply].moveTo = currMove.MoveTo(); ctx->ss[ply].moveTo = currMove.MoveTo();
ctx->ss[ply].side = board.sideToMove;
if (copy.positionIndex >= ctx->positionHistory.size()) { if (copy.positionIndex >= ctx->positionHistory.size()) {
ctx->positionHistory.resize(copy.positionIndex + 100); ctx->positionHistory.resize(copy.positionIndex + 100);
@@ -533,15 +536,16 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
int prevTo = ctx->ss[ply-1].moveTo; int prevTo = ctx->ss[ply-1].moveTo;
int pieceType = ctx->ss[ply].pieceType; int pieceType = ctx->ss[ply].pieceType;
int to = ctx->ss[ply].moveTo; int to = ctx->ss[ply].moveTo;
bool otherColor = ctx->ss[ply-1].side;
ctx->conthist.Update(board.sideToMove, !board.sideToMove, prevType, prevTo, pieceType, to, bonus); ctx->conthist.Update(board.sideToMove, otherColor, prevType, prevTo, pieceType, to, bonus);
// Malus // Malus
for (int moveIndex = 0; moveIndex < seenQuietsCount - 1; moveIndex++) { for (int moveIndex = 0; moveIndex < seenQuietsCount - 1; moveIndex++) {
pieceType = board.GetPieceType(seenQuiets[moveIndex].MoveFrom()); pieceType = board.GetPieceType(seenQuiets[moveIndex].MoveFrom());
to = seenQuiets[moveIndex].MoveTo(); to = seenQuiets[moveIndex].MoveTo();
ctx->conthist.Update(board.sideToMove, !board.sideToMove, prevType, prevTo, pieceType, to, -bonus); ctx->conthist.Update(board.sideToMove, otherColor, prevType, prevTo, pieceType, to, -bonus);
} }
} }
+2 -1
View File
@@ -51,7 +51,7 @@ public:
std::fill(&contHistMoves[0][0][0][0][0][0], &contHistMoves[0][0][0][0][0][0] + sizeof(contHistMoves) / sizeof(int16_t), 0); 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, bool otherColor, SearchContext* ctx, int ply); int16_t GetOnePly(Board& board, Move& move, SearchContext* ctx, int ply);
auto& operator[](int index) { auto& operator[](int index) {
return contHistMoves[index]; return contHistMoves[index];
@@ -115,6 +115,7 @@ public:
int pieceType = -1; int pieceType = -1;
int moveTo = -1; int moveTo = -1;
bool side = -1;
}; };
class SearchContext { class SearchContext {