-int MovePicker::see_sign() const
-{
- return stage == GOOD_CAPTURES ? 1
- : stage == BAD_CAPTURES ? -1 : 0;
-}
-
-/// next_move() is the most important method of the MovePicker class. It returns
-/// a new pseudo legal move every time it is called, until there are no more moves
-/// left. It picks the move with the biggest value from a list of generated moves
-/// taking care not to return the ttMove if it has already been searched.
+/// MovePicker::next_move() is the most important method of the MovePicker class. It
+/// returns a new pseudo legal move every time it is called until there are no more
+/// moves left, picking the move with the highest score from a list of generated moves.
+Move MovePicker::next_move(bool skipQuiets) {
+
+top:
+ switch (stage) {
+
+ case MAIN_TT:
+ case EVASION_TT:
+ case QSEARCH_TT:
+ case PROBCUT_TT:
+ ++stage;
+ return ttMove;
+
+ case CAPTURE_INIT:
+ case PROBCUT_INIT:
+ case QCAPTURE_INIT:
+ endBadCaptures = cur = moves;
+ endMoves = generate<CAPTURES>(pos, cur);
+ score<CAPTURES>();
+ ++stage;
+ goto top;
+
+ case GOOD_CAPTURE:
+ if (select_move<BEST_SCORE>([&](){ return pos.see_ge(move, Value(-55 * (cur-1)->value / 1024)) ?
+ // Move losing capture to endBadCaptures to be tried later
+ true : (*endBadCaptures++ = move, false); }))
+ return move;
+
+ // Prepare the pointers to loop over the refutations array
+ cur = std::begin(refutations), endMoves = std::end(refutations);
+
+ // If the countermove is the same as a killer, skip it
+ if ( refutations[0].move == refutations[2].move
+ || refutations[1].move == refutations[2].move)
+ --endMoves;
+
+ ++stage;
+ /* fallthrough */
+
+ case REFUTATION:
+ if (select_move<NEXT>([&](){ return move != MOVE_NONE
+ && !pos.capture(move)
+ && pos.pseudo_legal(move); }))
+ return move;
+ ++stage;
+ /* fallthrough */
+
+ case QUIET_INIT:
+ cur = endBadCaptures;
+ endMoves = generate<QUIETS>(pos, cur);
+ score<QUIETS>();
+ partial_insertion_sort(cur, endMoves, -4000 * depth / ONE_PLY);
+ ++stage;
+ /* fallthrough */