added 1-ply conthist without malus | bench 3298447
This commit is contained in:
1 parent
64a85bf780
commit
84f2fd0ea8
3 files changed
+57
-5
No files matched your search
+30
-5
@@ -25,7 +25,7 @@ void InitLMRTable() {
|
|||||||
static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) {
|
static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) {
|
||||||
TTEntry *current = ctx->TT.GetRawEntry(board.hashKey);
|
TTEntry *current = ctx->TT.GetRawEntry(board.hashKey);
|
||||||
if (current->hashKey == board.hashKey && current->bestMove == move) {
|
if (current->hashKey == board.hashKey && current->bestMove == move) {
|
||||||
return 50000;
|
return 100000;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (move.IsCapture()) {
|
if (move.IsCapture()) {
|
||||||
@@ -36,15 +36,23 @@ static int ScoreMove(Board &board, Move &move, int ply, SearchContext* ctx) {
|
|||||||
targetType = Pawn;
|
targetType = Pawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 30000 * ((SEE(board, move, -100))) + moveScoreTable[attackerType][targetType];
|
return 60000 * ((SEE(board, move, -100))) + moveScoreTable[attackerType][targetType];
|
||||||
} else {
|
} else {
|
||||||
if (ctx->killerMoves[0][ply] == move) {
|
if (ctx->killerMoves[0][ply] == move) {
|
||||||
return 20000;
|
return 40000;
|
||||||
} else if (ctx->killerMoves[1][ply] == move) {
|
} else if (ctx->killerMoves[1][ply] == move) {
|
||||||
return 18000;
|
return 36000;
|
||||||
} else {
|
} else {
|
||||||
// Max 16384
|
// Max 16384
|
||||||
return ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()];
|
int historyScore = ctx->history[board.sideToMove][move.MoveFrom()][move.MoveTo()];
|
||||||
|
int conthistScore = 0;
|
||||||
|
|
||||||
|
if (ply > 0) {
|
||||||
|
conthistScore = ctx->conthist[board.sideToMove][ctx->ss[ply-1].pieceType]
|
||||||
|
[ctx->ss[ply-1].moveTo][ctx->ss[ply].pieceType][ctx->ss[ply].moveTo];
|
||||||
|
}
|
||||||
|
|
||||||
|
return historyScore + conthistScore;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,6 +266,9 @@ static SearchResults Quiescence(Board& board, int alpha, int beta, int ply, Sear
|
|||||||
int isLegal = copy.MakeMove(board.moveList[i]);
|
int isLegal = copy.MakeMove(board.moveList[i]);
|
||||||
if (!isLegal) continue;
|
if (!isLegal) continue;
|
||||||
|
|
||||||
|
ctx->ss[ply].pieceType = board.GetPieceType(board.moveList[i].MoveFrom());
|
||||||
|
ctx->ss[ply].moveTo = board.moveList[i].MoveTo();
|
||||||
|
|
||||||
if (!SEE(board, board.moveList[i], 0))
|
if (!SEE(board, board.moveList[i], 0))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -413,6 +424,10 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
|||||||
bool isLegal = copy.MakeMove(currMove);
|
bool isLegal = copy.MakeMove(currMove);
|
||||||
|
|
||||||
if (!isLegal) continue;
|
if (!isLegal) continue;
|
||||||
|
|
||||||
|
ctx->ss[ply].pieceType = board.GetPieceType(currMove.MoveFrom());
|
||||||
|
ctx->ss[ply].moveTo = currMove.MoveTo();
|
||||||
|
|
||||||
if (copy.positionIndex >= ctx->positionHistory.size()) {
|
if (copy.positionIndex >= ctx->positionHistory.size()) {
|
||||||
ctx->positionHistory.resize(copy.positionIndex + 100);
|
ctx->positionHistory.resize(copy.positionIndex + 100);
|
||||||
}
|
}
|
||||||
@@ -475,6 +490,16 @@ SearchResults PVS(Board& board, int depth, int alpha, int beta, int ply, SearchC
|
|||||||
|
|
||||||
ctx->history.Update(board.sideToMove, currMove, bonus);
|
ctx->history.Update(board.sideToMove, currMove, bonus);
|
||||||
|
|
||||||
|
if (ply > 0) {
|
||||||
|
int prevType = ctx->ss[ply-1].pieceType;
|
||||||
|
int prevTo = ctx->ss[ply-1].moveTo;
|
||||||
|
int pieceType = ctx->ss[ply].pieceType;
|
||||||
|
int to = ctx->ss[ply].moveTo;
|
||||||
|
|
||||||
|
ctx->conthist.Update(board.sideToMove, prevType, prevTo, pieceType, to, bonus);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 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);
|
ctx->history.Update(board.sideToMove, seenQuiets[moveIndex], -bonus);
|
||||||
|
|||||||
@@ -34,6 +34,27 @@ constexpr std::array<int, 6> SEEPieceValues = {
|
|||||||
|
|
||||||
void InitLMRTable();
|
void InitLMRTable();
|
||||||
|
|
||||||
|
class ContHistory {
|
||||||
|
private:
|
||||||
|
// indexed by [stm][prev move piece][prev move to][piece][to]
|
||||||
|
MultiArray<int16_t, 2, 6, 64, 6, 64> contHistMoves;
|
||||||
|
public:
|
||||||
|
void Update(bool stm, int prevType, int prevTo, int type, int to, int bonus) {
|
||||||
|
int clampedBonus = std::clamp(bonus, -MAX_HISTORY, MAX_HISTORY);
|
||||||
|
|
||||||
|
contHistMoves[stm][prevType][prevTo][type][to] +=
|
||||||
|
clampedBonus - contHistMoves[stm][prevType][prevTo][type][to] * std::abs(clampedBonus) / MAX_HISTORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clear() {
|
||||||
|
std::fill(&contHistMoves[0][0][0][0][0], &contHistMoves[0][0][0][0][0] + sizeof(contHistMoves) / sizeof(int16_t), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& operator[](int index) {
|
||||||
|
return contHistMoves[index];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class History {
|
class History {
|
||||||
private:
|
private:
|
||||||
MultiArray<int, 2, 64, 64> historyMoves;
|
MultiArray<int, 2, 64, 64> historyMoves;
|
||||||
@@ -88,6 +109,9 @@ public:
|
|||||||
class Stack {
|
class Stack {
|
||||||
public:
|
public:
|
||||||
int32_t eval = ScoreNone;
|
int32_t eval = ScoreNone;
|
||||||
|
|
||||||
|
int pieceType = -1;
|
||||||
|
int moveTo = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SearchContext {
|
class SearchContext {
|
||||||
@@ -103,6 +127,7 @@ public:
|
|||||||
|
|
||||||
PVLine pvLine;
|
PVLine pvLine;
|
||||||
History history;
|
History history;
|
||||||
|
ContHistory conthist;
|
||||||
|
|
||||||
std::array<std::array<int, MAX_PLY>, 2> killerMoves{};
|
std::array<std::array<int, MAX_PLY>, 2> killerMoves{};
|
||||||
|
|
||||||
@@ -117,6 +142,7 @@ public:
|
|||||||
SearchContext(){
|
SearchContext(){
|
||||||
pvLine.Clear();
|
pvLine.Clear();
|
||||||
history.Clear();
|
history.Clear();
|
||||||
|
conthist.Clear();
|
||||||
TT.Clear();
|
TT.Clear();
|
||||||
sw.Restart();
|
sw.Restart();
|
||||||
killerMoves = {};
|
killerMoves = {};
|
||||||
|
|||||||
@@ -139,6 +139,7 @@ void UCILoop(Board &board) {
|
|||||||
|
|
||||||
ctx->killerMoves = {};
|
ctx->killerMoves = {};
|
||||||
ctx->history.Clear();
|
ctx->history.Clear();
|
||||||
|
ctx->conthist.Clear();
|
||||||
ctx->positionHistory = {};
|
ctx->positionHistory = {};
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in new issue
Block a user