+ it->score = history[pos.moved_piece(m)][to_sq(m)];
+ }
+}
+
+
+/// 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() {
+
+ cur = moves;
+
+ switch (++stage) {
+
+ case CAPTURES_S1: case CAPTURES_S3: case CAPTURES_S4: case CAPTURES_S5: case CAPTURES_S6:
+ end = generate<CAPTURES>(pos, moves);
+ score<CAPTURES>();
+ 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;
+
+ // Be sure countermoves are different from killers
+ for (int i = 0; i < 2; ++i)
+ if (countermoves[i] != cur->move && countermoves[i] != (cur+1)->move)
+ (end++)->move = countermoves[i];
+
+ if (countermoves[1] && countermoves[1] == countermoves[0]) // Due to SMP races
+ killers[3].move = MOVE_NONE;
+
+ 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:
+ stage = STOP;
+ case STOP:
+ end = cur + 1; // Avoid another next_phase() call
+ return;
+
+ default:
+ assert(false);