X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmovepick.cpp;h=b82e68b66a8019160998e7c0880c71ef58bbac2a;hp=3b636b935d431ac1af263b6e1ede2fc882fb3e23;hb=13d4df95cd4c56c0e730328648de54d9ed8bd81e;hpb=1c7a727795b82de75ed83e9648a94134ef75576a diff --git a/src/movepick.cpp b/src/movepick.cpp index 3b636b93..b82e68b6 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -67,8 +67,8 @@ 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, Move* fm, Search::Stack* s) : pos(p), history(h), counterMovesHistory(cmh), depth(d) { assert(d > DEPTH_ZERO); @@ -87,8 +87,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 +112,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 +162,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 +206,28 @@ 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; + killers[4].move = killers[5].move = MOVE_NONE; + + // In SMP case countermoves[] and followupmoves[] 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]; + + for (int i = 0; i < 2; ++i) + if ( followupmoves[i] != killers[0] + && followupmoves[i] != killers[1] + && followupmoves[i] != killers[2] + && followupmoves[i] != killers[3]) + *endMoves++ = followupmoves[i]; break; case QUIETS_1_S1: @@ -292,13 +312,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: