+
+/// MovePicker::generate_next() generates, scores and sorts the next bunch of moves,
+/// when there are no more moves to try for the current phase.
+
+void MovePicker::generate_next() {
+
+ curMove = moves;
+
+ switch (++phase) {
+
+ case CAPTURES_S1: case CAPTURES_S3: case CAPTURES_S4: case CAPTURES_S5: case CAPTURES_S6:
+ lastMove = generate<CAPTURES>(pos, moves);
+ score_captures();
+ return;
+
+ case KILLERS_S1:
+ curMove = killers;
+ lastMove = curMove + 2;
+ return;
+
+ case QUIETS_1_S1:
+ lastQuiet = lastMove = generate<QUIETS>(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:
+ // Just pick them in reverse order to get MVV/LVA ordering
+ curMove = moves + MAX_MOVES - 1;
+ lastMove = lastBadCapture;
+ return;
+
+ case EVASIONS_S2:
+ lastMove = generate<EVASIONS>(pos, moves);
+ score_evasions();
+ return;
+
+ case QUIET_CHECKS_S3:
+ lastMove = generate<QUIET_CHECKS>(pos, moves);
+ return;
+
+ case EVASION: case QSEARCH_0: case QSEARCH_1: case PROBCUT: case RECAPTURE:
+ phase = STOP;
+ case STOP:
+ lastMove = curMove + 1; // Avoid another next_phase() call
+ return;
+
+ default:
+ assert(false);
+ }
+}
+
+
+/// 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