- Move m = moves[i].move;
- if (m == ttMoves[0])
- moves[i].score = 2*HistoryMax;
- else if (!pos.square_is_empty(move_to(m)))
- {
- int seeScore = pos.see(m);
- moves[i].score = (seeScore >= 0)? seeScore + HistoryMax : seeScore;
- } else
- moves[i].score = H.move_ordering_score(pos.piece_on(move_from(m)), move_to(m));
+ m = cur->move;
+ if ((seeScore = pos.see_sign(m)) < 0)
+ cur->score = seeScore - History::MaxValue; // Be sure we are at the bottom
+ else if (pos.is_capture(m))
+ cur->score = PieceValue[Mg][pos.piece_on(to_sq(m))]
+ - type_of(pos.piece_moved(m)) + History::MaxValue;
+ else
+ cur->score = H.value(pos.piece_moved(m), to_sq(m));
+ }
+}
+
+
+/// 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);