Skip to content

Commit 12e79be

Browse files
locutus2snicolet
authored andcommitted
Better check evasion move sorting
Use in addition the counter move history table for sorting quiet check evasion moves in main and quiecence search. Also rename "contHistory" to "continuationHistory" while there. STC: LLR: 2.96 (-2.94,2.94) [0.00,5.00] Total: 73284 W: 16433 L: 15938 D: 40913 http://tests.stockfishchess.org/tests/view/5b4f526e0ebc5902bdb7a401 LTC: LLR: 2.96 (-2.94,2.94) [0.00,5.00] Total: 12135 W: 2171 L: 1997 D: 7967 http://tests.stockfishchess.org/tests/view/5b4fc0ef0ebc5902bdb7ae0e Closes #1685 Bench 4817583
1 parent 3913726 commit 12e79be

File tree

6 files changed

+30
-21
lines changed

6 files changed

+30
-21
lines changed

src/movepick.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace {
6161
/// MovePicker constructor for the main search
6262
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
6363
const CapturePieceToHistory* cph, const PieceToHistory** ch, Move cm, Move* killers)
64-
: pos(p), mainHistory(mh), captureHistory(cph), contHistory(ch),
64+
: pos(p), mainHistory(mh), captureHistory(cph), continuationHistory(ch),
6565
refutations{{killers[0], 0}, {killers[1], 0}, {cm, 0}}, depth(d) {
6666

6767
assert(d > DEPTH_ZERO);
@@ -73,8 +73,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHist
7373

7474
/// MovePicker constructor for quiescence search
7575
MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHistory* mh,
76-
const CapturePieceToHistory* cph, Square rs)
77-
: pos(p), mainHistory(mh), captureHistory(cph), recaptureSquare(rs), depth(d) {
76+
const CapturePieceToHistory* cph, const PieceToHistory** ch, Square rs)
77+
: pos(p), mainHistory(mh), captureHistory(cph), continuationHistory(ch), recaptureSquare(rs), depth(d) {
7878

7979
assert(d <= DEPTH_ZERO);
8080

@@ -115,17 +115,19 @@ void MovePicker::score() {
115115

116116
else if (Type == QUIETS)
117117
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
118-
+ (*contHistory[0])[pos.moved_piece(m)][to_sq(m)]
119-
+ (*contHistory[1])[pos.moved_piece(m)][to_sq(m)]
120-
+ (*contHistory[3])[pos.moved_piece(m)][to_sq(m)];
118+
+ (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
119+
+ (*continuationHistory[1])[pos.moved_piece(m)][to_sq(m)]
120+
+ (*continuationHistory[3])[pos.moved_piece(m)][to_sq(m)];
121121

122122
else // Type == EVASIONS
123123
{
124124
if (pos.capture(m))
125125
m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
126126
- Value(type_of(pos.moved_piece(m)));
127127
else
128-
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)] - (1 << 28);
128+
m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
129+
+ (*continuationHistory[0])[pos.moved_piece(m)][to_sq(m)]
130+
- (1 << 28);
129131
}
130132
}
131133

