killers[0].move = ss->killers[0];
killers[1].move = ss->killers[1];
Square prevSq = to_sq((ss-1)->currentMove);
- killers[2].move = cm[pos.piece_on(prevSq)][prevSq];
+ killers[2].move = cm[pos.piece_on(prevSq)][prevSq].first;
+ killers[3].move = cm[pos.piece_on(prevSq)][prevSq].second;
// Consider sligtly negative captures as good if at low depth and far from beta
if (ss && ss->staticEval < beta - PawnValueMg && d < 3 * ONE_PLY)
case KILLERS_S1:
cur = killers;
- end = cur + 3 - (killers[2].move == killers[0].move || killers[2].move == killers[1].move);
+ end = cur + 2;
+
+ if ((cur+3)->move && (cur+3)->move == (cur+2)->move) // Due to a SMP race
+ (cur+3)->move = MOVE_NONE;
+
+ // Be sure countermoves are different from killers
+ if ((cur+2)->move != cur->move && (cur+2)->move != (cur+1)->move)
+ end++;
+
+ if ((cur+3)->move != cur->move && (cur+3)->move != (cur+1)->move)
+ (end++)->move = (cur+3)->move;
return;
case QUIETS_1_S1:
if ( move != ttMove
&& move != killers[0].move
&& move != killers[1].move
- && move != killers[2].move)
+ && move != killers[2].move
+ && move != killers[3].move)
return move;
break;
static const Value Max = Value(2000);
- const T* operator[](Piece p) const { return &table[p][0]; }
+ const T* operator[](Piece p) const { return table[p]; }
void clear() { memset(table, 0, sizeof(table)); }
- void update(Piece p, Square to, Move m) { table[p][to] = m; }
+ void update(Piece p, Square to, Move m) {
+
+ if (m == table[p][to].first)
+ return;
+
+ table[p][to].second = table[p][to].first;
+ table[p][to].first = m;
+ }
+
void update(Piece p, Square to, Value v) {
if (Gain)
typedef Stats< true, Value> GainsStats;
typedef Stats<false, Value> HistoryStats;
-typedef Stats<false, Move> CountermovesStats;
+typedef Stats<false, std::pair<Move, Move> > CountermovesStats;
/// MovePicker class is used to pick one pseudo legal move at a time from the
Search::Stack* ss;
Depth depth;
Move ttMove;
- MoveStack killers[3];
+ MoveStack killers[4];
Square recaptureSquare;
int captureThreshold, phase;
MoveStack *cur, *end, *endQuiets, *endBadCaptures;