- while (true)
- {
- while (curMove == lastMove)
- go_next_phase();
-
- switch (phase) {
-
- case PH_TT_MOVE:
- curMove++;
- return ttMove;
- break;
-
- case PH_GOOD_CAPTURES:
- move = pick_best(curMove++, lastMove).move;
- if (move != ttMove)
- {
- assert(captureThreshold <= 0); // Otherwise we must use see instead of see_sign
-
- // Check for a non negative SEE now
- int seeValue = pos.see_sign(move);
- if (seeValue >= captureThreshold)
- return move;
-
- // Losing capture, move it to the tail of the array, note
- // that move has now been already checked for pseudo legality.
- (--badCaptures)->move = move;
- badCaptures->score = seeValue;
- }
- break;
-
- case PH_GOOD_PROBCUT:
- move = pick_best(curMove++, lastMove).move;
- if ( move != ttMove
- && pos.see(move) > captureThreshold)
- return move;
- break;
-
- case PH_KILLERS:
- move = (curMove++)->move;
- if ( move != MOVE_NONE
- && pos.move_is_pl(move)
- && move != ttMove
- && !pos.move_is_capture(move))
- return move;
- break;
-
- case PH_NONCAPTURES_1:
- case PH_NONCAPTURES_2:
- move = (curMove++)->move;
- if ( move != ttMove
- && move != killers[0].move
- && move != killers[1].move)
- return move;
- break;
-
- case PH_BAD_CAPTURES:
- move = pick_best(curMove++, lastMove).move;
- return move;
-
- case PH_EVASIONS:
- case PH_QCAPTURES:
- move = pick_best(curMove++, lastMove).move;
- if (move != ttMove)
- return move;
- break;
-
- case PH_QRECAPTURES:
- move = (curMove++)->move;
- if (move_to(move) == recaptureSquare)
- return move;
- break;
-
- case PH_QCHECKS:
- move = (curMove++)->move;
- if (move != ttMove)
- return move;
- break;
-
- case PH_STOP:
+ case PROBCUT:
+ return select<Best>([&](){ return pos.see_ge(*cur, threshold); });
+
+ case QCAPTURE:
+ if (select<Best>([&](){ return depth > DEPTH_QS_RECAPTURES
+ || to_sq(*cur) == recaptureSquare; }))
+ return *(cur - 1);
+
+ // If we did not find any move and we do not try checks, we have finished
+ if (depth != DEPTH_QS_CHECKS)