- for (MoveStack* cur = moves; cur != lastMove; cur++)
- {
- m = cur->move;
- if (m == ttMoves[0].move)
- cur->score = 2 * HistoryMax;
- else if (!pos.square_is_empty(move_to(m)))
- {
- int seeScore = pos.see(m);
- cur->score = seeScore + (seeScore >= 0 ? HistoryMax : 0);
- } else
- cur->score = H.move_ordering_score(pos.piece_on(move_from(m)), move_to(m));
+ else if (pos.capture(m))
+ m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
+ - Value(type_of(pos.moved_piece(m))) + HistoryStats::Max;
+ else
+ m.value = history[pos.moved_piece(m)][to_sq(m)];
+}
+
+
+/// 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 GOOD_QUIETS:
+ endQuiets = endMoves = generate<QUIETS>(pos, moves);
+ score<QUIETS>();
+ endMoves = std::partition(cur, endMoves, [](const ExtMove& m) { return m.value > VALUE_ZERO; });
+ insertion_sort(cur, endMoves);
+ break;
+
+ case BAD_QUIETS:
+ cur = endMoves;
+ endMoves = endQuiets;
+ if (depth >= 3 * ONE_PLY)
+ 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;
+
+ default:
+ assert(false);