-/// next_move() is the most important method of the MovePicker class. It returns
-/// a new pseudo legal move every time it is called, until there are no more moves
-/// left. It picks the move with the biggest value from a list of generated moves
-/// taking care not to return the ttMove if it has already been searched.
-
-Move MovePicker::next_move() {
-
- Move move;
-
- while (true)
- {
- while (cur == endMoves && stage != STOP)
- generate_next_stage();
-
- switch (stage) {
-
- case MAIN_SEARCH: case EVASION: case QSEARCH_WITH_CHECKS:
- case QSEARCH_WITHOUT_CHECKS: case PROBCUT:
- ++cur;
- return ttMove;
-
- case GOOD_CAPTURES:
- 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:
- move = *cur++;
- if ( move != MOVE_NONE
- && move != ttMove
- && pos.pseudo_legal(move)
- && !pos.capture(move))
- return move;
- break;
-
- case QUIET:
- move = *cur++;
- if ( move != ttMove
- && move != killers[0]
- && move != killers[1]
- && move != killers[2])
- return move;
- break;
-
- case BAD_CAPTURES:
- return *cur--;
-
- case ALL_EVASIONS: case QCAPTURES_1: case QCAPTURES_2:
- move = pick_best(cur++, endMoves);
- if (move != ttMove)
- return move;
- break;
-
- case PROBCUT_CAPTURES:
- move = pick_best(cur++, endMoves);
- if (move != ttMove && pos.see(move) > threshold)
- return move;
- break;
-
- case RECAPTURES:
- move = pick_best(cur++, endMoves);
- if (to_sq(move) == recaptureSquare)
- return move;
- break;
-
- case CHECKS:
- move = *cur++;
- if (move != ttMove)
- return move;
- break;
-
- case STOP:
- return MOVE_NONE;
-
- default:
- assert(false);
- }
- }
-}