Skip to content

Commit f7c013e

Browse files
zamarmcostalba
authored andcommitted
Use two counter moves instead of one
Very good at long 60"+0.05 TC LLR: 2.95 (-2.94,2.94) Total: 5954 W: 1151 L: 1016 D: 3787 [edit: slightly changed form original patch to avoid useless loop across killers when killer is MOVE_NONE] bench: 4327405
1 parent 148490f commit f7c013e

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

src/movepick.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats&
9090
killers[0].move = ss->killers[0];
9191
killers[1].move = ss->killers[1];
9292
Square prevSq = to_sq((ss-1)->currentMove);
93-
killers[2].move = cm[pos.piece_on(prevSq)][prevSq];
93+
killers[2].move = cm[pos.piece_on(prevSq)][prevSq].first;
94+
killers[3].move = cm[pos.piece_on(prevSq)][prevSq].second;
9495

9596
// Consider sligtly negative captures as good if at low depth and far from beta
9697
if (ss && ss->staticEval < beta - PawnValueMg && d < 3 * ONE_PLY)
@@ -239,7 +240,17 @@ void MovePicker::generate_next() {
239240

240241
case KILLERS_S1:
241242
cur = killers;
242-
end = cur + 3 - (killers[2].move == killers[0].move || killers[2].move == killers[1].move);
243+
end = cur + 2;
244+
245+
if ((cur+3)->move && (cur+3)->move == (cur+2)->move) // Due to a SMP race
246+
(cur+3)->move = MOVE_NONE;
247+
248+
// Be sure countermoves are different from killers
249+
if ((cur+2)->move != cur->move && (cur+2)->move != (cur+1)->move)
250+
end++;
251+
252+
if ((cur+3)->move != cur->move && (cur+3)->move != (cur+1)->move)
253+
(end++)->move = (cur+3)->move;
243254
return;
244255

245256
case QUIETS_1_S1:
@@ -332,7 +343,8 @@ Move MovePicker::next_move<false>() {
332343
if ( move != ttMove
333344
&& move != killers[0].move
334345
&& move != killers[1].move
335-
&& move != killers[2].move)
346+
&& move != killers[2].move
347+
&& move != killers[3].move)
336348
return move;
337349
break;
338350

src/movepick.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,18 @@ struct Stats {
4242

4343
static const Value Max = Value(2000);
4444

45-
const T* operator[](Piece p) const { return &table[p][0]; }
45+
const T* operator[](Piece p) const { return table[p]; }
4646
void clear() { memset(table, 0, sizeof(table)); }
4747

48-
void update(Piece p, Square to, Move m) { table[p][to] = m; }
48+
void update(Piece p, Square to, Move m) {
49+
50+
if (m == table[p][to].first)
51+
return;
52+
53+
table[p][to].second = table[p][to].first;
54+
table[p][to].first = m;
55+
}
56+
4957
void update(Piece p, Square to, Value v) {
5058

5159
if (Gain)
@@ -61,7 +69,7 @@ struct Stats {
6169

6270
typedef Stats< true, Value> GainsStats;
6371
typedef Stats<false, Value> HistoryStats;
64-
typedef Stats<false, Move> CountermovesStats;
72+
typedef Stats<false, std::pair<Move, Move> > CountermovesStats;
6573

6674

6775
/// MovePicker class is used to pick one pseudo legal move at a time from the
@@ -92,7 +100,7 @@ class MovePicker {
92100
Search::Stack* ss;
93101
Depth depth;
94102
Move ttMove;
95-
MoveStack killers[3];
103+
MoveStack killers[4];
96104
Square recaptureSquare;
97105
int captureThreshold, phase;
98106
MoveStack *cur, *end, *endQuiets, *endBadCaptures;

0 commit comments

Comments
 (0)