- while (true)
- {
- while (curMove == lastMove)
- next_phase();
-
- switch (phase) {
-
- case TT_MOVE_S1: case TT_MOVE_S2: case TT_MOVE_S3: case TT_MOVE_S4: case TT_MOVE_S5:
- curMove++;
- return ttMove;
-
- case CAPTURES_S1:
- move = pick_best(curMove++, lastMove)->move;
- if (move != ttMove)
- {
- assert(captureThreshold <= 0); // Otherwise we cannot use see_sign()
-
- int seeScore = pos.see_sign(move);
- if (seeScore >= captureThreshold)
- return move;
-
- // Losing capture, move it to the tail of the array
- (--badCaptures)->move = move;
- badCaptures->score = seeScore;
- }
- break;
-
- case KILLERS_S1:
- move = (curMove++)->move;
- if ( move != MOVE_NONE
- && pos.is_pseudo_legal(move)
- && move != ttMove
- && !pos.is_capture(move))
- return move;
- break;
-
- case QUIETS_1_S1:
- case QUIETS_2_S1:
- move = (curMove++)->move;
- if ( move != ttMove
- && move != killers[0].move
- && move != killers[1].move)
- return move;
- break;
-
- case BAD_CAPTURES_S1:
- move = pick_best(curMove++, lastMove)->move;
- return move;
-
- case EVASIONS_S2:
- case CAPTURES_S3:
- case CAPTURES_S4:
- move = pick_best(curMove++, lastMove)->move;
- if (move != ttMove)
- return move;
- break;
-
- case CAPTURES_S5:
- move = pick_best(curMove++, lastMove)->move;
- if (move != ttMove && pos.see(move) > captureThreshold)
- return move;
- break;
-
- case CAPTURES_S6:
- move = pick_best(curMove++, lastMove)->move;
- if (to_sq(move) == recaptureSquare)
- return move;
- break;
-
- case QUIET_CHECKS_S3:
- move = (curMove++)->move;
- if (move != ttMove)
- return move;
- break;
-
- case STOP_S1: case STOP_S2: case STOP_S3: case STOP_S4: case STOP_S5: case STOP_S6:
- return MOVE_NONE;