- return;
-
- case KILLERS_S1:
- cur = killers;
- end = cur + 3;
- return;
-
- case QUIETS_1_S1:
- endQuiets = end = generate<QUIETS>(pos, moves);
- score<QUIETS>();
- end = std::partition(cur, end, has_positive_score);
- insertion_sort(cur, end);
- return;
-
- case QUIETS_2_S1:
- cur = end;
- end = endQuiets;
- if (depth >= 3 * ONE_PLY)
- insertion_sort(cur, end);
- return;
-
- case BAD_CAPTURES_S1:
- // Just pick them in reverse order to get MVV/LVA ordering
- cur = moves + MAX_MOVES - 1;
- end = endBadCaptures;
- return;
-
- case EVASIONS_S2:
- end = generate<EVASIONS>(pos, moves);
- if (end > moves + 1)
- score<EVASIONS>();
- return;
-
- case QUIET_CHECKS_S3:
- end = generate<QUIET_CHECKS>(pos, moves);
- return;
-
- case EVASION: case QSEARCH_0: case QSEARCH_1: case PROBCUT: case RECAPTURE:
- phase = STOP;
- case STOP:
- end = cur + 1; // Avoid another next_phase() call
- return;
-
- default:
- assert(false);
- }
-}
-
-
-/// next_move() is the most important method of the MovePicker class. It returns
-/// a new pseudo legal move every time is called, until there are no more moves
-/// left. It picks the move with the biggest score from a list of generated moves
-/// taking care not returning the ttMove if has already been searched previously.
-template<>
-Move MovePicker::next_move<false>() {
-
- Move move;
-
- while (true)
- {
- while (cur == end)
- generate_next();
-
- switch (phase) {
-
- case MAIN_SEARCH: case EVASION: case QSEARCH_0: case QSEARCH_1: case PROBCUT:
- cur++;
- return ttMove;
-
- case CAPTURES_S1:
- move = pick_best(cur++, end)->move;
- if (move != ttMove)
- {
- assert(captureThreshold <= 0); // Otherwise we cannot use see_sign()
-
- if (pos.see_sign(move) >= captureThreshold)
- return move;
-
- // Losing capture, move it to the tail of the array
- (endBadCaptures--)->move = move;
- }
- break;
-
- case KILLERS_S1:
- move = (cur++)->move;
+ ++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;
+
+ // If the countermove is the same as a killer, skip it
+ if ( refutations[0] == refutations[2]
+ || refutations[1] == refutations[2])
+ refutations[2] = MOVE_NONE;
+ ++stage;
+ /* fallthrough */
+
+ case KILLER0:
+ case KILLER1:
+ case COUNTERMOVE:
+ while (stage <= COUNTERMOVE)
+ {
+ move = refutations[ stage++ - KILLER0];