X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmovepick.cpp;h=f7b7f42673d2a0405580848faa25845ed3a010c5;hp=1f4ef1952d0a0c469ba654f31512c3c3966e7712;hb=2ca142a5b4ca200c56cb99495ec51a804983d07d;hpb=0dc6f16992c7e682be4be89123cdc5f6fb307606 diff --git a/src/movepick.cpp b/src/movepick.cpp index 1f4ef195..f7b7f426 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -55,7 +55,7 @@ namespace { inline Move pick_best(ExtMove* begin, ExtMove* end) { std::swap(*begin, *std::max_element(begin, end)); - return begin->move; + return *begin; } } // namespace @@ -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; + countermove = cm; 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<> @@ -203,26 +207,14 @@ void MovePicker::generate_next_stage() { cur = killers; endMoves = cur + 2; - killers[0].move = ss->killers[0]; - killers[1].move = ss->killers[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].move - && countermoves[i] != killers[1].move) - (endMoves++)->move = countermoves[i]; - - for (int i = 0; i < 2; ++i) - if ( followupmoves[i] != killers[0].move - && followupmoves[i] != killers[1].move - && followupmoves[i] != killers[2].move - && followupmoves[i] != killers[3].move) - (endMoves++)->move = followupmoves[i]; + killers[0] = ss->killers[0]; + killers[1] = ss->killers[1]; + killers[2].move = MOVE_NONE; + + // Be sure countermoves are different from killers + if ( countermove != killers[0] + && countermove != killers[1]) + *endMoves++ = countermove; break; case QUIETS_1_S1: @@ -260,7 +252,7 @@ void MovePicker::generate_next_stage() { /* Fall through */ case STOP: - endMoves = cur + 1; // Avoid another next_phase() call + endMoves = cur + 1; // Avoid another generate_next_stage() call break; default: @@ -297,7 +289,7 @@ Move MovePicker::next_move() { return move; // Losing capture, move it to the tail of the array - (endBadCaptures--)->move = move; + *endBadCaptures-- = move; } break; @@ -313,12 +305,9 @@ Move MovePicker::next_move() { case QUIETS_1_S1: case QUIETS_2_S1: move = *cur++; if ( move != ttMove - && move != killers[0].move - && move != killers[1].move - && move != killers[2].move - && move != killers[3].move - && move != killers[4].move - && move != killers[5].move) + && move != killers[0] + && move != killers[1] + && move != killers[2]) return move; break;