-#include "thread.h"
-
-namespace {
-
- enum Stages {
- MAIN_SEARCH, CAPTURES_S1, KILLERS_S1, QUIETS_1_S1, QUIETS_2_S1, BAD_CAPTURES_S1,
- EVASION, EVASIONS_S2,
- QSEARCH_0, CAPTURES_S3, QUIET_CHECKS_S3,
- QSEARCH_1, CAPTURES_S4,
- PROBCUT, CAPTURES_S5,
- RECAPTURE, CAPTURES_S6,
- STOP
- };
-
- // Our insertion sort, which is guaranteed to be stable, as it should be
- void insertion_sort(ExtMove* begin, ExtMove* end)
- {
- ExtMove tmp, *p, *q;
-
- for (p = begin + 1; p < end; ++p)
- {
- tmp = *p;
- for (q = p; q != begin && *(q-1) < tmp; --q)
- *q = *(q-1);
- *q = tmp;
- }
- }
-
- // pick_best() finds the best move in the range (begin, end) and moves it to
- // the front. It's faster than sorting all the moves in advance when there
- // are few moves e.g. the possible captures.
- inline Move pick_best(ExtMove* begin, ExtMove* end)
- {
- std::swap(*begin, *std::max_element(begin, end));
- return *begin;
- }
-
-} // namespace
-
-
-/// Constructors of the MovePicker class. As arguments we pass information
-/// to help it to return the (presumably) good moves first, to decide which
-/// moves to return (in the quiescence search, for instance, we only want to
-/// 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, 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;
- countermove = cm;
- ss = s;
-
- if (pos.checkers())
- stage = EVASION;
-
- else
- stage = MAIN_SEARCH;
-
- ttMove = (ttm && pos.pseudo_legal(ttm) ? ttm : MOVE_NONE);
- endMoves += (ttMove != MOVE_NONE);
-}
-
-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);
-
- if (pos.checkers())
- stage = EVASION;
-
- else if (d > DEPTH_QS_NO_CHECKS)
- stage = QSEARCH_0;
-
- else if (d > DEPTH_QS_RECAPTURES)
- stage = QSEARCH_1;