- m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
- - Value(200 * relative_rank(pos.side_to_move(), to_sq(m)));
-}
-
-template<>
-void MovePicker::score<QUIETS>() {
-
- const HistoryStats& history = pos.this_thread()->history;
-
- const CounterMoveStats* cm = (ss-1)->counterMoves;
- const CounterMoveStats* fm = (ss-2)->counterMoves;
- const CounterMoveStats* f2 = (ss-4)->counterMoves;
-
- for (auto& m : *this)
- m.value = history[pos.moved_piece(m)][to_sq(m)]
- + (cm ? (*cm)[pos.moved_piece(m)][to_sq(m)] : VALUE_ZERO)
- + (fm ? (*fm)[pos.moved_piece(m)][to_sq(m)] : VALUE_ZERO)
- + (f2 ? (*f2)[pos.moved_piece(m)][to_sq(m)] : VALUE_ZERO);
-}
-
-template<>
-void MovePicker::score<EVASIONS>() {
- // Try winning and equal captures ordered by MVV/LVA, then non-captures ordered
- // by history value, then bad captures and quiet moves with a negative SEE ordered
- // by SEE value.
- const HistoryStats& history = pos.this_thread()->history;
- Value see;
-
- for (auto& m : *this)
- if ((see = pos.see_sign(m)) < VALUE_ZERO)
- m.value = see - HistoryStats::Max; // At the bottom
-
- 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 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;
-
- default:
- assert(false);
- }
+ if (T == CAPTURES || (T == EVASIONS && pos.capture(m)))
+ m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
+ - (T == EVASIONS ? Value(type_of(pos.moved_piece(m)))
+ : Value(200 * relative_rank(pos.side_to_move(), to_sq(m))));
+ else if (T == QUIETS)
+ m.value = (*mainHistory)[pos.side_to_move()][from_to(m)]
+ + (*contHistory[0])[pos.moved_piece(m)][to_sq(m)]
+ + (*contHistory[1])[pos.moved_piece(m)][to_sq(m)]
+ + (*contHistory[3])[pos.moved_piece(m)][to_sq(m)];
+
+ else // Quiet evasions
+ m.value = (*mainHistory)[pos.side_to_move()][from_to(m)] - (1 << 28);