@@ -32,7 +32,7 @@ int history_slot(Piece pc) {
3232namespace {
3333
3434 enum Stages {
35- MAIN_TT, CAPTURE_INIT, GOOD_CAPTURE, REFUTATION, QUIET_INIT, QUIET, BAD_CAPTURE,
35+ MAIN_TT, CAPTURE_INIT, GOOD_CAPTURE, REFUTATION, QUIET_INIT, QUIET, POTION_INIT, POTION, BAD_CAPTURE,
3636 EVASION_TT, EVASION_INIT, EVASION,
3737 PROBCUT_TT, PROBCUT_INIT, PROBCUT,
3838 QSEARCH_TT, QCAPTURE_INIT, QCAPTURE, QCHECK_INIT, QCHECK
@@ -117,7 +117,7 @@ bool MovePicker::is_potion_move(Move m) const {
117117MovePicker::MovePicker (const Position& p, Move ttm, Depth d, const ButterflyHistory* mh, const GateHistory* dh, const LowPlyHistory* lp,
118118 const CapturePieceToHistory* cph, const PieceToHistory** ch, Move cm, const Move* killers, int pl)
119119 : pos(p), mainHistory(mh), gateHistory(dh), lowPlyHistory(lp), captureHistory(cph), continuationHistory(ch),
120- ttMove (ttm), refutations{{killers[0 ], 0 }, {killers[1 ], 0 }, {cm, 0 }}, depth(d), ply(pl) {
120+ ttMove (ttm), refutations{{killers[0 ], 0 }, {killers[1 ], 0 }, {cm, 0 }}, quietStart(moves), quietEnd(moves), depth(d), ply(pl) {
121121
122122 assert (d > 0 );
123123
@@ -128,7 +128,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHist
128128// / MovePicker constructor for quiescence search
129129MovePicker::MovePicker (const Position& p, Move ttm, Depth d, const ButterflyHistory* mh, const GateHistory* dh,
130130 const CapturePieceToHistory* cph, const PieceToHistory** ch, Square rs)
131- : pos(p), mainHistory(mh), gateHistory(dh), captureHistory(cph), continuationHistory(ch), ttMove(ttm), recaptureSquare(rs), depth(d) {
131+ : pos(p), mainHistory(mh), gateHistory(dh), captureHistory(cph), continuationHistory(ch), ttMove(ttm), quietStart(moves), quietEnd(moves), recaptureSquare(rs), depth(d) {
132132
133133 assert (d <= 0 );
134134
@@ -141,7 +141,7 @@ MovePicker::MovePicker(const Position& p, Move ttm, Depth d, const ButterflyHist
141141// / MovePicker constructor for ProbCut: we generate captures with SEE greater
142142// / than or equal to the given threshold.
143143MovePicker::MovePicker (const Position& p, Move ttm, Value th, const GateHistory* dh, const CapturePieceToHistory* cph)
144- : pos(p), gateHistory(dh), captureHistory(cph), ttMove(ttm), threshold(th) {
144+ : pos(p), gateHistory(dh), captureHistory(cph), ttMove(ttm), quietStart(moves), quietEnd(moves), threshold(th) {
145145
146146 assert (!pos.checkers ());
147147
@@ -272,12 +272,16 @@ Move MovePicker::next_move(bool skipQuiets) {
272272 case QUIET_INIT:
273273 if (!skipQuiets && !(pos.must_capture () && pos.has_capture ()))
274274 {
275- cur = endBadCaptures;
276- endMoves = generate<QUIETS>(pos, cur);
275+ quietStart = endBadCaptures;
276+ quietEnd = generate_base (QUIETS, pos, quietStart);
277+ cur = quietStart;
278+ endMoves = quietEnd;
277279
278280 score<QUIETS>();
279281 partial_insertion_sort (cur, endMoves, -3000 * depth);
280282 }
283+ else
284+ quietStart = quietEnd = endBadCaptures;
281285
282286 ++stage;
283287 [[fallthrough]];
@@ -289,6 +293,34 @@ Move MovePicker::next_move(bool skipQuiets) {
289293 && *cur != refutations[2 ].move ;}))
290294 return *(cur - 1 );
291295
296+ ++stage;
297+ [[fallthrough]];
298+
299+ case POTION_INIT:
300+ if ( skipQuiets
301+ || (pos.must_capture () && pos.has_capture ())
302+ || !pos.potions_enabled ()
303+ || quietStart == quietEnd)
304+ {
305+ cur = moves;
306+ endMoves = endBadCaptures;
307+ stage = BAD_CAPTURE;
308+ goto top;
309+ }
310+
311+ cur = quietEnd;
312+ endMoves = generate_potions (QUIETS, pos, quietStart, quietEnd);
313+
314+ score<QUIETS>();
315+ partial_insertion_sort (cur, endMoves, -3000 * depth);
316+
317+ ++stage;
318+ [[fallthrough]];
319+
320+ case POTION:
321+ if (select<Next>([&](){return true ;}))
322+ return *(cur - 1 );
323+
292324 // Prepare the pointers to loop over the bad captures
293325 cur = moves;
294326 endMoves = endBadCaptures;
0 commit comments