/// search captures, promotions and some checks) and how important good move
/// ordering is at the current node.
-MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
- Move* cm, Move* fm, Search::Stack* s) : pos(p), history(h), depth(d) {
+MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h, const CounterMovesHistoryStats& cmh,
+ Move* cm, Search::Stack* s) : pos(p), history(h), counterMovesHistory(cmh), depth(d) {
assert(d > DEPTH_ZERO);
endBadCaptures = moves + MAX_MOVES - 1;
countermoves = cm;
- followupmoves = fm;
ss = s;
if (pos.checkers())
endMoves += (ttMove != MOVE_NONE);
}
-MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h,
- Square s) : pos(p), history(h) {
+MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& h, const CounterMovesHistoryStats& cmh,
+ Square s) : pos(p), history(h), counterMovesHistory(cmh) {
assert(d <= DEPTH_ZERO);
endMoves += (ttMove != MOVE_NONE);
}
-MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, PieceType pt)
- : pos(p), history(h) {
+MovePicker::MovePicker(const Position& p, Move ttm, const HistoryStats& h, const CounterMovesHistoryStats& cmh, PieceType pt)
+ : pos(p), history(h), counterMovesHistory(cmh) {
assert(!pos.checkers());
template<>
void MovePicker::score<QUIETS>() {
+
+ Square prevSq = to_sq((ss-1)->currentMove);
+ const HistoryStats& cmh = counterMovesHistory[pos.piece_on(prevSq)][prevSq];
+
for (auto& m : *this)
- m.value = history[pos.moved_piece(m)][to_sq(m)];
+ m.value = history[pos.moved_piece(m)][to_sq(m)]
+ + cmh[pos.moved_piece(m)][to_sq(m)];
}
template<>
case KILLERS_S1:
cur = killers;
- endMoves = cur + 6;
+ endMoves = cur + 2;
+
killers[0] = ss->killers[0];
killers[1] = ss->killers[1];
- killers[2] = countermoves[0];
- killers[3] = countermoves[1];
- killers[4] = followupmoves[0];
- killers[5] = followupmoves[1];
+ killers[2].move = killers[3].move = MOVE_NONE;
+
+ // In SMP case countermoves[] could have duplicated entries
+ // in rare cases (less than 1 out of a million). This is harmless.
+
+ // Be sure countermoves and followupmoves are different from killers
+ for (int i = 0; i < 2; ++i)
+ if ( countermoves[i] != killers[0]
+ && countermoves[i] != killers[1])
+ *endMoves++ = countermoves[i];
break;
case QUIETS_1_S1:
/* Fall through */
case STOP:
- endMoves = cur + 1; // Avoid another next_phase() call
+ endMoves = cur + 1; // Avoid another generate_next_stage() call
break;
default:
&& move != ttMove
&& pos.pseudo_legal(move)
&& !pos.capture(move))
- {
- for (int i = 0; i < cur - 1 - killers; i++) // Skip duplicated
- if (move == killers[i])
- goto skip;
return move;
- }
- skip:
break;
case QUIETS_1_S1: case QUIETS_2_S1:
&& move != killers[0]
&& move != killers[1]
&& move != killers[2]
- && move != killers[3]
- && move != killers[4]
- && move != killers[5])
+ && move != killers[3])
return move;
break;