fixed threats hist? | bench 6448969
This commit is contained in:
1 parent
1dd0e33d2b
commit
10a0f502ae
3 files changed
+18
-41
No files matched your search
+16
-17
@@ -70,14 +70,11 @@ static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) {
|
|||||||
} else if (ctx->killerMoves[1][ply] == move) {
|
} else if (ctx->killerMoves[1][ply] == move) {
|
||||||
return 40000;
|
return 40000;
|
||||||
} else {
|
} else {
|
||||||
int historyScore = ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()];
|
|
||||||
int conthistScore = 0;
|
|
||||||
|
|
||||||
bool sourceThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveFrom());
|
bool sourceThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveFrom());
|
||||||
bool targetThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveFrom());
|
bool targetThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveTo());
|
||||||
|
|
||||||
int threatsScore =
|
int historyScore = ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()][sourceThreatened][targetThreatened];
|
||||||
ctx->threatsHist[board.sideToMove][move.MoveFrom()][move.MoveTo()][sourceThreatened][targetThreatened];
|
int conthistScore = 0;
|
||||||
|
|
||||||
if (ply > 0) {
|
if (ply > 0) {
|
||||||
conthistScore = ctx->conthist.GetOnePly(board, move, ctx, ply);
|
conthistScore = ctx->conthist.GetOnePly(board, move, ctx, ply);
|
||||||
@@ -88,7 +85,7 @@ static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
return 20000 + historyScore + conthistScore + threatsScore;
|
return 20000 + historyScore + conthistScore;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,8 +172,11 @@ static int GetReductions(Board &board, Move &move, int depth, int moveSeen, int
|
|||||||
if (!improving)
|
if (!improving)
|
||||||
reduction += lmrImproving;
|
reduction += lmrImproving;
|
||||||
|
|
||||||
|
bool sourceThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveFrom());
|
||||||
|
bool targetThreatened = board.IsSquareThreatened(board.sideToMove, move.MoveTo());
|
||||||
|
|
||||||
// History LMR
|
// 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) {
|
if (ply > 0) {
|
||||||
historyReduction += ctx->conthist.GetOnePly(board, move, ctx, ply);
|
historyReduction += ctx->conthist.GetOnePly(board, move, ctx, ply);
|
||||||
|
|
||||||
@@ -485,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
|
// Futility pruning
|
||||||
// If our static eval is far below alpha, there is only a small chance
|
// 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
|
// 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) {
|
if (ply > 0) {
|
||||||
historyScore += ctx->conthist.GetOnePly(board, currMove, ctx, ply);
|
historyScore += ctx->conthist.GetOnePly(board, currMove, ctx, ply);
|
||||||
@@ -621,10 +624,7 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
|||||||
|
|
||||||
int bonus = historyBonusMultiplier * depth - historyBonusSub;
|
int bonus = historyBonusMultiplier * depth - historyBonusSub;
|
||||||
|
|
||||||
ctx->history.Update(board.sideToMove, currMove, bonus);
|
ctx->history.Update(board.sideToMove, currMove, sourceThreatened, targetThreatened, bonus);
|
||||||
ctx->threatsHist.Update(board.sideToMove, currMove,
|
|
||||||
board.IsSquareThreatened(board.sideToMove, currMove.MoveFrom()),
|
|
||||||
board.IsSquareThreatened(board.sideToMove, currMove.MoveTo()), bonus);
|
|
||||||
|
|
||||||
if (ply > 0) {
|
if (ply > 0) {
|
||||||
int prevType = ctx->ss[ply-1].pieceType;
|
int prevType = ctx->ss[ply-1].pieceType;
|
||||||
@@ -664,11 +664,10 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
|||||||
|
|
||||||
// Malus
|
// Malus
|
||||||
for (int moveIndex = 0; moveIndex < seenQuietsCount - 1; moveIndex++) {
|
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->threatsHist.Update(board.sideToMove, currMove,
|
ctx->history.Update(board.sideToMove, seenQuiets[moveIndex], sourceThreatened, targetThreatened, -bonus);
|
||||||
board.IsSquareThreatened(board.sideToMove, currMove.MoveFrom()),
|
|
||||||
board.IsSquareThreatened(board.sideToMove, currMove.MoveTo()), bonus);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-23
@@ -102,9 +102,9 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ThreatsHistory {
|
class History {
|
||||||
private:
|
private:
|
||||||
// indexed by [stm][from][to][threatSource][threatTarget]
|
// indexed by [stm][from][to][threatenedSource][threatenedTarget]
|
||||||
MultiArray<int, 2, 64, 64, 2, 2> historyMoves;
|
MultiArray<int, 2, 64, 64, 2, 2> historyMoves;
|
||||||
public:
|
public:
|
||||||
void Update(bool stm, Move move, bool source, bool target, int bonus) {
|
void Update(bool stm, Move move, bool source, bool target, int bonus) {
|
||||||
@@ -122,25 +122,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class History {
|
|
||||||
private:
|
|
||||||
MultiArray<int, 2, 64, 64> historyMoves;
|
|
||||||
public:
|
|
||||||
void Update(bool stm, Move move, 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Clear() {
|
|
||||||
std::fill(&historyMoves[0][0][0], &historyMoves[0][0][0] + sizeof(historyMoves) / sizeof(int), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& operator[](int index) {
|
|
||||||
return historyMoves[index];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class PVLine {
|
class PVLine {
|
||||||
private:
|
private:
|
||||||
int length[MAX_PLY] = {};
|
int length[MAX_PLY] = {};
|
||||||
@@ -199,7 +180,6 @@ public:
|
|||||||
|
|
||||||
PVLine pvLine;
|
PVLine pvLine;
|
||||||
History history;
|
History history;
|
||||||
ThreatsHistory threatsHist;
|
|
||||||
ContHistory conthist;
|
ContHistory conthist;
|
||||||
CorrHist corrhist;
|
CorrHist corrhist;
|
||||||
|
|
||||||
@@ -216,7 +196,6 @@ public:
|
|||||||
SearchContext(){
|
SearchContext(){
|
||||||
pvLine.Clear();
|
pvLine.Clear();
|
||||||
history.Clear();
|
history.Clear();
|
||||||
threatsHist.Clear();
|
|
||||||
conthist.Clear();
|
conthist.Clear();
|
||||||
corrhist.Clear();
|
corrhist.Clear();
|
||||||
TT.Clear();
|
TT.Clear();
|
||||||
|
|||||||
@@ -249,7 +249,6 @@ void UCILoop(Board &board) {
|
|||||||
|
|
||||||
ctx->killerMoves = {};
|
ctx->killerMoves = {};
|
||||||
ctx->history.Clear();
|
ctx->history.Clear();
|
||||||
ctx->threatsHist.Clear();
|
|
||||||
ctx->conthist.Clear();
|
ctx->conthist.Clear();
|
||||||
ctx->corrhist.Clear();
|
ctx->corrhist.Clear();
|
||||||
ctx->positionHistory = {};
|
ctx->positionHistory = {};
|
||||||
|
|||||||
Reference in new issue
Block a user