Merge pull request #111 from rektdie/threats-hist

Threats hist bench 6448969
This commit was merged in pull request #111.
This commit is contained in:
rektdie authored and GitHub committed 2025-09-17 01:34:44 +02:00
commit e7d8044745
4 files changed
+29 -10

No files matched your search

+4
View File
@@ -553,3 +553,7 @@ Bitboard Board::AttacksTo(int square, Bitboard occupancy) {
return attacks;
}
bool Board::IsSquareThreatened(bool side, int square) {
return colorThreats[!side].IsSet(square);
}
+2
View File
@@ -70,4 +70,6 @@ public:
bool InPossibleZug();
Bitboard AttacksTo(int square, Bitboard occupancy);
bool IsSquareThreatened(bool side, int square);
};
+17 -5
View File
@@ -70,7 +70,10 @@ static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) {
} else if (ctx->killerMoves[1][ply] == move) {
return 40000;
} else {
int historyScore = ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()];
bool sourceThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveFrom());
bool targetThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveTo());
int historyScore = ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()][sourceThreatened][targetThreatened];
int conthistScore = 0;
if (ply > 0) {
@@ -169,8 +172,11 @@ static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int
if (!improving)
reduction += lmrImproving;
bool sourceThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveFrom());
bool targetThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveTo());
// History LMR
int historyReduction = ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()];
int historyReduction = ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()][sourceThreatened][targetThreatened];
if (ply > 0) {
historyReduction += ctx->conthist.GetOnePly(board, move, ctx, ply);
@@ -479,10 +485,13 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
}
}
bool sourceThreatened = board.IsSquareThreatened(board.sideToMove, currMove.MoveFrom());
bool targetThreatened = board.IsSquareThreatened(board.sideToMove, currMove.MoveTo());
// Futility pruning
// If our static eval is far below alpha, there is only a small chance
// that a quiet move will help us so we skip them
int historyScore = ctx->history[board.sideToMove][currMove.MoveFrom()][currMove.MoveTo()];
int historyScore = ctx->history[board.sideToMove][currMove.MoveFrom()][currMove.MoveTo()][sourceThreatened][targetThreatened];
if (ply > 0) {
historyScore += ctx->conthist.GetOnePly(board, currMove, ctx, ply);
@@ -615,7 +624,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
int bonus = historyBonusMultiplier * depth - historyBonusSub;
ctx->history.Update(board.sideToMove, currMove, bonus);
ctx->history.Update(board.sideToMove, currMove, sourceThreatened, targetThreatened, bonus);
if (ply > 0) {
int prevType = ctx->ss[ply-1].pieceType;
@@ -655,7 +664,10 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
// Malus
for (int moveIndex = 0; moveIndex < seenQuietsCount - 1; moveIndex++) {
ctx->history.Update(board.sideToMove, seenQuiets[moveIndex], -bonus);
sourceThreatened = board.IsSquareThreatened(board.sideToMove, seenQuiets[moveIndex].MoveFrom());
targetThreatened = board.IsSquareThreatened(board.sideToMove, seenQuiets[moveIndex].MoveTo());
ctx->history.Update(board.sideToMove, seenQuiets[moveIndex], sourceThreatened, targetThreatened, -bonus);
}
}
+6 -5
View File
@@ -104,16 +104,17 @@ public:
class History {
private:
MultiArray<int, 2, 64, 64> historyMoves;
// indexed by [stm][from][to][threatenedSource][threatenedTarget]
MultiArray<int, 2, 64, 64, 2, 2> historyMoves;
public:
void Update(bool stm, Move move, int bonus) {
void Update(bool stm, Move move, bool source, bool target, int bonus) {
int clampedBonus = std::clamp(bonus, -MAX_HISTORY, MAX_HISTORY);
historyMoves[stm][move.MoveFrom()][move.MoveTo()] +=
clampedBonus - historyMoves[stm][move.MoveFrom()][move.MoveTo()] * std::abs(clampedBonus) / MAX_HISTORY;
historyMoves[stm][move.MoveFrom()][move.MoveTo()][source][target] +=
clampedBonus - historyMoves[stm][move.MoveFrom()][move.MoveTo()][source][target] * std::abs(clampedBonus) / MAX_HISTORY;
}
void Clear() {
std::fill(&historyMoves[0][0][0], &historyMoves[0][0][0] + sizeof(historyMoves) / sizeof(int), 0);
std::fill(&historyMoves[0][0][0][0][0], &historyMoves[0][0][0][0][0] + sizeof(historyMoves) / sizeof(int), 0);
}
auto& operator[](int index) {