Skip to content

Commit 2e96c51

Browse files
VoyagerOnesnicolet
authored andcommitted
Introduce separate counter-move tables for captures
Enhance counter-move history table by adding a capture/no-capture dimension, depending wether the previous move was a quiet move or a capture. This doubles the size of the table but provides more accurate move ordering. STC: LLR: 2.95 (-2.94,2.94) [0.50,4.50] Total: 79702 W: 17720 L: 17164 D: 44818 http://tests.stockfishchess.org/tests/view/5d97945e0ebc590c21aa724b LTC: LLR: 2.96 (-2.94,2.94) [0.00,3.50] Total: 29147 W: 4907 L: 4651 D: 19589 http://tests.stockfishchess.org/tests/view/5d97ccb90ebc590c21aa7bc0 Closes #2344 Bench: 4131643
1 parent ca7d4e9 commit 2e96c51

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

src/movepick.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ void MovePicker::score() {
111111
+ (*captureHistory)[pos.moved_piece(m)][to_sq(m)][type_of(pos.piece_on(to_sq(m)))];
112112

113113
else if (Type == QUIETS)
114-
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
115-
+ (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
116-
+ (*continuationHistory[1])[pos.moved_piece(m)][to_sq(m)]
117-
+ (*continuationHistory[3])[pos.moved_piece(m)][to_sq(m)]
118-
+ (*continuationHistory[5])[pos.moved_piece(m)][to_sq(m)] / 2;
114+
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
115+
+ 2 * (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
116+
+ 2 * (*continuationHistory[1])[pos.moved_piece(m)][to_sq(m)]
117+
+ 2 * (*continuationHistory[3])[pos.moved_piece(m)][to_sq(m)]
118+
+ (*continuationHistory[5])[pos.moved_piece(m)][to_sq(m)];
119119

120120
else // Type == EVASIONS
121121
{
@@ -206,7 +206,7 @@ Move MovePicker::next_move(bool skipQuiets) {
206206
endMoves = generate<QUIETS>(pos, cur);
207207

208208
score<QUIETS>();
209-
partial_insertion_sort(cur, endMoves, -4000 * depth);
209+
partial_insertion_sort(cur, endMoves, -3000 * depth);
210210
}
211211

212212
++stage;

src/movepick.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct Stats<T, D, Size> : public std::array<StatsEntry<T, D>, Size> {};
8080

8181
/// In stats table, D=0 means that the template parameter is not used
8282
enum StatsParams { NOT_USED = 0 };
83-
83+
enum StatsType { NoCaptures, Captures };
8484

8585
/// ButterflyHistory records how often quiet moves have been successful or
8686
/// unsuccessful during the current search, and is used for reduction and move

src/search.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ void Thread::search() {
334334

335335
std::memset(ss-7, 0, 10 * sizeof(Stack));
336336
for (int i = 7; i > 0; i--)
337-
(ss-i)->continuationHistory = &this->continuationHistory[NO_PIECE][0]; // Use as sentinel
337+
(ss-i)->continuationHistory = &this->continuationHistory[0][NO_PIECE][0]; // Use as a sentinel
338+
338339
ss->pv = pv;
339340

340341
bestValue = delta = alpha = -VALUE_INFINITE;
@@ -595,12 +596,13 @@ namespace {
595596
Value bestValue, value, ttValue, eval, maxValue;
596597
bool ttHit, ttPv, inCheck, givesCheck, improving, doLMR;
597598
bool captureOrPromotion, doFullDepthSearch, moveCountPruning, ttCapture;
598-
Piece movedPiece;
599+
Piece movedPiece, priorCapture;
599600
int moveCount, captureCount, quietCount, singularLMR;
600601

601602
// Step 1. Initialize node
602603
Thread* thisThread = pos.this_thread();
603604
inCheck = pos.checkers();
605+
priorCapture = pos.captured_piece();
604606
Color us = pos.side_to_move();
605607
moveCount = captureCount = quietCount = singularLMR = ss->moveCount = 0;
606608
bestValue = -VALUE_INFINITE;
@@ -680,7 +682,7 @@ namespace {
680682
update_quiet_stats(pos, ss, ttMove, nullptr, 0, stat_bonus(depth));
681683

682684
// Extra penalty for early quiet moves of the previous ply
683-
if ((ss-1)->moveCount <= 2 && !pos.captured_piece())
685+
if ((ss-1)->moveCount <= 2 && !priorCapture)
684686
update_continuation_histories(ss-1, pos.piece_on(prevSq), prevSq, -stat_bonus(depth + 1));
685687
}
686688
// Penalty for a quiet ttMove that fails low
@@ -814,7 +816,7 @@ namespace {
814816
Depth R = (835 + 70 * depth) / 256 + std::min(int(eval - beta) / 185, 3);
815817

816818
ss->currentMove = MOVE_NULL;
817-
ss->continuationHistory = &thisThread->continuationHistory[NO_PIECE][0];
819+
ss->continuationHistory = &thisThread->continuationHistory[0][NO_PIECE][0];
818820

819821
pos.do_null_move(st);
820822

@@ -865,7 +867,7 @@ namespace {
865867
probCutCount++;
866868

867869
ss->currentMove = move;
868-
ss->continuationHistory = &thisThread->continuationHistory[pos.moved_piece(move)][to_sq(move)];
870+
ss->continuationHistory = &thisThread->continuationHistory[!!priorCapture][pos.moved_piece(move)][to_sq(move)];
869871

870872
assert(depth >= 5);
871873

@@ -1066,7 +1068,7 @@ namespace {
10661068

10671069
// Update the current move (this must be done after singular extension search)
10681070
ss->currentMove = move;
1069-
ss->continuationHistory = &thisThread->continuationHistory[movedPiece][to_sq(move)];
1071+
ss->continuationHistory = &thisThread->continuationHistory[!!priorCapture][movedPiece][to_sq(move)];
10701072

10711073
// Step 15. Make the move
10721074
pos.do_move(move, st, givesCheck);
@@ -1279,13 +1281,13 @@ namespace {
12791281

12801282
// Extra penalty for a quiet TT or main killer move in previous ply when it gets refuted
12811283
if ( ((ss-1)->moveCount == 1 || ((ss-1)->currentMove == (ss-1)->killers[0]))
1282-
&& !pos.captured_piece())
1284+
&& !priorCapture)
12831285
update_continuation_histories(ss-1, pos.piece_on(prevSq), prevSq, -stat_bonus(depth + 1));
12841286

12851287
}
12861288
// Bonus for prior countermove that caused the fail low
12871289
else if ( (depth >= 3 || PvNode)
1288-
&& !pos.captured_piece())
1290+
&& !priorCapture)
12891291
update_continuation_histories(ss-1, pos.piece_on(prevSq), prevSq, stat_bonus(depth));
12901292

12911293
if (PvNode)
@@ -1321,6 +1323,7 @@ namespace {
13211323
Move ttMove, move, bestMove;
13221324
Depth ttDepth;
13231325
Value bestValue, value, ttValue, futilityValue, futilityBase, oldAlpha;
1326+
Piece priorCapture;
13241327
bool ttHit, pvHit, inCheck, givesCheck, evasionPrunable;
13251328
int moveCount;
13261329

@@ -1335,6 +1338,7 @@ namespace {
13351338
(ss+1)->ply = ss->ply + 1;
13361339
bestMove = MOVE_NONE;
13371340
inCheck = pos.checkers();
1341+
priorCapture = pos.captured_piece();
13381342
moveCount = 0;
13391343

13401344
// Check for an immediate draw or maximum ply reached
@@ -1472,7 +1476,7 @@ namespace {
14721476
}
14731477

14741478
ss->currentMove = move;
1475-
ss->continuationHistory = &thisThread->continuationHistory[pos.moved_piece(move)][to_sq(move)];
1479+
ss->continuationHistory = &thisThread->continuationHistory[!!priorCapture][pos.moved_piece(move)][to_sq(move)];
14761480

14771481
// Make and search the move
14781482
pos.do_move(move, st, givesCheck);

src/thread.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ void Thread::clear() {
7070
mainHistory.fill(0);
7171
captureHistory.fill(0);
7272

73-
for (auto& to : continuationHistory)
74-
for (auto& h : to)
75-
h->fill(0);
73+
for (StatsType c : { NoCaptures, Captures })
74+
for (auto& to : continuationHistory[c])
75+
for (auto& h : to)
76+
h->fill(0);
7677

77-
continuationHistory[NO_PIECE][0]->fill(Search::CounterMovePruneThreshold - 1);
78+
for (StatsType c : { NoCaptures, Captures })
79+
continuationHistory[c][NO_PIECE][0]->fill(Search::CounterMovePruneThreshold - 1);
7880
}
7981

8082
/// Thread::start_searching() wakes up the thread that will start the search

src/thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Thread {
7171
CounterMoveHistory counterMoves;
7272
ButterflyHistory mainHistory;
7373
CapturePieceToHistory captureHistory;
74-
ContinuationHistory continuationHistory;
74+
ContinuationHistory continuationHistory[2];
7575
Score contempt;
7676
};
7777

0 commit comments

Comments
 (0)