-/// MovePicker::init_phase_table() initializes the PhaseTable[],
-/// MainSearchPhaseIndex, EvasionPhaseIndex, QsearchWithChecksPhaseIndex
-/// and QsearchWithoutChecksPhaseIndex variables. It is only called once
-/// during program startup, and never again while the program is running.
-
-void MovePicker::init_phase_table() {
-
- int i = 0;
-
- // Main search
- MainSearchPhaseIndex = i - 1;
- PhaseTable[i++] = PH_TT_MOVE;
- PhaseTable[i++] = PH_MATE_KILLER;
- PhaseTable[i++] = PH_GOOD_CAPTURES;
- // PH_KILLER_1 and PH_KILLER_2 are not yet used.
- // PhaseTable[i++] = PH_KILLER_1;
- // PhaseTable[i++] = PH_KILLER_2;
- PhaseTable[i++] = PH_NONCAPTURES;
- PhaseTable[i++] = PH_BAD_CAPTURES;
- PhaseTable[i++] = PH_STOP;
-
- // Check evasions
- EvasionsPhaseIndex = i - 1;
- PhaseTable[i++] = PH_EVASIONS;
- PhaseTable[i++] = PH_STOP;
-
- // Quiescence search with checks
- QsearchWithChecksPhaseIndex = i - 1;
- PhaseTable[i++] = PH_QCAPTURES;
- PhaseTable[i++] = PH_QCHECKS;
- PhaseTable[i++] = PH_STOP;
-
- // Quiescence search without checks
- QsearchWithoutChecksPhaseIndex = i - 1;
- PhaseTable[i++] = PH_QCAPTURES;
- PhaseTable[i++] = PH_STOP;
+ while (true)
+ {
+ while (cur == endMoves)
+ generate_next_stage();
+
+ switch (stage) {
+
+ case MAIN_SEARCH: case EVASION: case QSEARCH_0: case QSEARCH_1: case PROBCUT:
+ ++cur;
+ return ttMove;
+
+ case CAPTURES_S1:
+ move = pick_best(cur++, endMoves);
+ if (move != ttMove)
+ {
+ if (pos.see_sign(move) >= VALUE_ZERO)
+ return move;
+
+ // Losing capture, move it to the tail of the array
+ *endBadCaptures-- = move;
+ }
+ break;
+
+ case KILLERS_S1:
+ move = *cur++;
+ if ( move != MOVE_NONE
+ && move != ttMove
+ && pos.pseudo_legal(move)
+ && !pos.capture(move))
+ return move;
+ break;
+
+ case QUIETS_1_S1: case QUIETS_2_S1:
+ move = *cur++;
+ if ( move != ttMove
+ && move != killers[0]
+ && move != killers[1]
+ && move != killers[2]
+ && move != killers[3])
+ return move;
+ break;
+
+ case BAD_CAPTURES_S1:
+ return *cur--;
+
+ case EVASIONS_S2: case CAPTURES_S3: case CAPTURES_S4:
+ move = pick_best(cur++, endMoves);
+ if (move != ttMove)
+ return move;
+ break;
+
+ case CAPTURES_S5:
+ move = pick_best(cur++, endMoves);
+ if (move != ttMove && pos.see(move) > captureThreshold)
+ return move;
+ break;
+
+ case CAPTURES_S6:
+ move = pick_best(cur++, endMoves);
+ if (to_sq(move) == recaptureSquare)
+ return move;
+ break;
+
+ case QUIET_CHECKS_S3:
+ move = *cur++;
+ if (move != ttMove)
+ return move;
+ break;
+
+ case STOP:
+ return MOVE_NONE;
+
+ default:
+ assert(false);
+ }
+ }