- return;
-
- case KILLERS_S1:
- cur = killers;
- end = 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;
-
- // Please note that following code is racy and could yield to rare (less
- // than 1 out of a million) duplicated entries in SMP case. This is harmless.
-
- // Be sure countermoves are different from killers
- for (int i = 0; i < 2; ++i)
- if ( countermoves[i] != (cur+0)->move
- && countermoves[i] != (cur+1)->move)
- (end++)->move = countermoves[i];
-
- // Be sure followupmoves are different from killers and countermoves
- for (int i = 0; i < 2; ++i)
- if ( followupmoves[i] != (cur+0)->move
- && followupmoves[i] != (cur+1)->move
- && followupmoves[i] != (cur+2)->move
- && followupmoves[i] != (cur+3)->move)
- (end++)->move = followupmoves[i];
- return;
-
- case QUIETS_1_S1:
- endQuiets = end = generate<QUIETS>(pos, moves);
- score<QUIETS>();
- end = std::partition(cur, end, [](const ExtMove& m) { return m.value > VALUE_ZERO; });
- 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:
- stage = STOP;
- /* Fall through */
-
- 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 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.
-template<>
-Move MovePicker::next_move<false>() {
-
- Move move;
-
- while (true)
- {
- while (cur == end)
- generate_next_stage();
-
- switch (stage) {
-
- 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)
- {
- if (pos.see_sign(move) >= VALUE_ZERO)
- 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];