- if (type_of(m) == ENPASSANT)
- m.value = PieceValue[MG][PAWN] - Value(PAWN);
-
- else if (type_of(m) == PROMOTION)
- m.value = PieceValue[MG][pos.piece_on(to_sq(m))] - Value(PAWN)
- + PieceValue[MG][promotion_type(m)] - PieceValue[MG][PAWN];
- else
- m.value = PieceValue[MG][pos.piece_on(to_sq(m))]
- - Value(type_of(pos.moved_piece(m)));
-}
-
-template<>
-void MovePicker::score<QUIETS>() {
- for (auto& m : *this)
- m.value = history[pos.moved_piece(m)][to_sq(m)];
-}
-
-template<>
-void MovePicker::score<EVASIONS>() {
- // Try good captures ordered by MVV/LVA, then non-captures if destination square
- // is not under attack, ordered by history value, then bad-captures and quiet
- // moves with a negative SEE. This last group is ordered by the SEE value.
- 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() {
-
- cur = moves;
-
- switch (++stage) {
-
- case CAPTURES_S1: case CAPTURES_S3: case CAPTURES_S4: case CAPTURES_S5: case CAPTURES_S6:
- endMoves = generate<CAPTURES>(pos, moves);
- score<CAPTURES>();
- break;
-
- case KILLERS_S1:
- cur = killers;
- endMoves = cur + 2;
-
- killers[0] = ss->killers[0];
- killers[1] = ss->killers[1];
- killers[2].move = killers[3].move = MOVE_NONE;
- killers[4].move = killers[5].move = MOVE_NONE;
-
- // In SMP case countermoves[] and followupmoves[] could have duplicated entries
- // in rare cases (less than 1 out of a million). This is harmless.
-
- // Be sure countermoves and followupmoves are different from killers
- for (int i = 0; i < 2; ++i)
- if ( countermoves[i] != killers[0]
- && countermoves[i] != killers[1])
- *endMoves++ = countermoves[i];
-
- for (int i = 0; i < 2; ++i)
- if ( followupmoves[i] != killers[0]
- && followupmoves[i] != killers[1]
- && followupmoves[i] != killers[2]
- && followupmoves[i] != killers[3])
- *endMoves++ = followupmoves[i];
- break;
-
- case QUIETS_1_S1:
- 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 QUIETS_2_S1:
- cur = endMoves;
- endMoves = endQuiets;
- if (depth >= 3 * ONE_PLY)
- insertion_sort(cur, endMoves);
- break;
-
- case BAD_CAPTURES_S1:
- // Just pick them in reverse order to get MVV/LVA ordering
- cur = moves + MAX_MOVES - 1;
- endMoves = endBadCaptures;
- break;
-
- case EVASIONS_S2:
- endMoves = generate<EVASIONS>(pos, moves);
- if (endMoves - moves > 1)
- score<EVASIONS>();
- break;
-
- case QUIET_CHECKS_S3:
- endMoves = generate<QUIET_CHECKS>(pos, moves);
- break;
-
- case EVASION: case QSEARCH_0: case QSEARCH_1: case PROBCUT: case RECAPTURE:
- stage = STOP;
- /* Fall through */
-
- case STOP:
- endMoves = cur + 1; // Avoid another generate_next_stage() call
- break;
-
- default:
- assert(false);
- }