X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmovepick.cpp;h=3baf4f700b59cd52ab30c5a13d625bdbecd2027e;hp=3b636b935d431ac1af263b6e1ede2fc882fb3e23;hb=6c4257520847f7bb0f4008dedb65159cbacce106;hpb=0af24a14455bbcde181fff7632722ce55419991e diff --git a/src/movepick.cpp b/src/movepick.cpp index 3b636b93..3baf4f70 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -67,14 +67,13 @@ namespace { /// 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()) @@ -87,8 +86,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& 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); @@ -112,8 +111,8 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const HistoryStats& 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()); @@ -162,8 +161,13 @@ void MovePicker::score() { template<> void MovePicker::score() { + + 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<> @@ -201,13 +205,20 @@ void MovePicker::generate_next_stage() { 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: @@ -292,13 +303,7 @@ Move MovePicker::next_move() { && 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: @@ -307,9 +312,7 @@ Move MovePicker::next_move() { && move != killers[0] && move != killers[1] && move != killers[2] - && move != killers[3] - && move != killers[4] - && move != killers[5]) + && move != killers[3]) return move; break;