-/// MovePicker::next_phase() generates, scores and sorts the next bunch of moves,
-/// when there are no more moves to try for the current phase.
-
-void MovePicker::next_phase() {
-
- curMove = moves;
-
- switch (++phase) {
-
- case TT_MOVE_S1: case TT_MOVE_S2: case TT_MOVE_S3: case TT_MOVE_S4: case TT_MOVE_S5:
- lastMove = curMove + 1;
- return;
-
- case CAPTURES_S1: case CAPTURES_S3: case CAPTURES_S4:
- case CAPTURES_S5: case CAPTURES_S6:
- lastMove = generate<MV_CAPTURE>(pos, moves);
- score_captures();
- return;
-
- case KILLERS_S1:
- curMove = killers;
- lastMove = curMove + 2;
- return;
-
- case QUIETS_1_S1:
- lastQuiet = lastMove = generate<MV_QUIET>(pos, moves);
- score_noncaptures();
- lastMove = std::partition(curMove, lastMove, has_positive_score);
- sort<MoveStack>(curMove, lastMove);
- return;
-
- case QUIETS_2_S1:
- curMove = lastMove;
- lastMove = lastQuiet;
- if (depth >= 3 * ONE_PLY)
- sort<MoveStack>(curMove, lastMove);
- return;
-
- case BAD_CAPTURES_S1:
- // Bad captures SEE value is already calculated so just pick them in order
- // to get SEE move ordering.
- curMove = badCaptures;
- lastMove = moves + MAX_MOVES;
- return;
-
- case EVASIONS_S2:
- assert(pos.in_check());
- lastMove = generate<MV_EVASION>(pos, moves);
- score_evasions();
- return;
-
- case QUIET_CHECKS_S3:
- lastMove = generate<MV_QUIET_CHECK>(pos, moves);
- return;
-
- case STOP_S1: case STOP_S2: case STOP_S3: case STOP_S4: case STOP_S5: case STOP_S6:
- lastMove = curMove + 1; // Avoid another next_phase() call
- return;
+/// generate_next_stage() generates, scores, and sorts the next bunch of moves
+/// when there are no more moves to try for the current stage.
+
+void MovePicker::generate_next_stage() {
+
+ assert(stage != STOP);
+
+ cur = moves;
+
+ switch (++stage) {
+
+ case GOOD_CAPTURES: case QCAPTURES_1: case QCAPTURES_2:
+ case PROBCUT_CAPTURES: case RECAPTURES:
+ endMoves = generate<CAPTURES>(pos, moves);
+ score<CAPTURES>();
+ break;
+
+ case KILLERS:
+ killers[0] = ss->killers[0];
+ killers[1] = ss->killers[1];
+ killers[2] = countermove;
+ cur = killers;
+ endMoves = cur + 2 + (countermove != killers[0] && countermove != killers[1]);
+ break;
+
+ case QUIET:
+ endMoves = generate<QUIETS>(pos, moves);
+ score<QUIETS>();
+ if (depth < 3 * ONE_PLY)
+ {
+ ExtMove* goodQuiet = std::partition(cur, endMoves, [](const ExtMove& m)
+ { return m.value > VALUE_ZERO; });
+ insertion_sort(cur, goodQuiet);
+ } else
+ insertion_sort(cur, endMoves);
+ break;
+
+ case BAD_CAPTURES:
+ // Just pick them in reverse order to get correct ordering
+ cur = moves + MAX_MOVES - 1;
+ endMoves = endBadCaptures;
+ break;
+
+ case ALL_EVASIONS:
+ endMoves = generate<EVASIONS>(pos, moves);
+ if (endMoves - moves > 1)
+ score<EVASIONS>();
+ break;
+
+ case CHECKS:
+ endMoves = generate<QUIET_CHECKS>(pos, moves);
+ break;
+
+ case EVASION: case QSEARCH_WITH_CHECKS: case QSEARCH_WITHOUT_CHECKS:
+ case PROBCUT: case RECAPTURE: case STOP:
+ stage = STOP;
+ break;