Capthist #132
No files matched your search
+36
-3
@@ -60,7 +60,9 @@ static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) {
|
|||||||
targetType = Pawn;
|
targetType = Pawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 50000 * ((SEE(board, move, seeOrderingThreshold))) + (100 * targetType - attackerType + 105);
|
const int capthistScore = ctx->capthist[board.sideToMove][attackerType][targetType][move.MoveTo()];
|
||||||
|
|
||||||
|
return 50000 * ((SEE(board, move, seeOrderingThreshold))) + (100 * targetType - attackerType + 105) + capthistScore;
|
||||||
} else {
|
} else {
|
||||||
if (ctx->killerMoves[0][ply] == move) {
|
if (ctx->killerMoves[0][ply] == move) {
|
||||||
return 41000;
|
return 41000;
|
||||||
@@ -535,7 +537,9 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
|||||||
|
|
||||||
int moveSeen = 0;
|
int moveSeen = 0;
|
||||||
std::array<Move, MAX_MOVES> seenQuiets;
|
std::array<Move, MAX_MOVES> seenQuiets;
|
||||||
|
std::array<Move, MAX_MOVES> seenCaptures;
|
||||||
int seenQuietsCount = 0;
|
int seenQuietsCount = 0;
|
||||||
|
int seenCapturesCount = 0;
|
||||||
|
|
||||||
// For all moves
|
// For all moves
|
||||||
for (int i = 0; i < board.currentMoveIndex; i++) {
|
for (int i = 0; i < board.currentMoveIndex; i++) {
|
||||||
@@ -690,16 +694,19 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
|||||||
if (currMove != 0 && currMove.IsQuiet()) {
|
if (currMove != 0 && currMove.IsQuiet()) {
|
||||||
seenQuiets[seenQuietsCount] = currMove;
|
seenQuiets[seenQuietsCount] = currMove;
|
||||||
seenQuietsCount++;
|
seenQuietsCount++;
|
||||||
|
} else if (currMove != 0 && currMove.IsCapture()) {
|
||||||
|
seenCaptures[seenCapturesCount] = currMove;
|
||||||
|
seenCapturesCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fail high (beta cutoff)
|
// Fail high (beta cutoff)
|
||||||
if (score >= beta) {
|
if (score >= beta) {
|
||||||
|
int bonus = historyBonusMultiplier * depth - historyBonusSub;
|
||||||
|
|
||||||
if (!currMove.IsCapture()) {
|
if (!currMove.IsCapture()) {
|
||||||
ctx->killerMoves[1][ply] = ctx->killerMoves[0][ply];
|
ctx->killerMoves[1][ply] = ctx->killerMoves[0][ply];
|
||||||
ctx->killerMoves[0][ply] = currMove;
|
ctx->killerMoves[0][ply] = currMove;
|
||||||
|
|
||||||
int bonus = historyBonusMultiplier * depth - historyBonusSub;
|
|
||||||
|
|
||||||
ctx->history.Update(board.sideToMove, currMove, sourceThreatened, targetThreatened, bonus);
|
ctx->history.Update(board.sideToMove, currMove, sourceThreatened, targetThreatened, bonus);
|
||||||
|
|
||||||
if (ply > 0) {
|
if (ply > 0) {
|
||||||
@@ -745,6 +752,32 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
|||||||
|
|
||||||
ctx->history.Update(board.sideToMove, seenQuiets[moveIndex], sourceThreatened, targetThreatened, -bonus);
|
ctx->history.Update(board.sideToMove, seenQuiets[moveIndex], sourceThreatened, targetThreatened, -bonus);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
int movingPiece = board.GetPieceType(currMove.MoveFrom());
|
||||||
|
int capturedPiece = board.GetPieceType(currMove.MoveTo());
|
||||||
|
|
||||||
|
if (currMove.GetFlags() == epCapture) {
|
||||||
|
capturedPiece = Pawn;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->capthist.Update(board.sideToMove, movingPiece, capturedPiece, currMove.MoveTo(), bonus);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Capthist malus
|
||||||
|
for (int moveIndex = 0; moveIndex < seenCapturesCount - currMove.IsCapture(); moveIndex++) {
|
||||||
|
int movingPiece = board.GetPieceType(seenCaptures[moveIndex].MoveFrom());
|
||||||
|
int capturedPiece = board.GetPieceType(seenCaptures[moveIndex].MoveTo());
|
||||||
|
|
||||||
|
if (seenCaptures[moveIndex].GetFlags() == epCapture) {
|
||||||
|
capturedPiece = Pawn;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (movingPiece == nullPieceType || capturedPiece == nullPieceType) {
|
||||||
|
std::cout << "asd\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->capthist.Update(board.sideToMove, movingPiece, capturedPiece,
|
||||||
|
seenCaptures[moveIndex].MoveTo(), -bonus);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ctx->excluded)
|
if (!ctx->excluded)
|
||||||
|
|||||||
@@ -49,6 +49,26 @@ constexpr std::array<int, 6> SEEPieceValues = {
|
|||||||
void InitLMRTable();
|
void InitLMRTable();
|
||||||
class SearchContext;
|
class SearchContext;
|
||||||
|
|
||||||
|
class CaptHistory {
|
||||||
|
private:
|
||||||
|
// indexed by [stm][moving pt][capture pt][to]
|
||||||
|
MultiArray<int, 2, 6, 6, 64> historyMoves;
|
||||||
|
public:
|
||||||
|
void Update(bool stm, int moving, int capture, int to, int bonus) {
|
||||||
|
int clampedBonus = std::clamp(bonus, -MAX_HISTORY, MAX_HISTORY);
|
||||||
|
historyMoves[stm][moving][capture][to] +=
|
||||||
|
clampedBonus - historyMoves[stm][moving][capture][to] * std::abs(clampedBonus) / MAX_HISTORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clear() {
|
||||||
|
std::fill(&historyMoves[0][0][0][0], &historyMoves[0][0][0][0] + sizeof(historyMoves) / sizeof(int), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& operator[](int index) {
|
||||||
|
return historyMoves[index];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class CorrHist {
|
class CorrHist {
|
||||||
private:
|
private:
|
||||||
// indexed by [stm][key]
|
// indexed by [stm][key]
|
||||||
@@ -204,6 +224,7 @@ public:
|
|||||||
History history;
|
History history;
|
||||||
ContHistory conthist;
|
ContHistory conthist;
|
||||||
CorrHist corrhist;
|
CorrHist corrhist;
|
||||||
|
CaptHistory capthist;
|
||||||
|
|
||||||
std::array<std::array<int, MAX_DEPTH>, 2> killerMoves{};
|
std::array<std::array<int, MAX_DEPTH>, 2> killerMoves{};
|
||||||
|
|
||||||
@@ -220,6 +241,7 @@ public:
|
|||||||
history.Clear();
|
history.Clear();
|
||||||
conthist.Clear();
|
conthist.Clear();
|
||||||
corrhist.Clear();
|
corrhist.Clear();
|
||||||
|
capthist.Clear();
|
||||||
TT.Clear();
|
TT.Clear();
|
||||||
sw.Restart();
|
sw.Restart();
|
||||||
killerMoves = {};
|
killerMoves = {};
|
||||||
|
|||||||
Reference in new issue
Block a user