src/movepick.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class MovePicker {
119119
MovePicker(const Position&, Move, Value, const CapturePieceToHistory*);
120120
MovePicker(const Position&, Move, Depth, const ButterflyHistory*,
121121
const CapturePieceToHistory*,
122+
const PieceToHistory**,
122123
Square);
123124
MovePicker(const Position&, Move, Depth, const ButterflyHistory*,
124125
const CapturePieceToHistory*,
@@ -136,7 +137,7 @@ class MovePicker {
136137
const Position& pos;
137138
const ButterflyHistory* mainHistory;
138139
const CapturePieceToHistory* captureHistory;
139-
const PieceToHistory** contHistory;
140+
const PieceToHistory** continuationHistory;
140141
Move ttMove;
141142
ExtMove refutations[3], *cur, *endMoves, *endBadCaptures;
142143
int stage;

src/search.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ void Thread::search() {
290290

291291
std::memset(ss-4, 0, 7 * sizeof(Stack));
292292
for (int i = 4; i > 0; i--)
293-
(ss-i)->contHistory = this->contHistory[NO_PIECE][0].get(); // Use as sentinel
293+
(ss-i)->continuationHistory = this->continuationHistory[NO_PIECE][0].get(); // Use as sentinel
294294

295295
bestValue = delta = alpha = -VALUE_INFINITE;
296296
beta = VALUE_INFINITE;
@@ -587,7 +587,7 @@ namespace {
587587

588588
(ss+1)->ply = ss->ply + 1;
589589
ss->currentMove = (ss+1)->excludedMove = bestMove = MOVE_NONE;
590-
ss->contHistory = thisThread->contHistory[NO_PIECE][0].get();
590+
ss->continuationHistory = thisThread->continuationHistory[NO_PIECE][0].get();
591591
(ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE;
592592
Square prevSq = to_sq((ss-1)->currentMove);
593593

@@ -751,7 +751,7 @@ namespace {
751751
Depth R = ((823 + 67 * depth / ONE_PLY) / 256 + std::min((eval - beta) / PawnValueMg, 3)) * ONE_PLY;
752752

753753
ss->currentMove = MOVE_NULL;
754-
ss->contHistory = thisThread->contHistory[NO_PIECE][0].get();
754+
ss->continuationHistory = thisThread->continuationHistory[NO_PIECE][0].get();
755755

756756
pos.do_null_move(st);
757757

@@ -802,7 +802,7 @@ namespace {
802802
probCutCount++;
803803

804804
ss->currentMove = move;
805-
ss->contHistory = thisThread->contHistory[pos.moved_piece(move)][to_sq(move)].get();
805+
ss->continuationHistory = thisThread->continuationHistory[pos.moved_piece(move)][to_sq(move)].get();
806806

807807
assert(depth >= 5 * ONE_PLY);
808808

@@ -835,7 +835,7 @@ namespace {
835835

836836
moves_loop: // When in check, search starts from here
837837

838-
const PieceToHistory* contHist[] = { (ss-1)->contHistory, (ss-2)->contHistory, nullptr, (ss-4)->contHistory };
838+
const PieceToHistory* contHist[] = { (ss-1)->continuationHistory, (ss-2)->continuationHistory, nullptr, (ss-4)->continuationHistory };
839839
Move countermove = thisThread->counterMoves[pos.piece_on(prevSq)][prevSq];
840840

841841
MovePicker mp(pos, ttMove, depth, &thisThread->mainHistory,
@@ -970,7 +970,7 @@ namespace {
970970

971971
// Update the current move (this must be done after singular extension search)
972972
ss->currentMove = move;
973-
ss->contHistory = thisThread->contHistory[movedPiece][to_sq(move)].get();
973+
ss->continuationHistory = thisThread->continuationHistory[movedPiece][to_sq(move)].get();
974974

975975
// Step 15. Make the move
976976
pos.do_move(move, st, givesCheck);
@@ -1212,8 +1212,10 @@ namespace {
12121212
ss->pv[0] = MOVE_NONE;
12131213
}
12141214

1215+
Thread* thisThread = pos.this_thread();
12151216
(ss+1)->ply = ss->ply + 1;
12161217
ss->currentMove = bestMove = MOVE_NONE;
1218+
ss->continuationHistory = thisThread->continuationHistory[NO_PIECE][0].get();
12171219
inCheck = pos.checkers();
12181220
moveCount = 0;
12191221

@@ -1283,12 +1285,15 @@ namespace {
12831285
futilityBase = bestValue + 128;
12841286
}
12851287

1288+
const PieceToHistory* contHist[] = { (ss-1)->continuationHistory, (ss-2)->continuationHistory, nullptr, (ss-4)->continuationHistory };
1289+
12861290
// Initialize a MovePicker object for the current position, and prepare
12871291
// to search the moves. Because the depth is <= 0 here, only captures,
12881292
// queen promotions and checks (only if depth >= DEPTH_QS_CHECKS) will
12891293
// be generated.
1290-
MovePicker mp(pos, ttMove, depth, &pos.this_thread()->mainHistory,
1291-
&pos.this_thread()->captureHistory,
1294+
MovePicker mp(pos, ttMove, depth, &thisThread->mainHistory,
1295+
&thisThread->captureHistory,
1296+
contHist,
12921297
to_sq((ss-1)->currentMove));
12931298

12941299
// Loop through the moves until no moves remain or a beta cutoff occurs
@@ -1345,6 +1350,7 @@ namespace {
13451350
}
13461351

13471352
ss->currentMove = move;
1353+
ss->continuationHistory = thisThread->continuationHistory[pos.moved_piece(move)][to_sq(move)].get();
13481354

13491355
// Make and search the move
13501356
pos.do_move(move, st, givesCheck);
@@ -1436,7 +1442,7 @@ namespace {
14361442

14371443
for (int i : {1, 2, 4})
14381444
if (is_ok((ss-i)->currentMove))
1439-
(*(ss-i)->contHistory)[pc][to] << bonus;
1445+
(*(ss-i)->continuationHistory)[pc][to] << bonus;
14401446
}
14411447

14421448

src/search.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ constexpr int CounterMovePruneThreshold = 0;
4141

4242
struct Stack {
4343
Move* pv;
44-
PieceToHistory* contHistory;
44+
PieceToHistory* continuationHistory;
4545
int ply;
4646
Move currentMove;
4747
Move excludedMove;

src/thread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ void Thread::clear() {
6161
mainHistory.fill(0);
6262
captureHistory.fill(0);
6363

64-
for (auto& to : contHistory)
64+
for (auto& to : continuationHistory)
6565
for (auto& h : to)
6666
h.get()->fill(0);
6767

68-
contHistory[NO_PIECE][0].get()->fill(Search::CounterMovePruneThreshold - 1);
68+
continuationHistory[NO_PIECE][0].get()->fill(Search::CounterMovePruneThreshold - 1);
6969
}
7070

7171
/// 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 contHistory;
74+
ContinuationHistory continuationHistory;
7575
Score contempt;
7676
};
7777

0 commit comments

Comments
 (0)