namespace {
enum Stages {
- MAIN_SEARCH, CAPTURES_INIT, GOOD_CAPTURES, KILLERS, COUNTERMOVE, QUIET_INIT, QUIET, BAD_CAPTURES,
+ MAIN_SEARCH, CAPTURES_INIT, GOOD_CAPTURES, KILLER0, KILLER1, COUNTERMOVE, QUIET_INIT, QUIET, BAD_CAPTURES,
EVASION, EVASIONS_INIT, ALL_EVASIONS,
- PROBCUT, PROBCUT_INIT, PROBCUT_CAPTURES,
+ PROBCUT, PROBCUT_CAPTURES_INIT, PROBCUT_CAPTURES,
QSEARCH, QCAPTURES_INIT, QCAPTURES, QCHECKS, QSEARCH_RECAPTURES, QRECAPTURES
};
return ttMove;
case CAPTURES_INIT:
+ case PROBCUT_CAPTURES_INIT:
+ case QCAPTURES_INIT:
+ case QSEARCH_RECAPTURES:
endBadCaptures = cur = moves;
endMoves = generate<CAPTURES>(pos, cur);
score<CAPTURES>();
++stage;
- /* fallthrough */
+
+ // Rebranch at the top of the switch via a recursive call
+ return next_move(skipQuiets);
case GOOD_CAPTURES:
while (cur < endMoves)
*endBadCaptures++ = move;
}
}
-
++stage;
- move = killers[0]; // First killer move
- if ( move != MOVE_NONE
- && move != ttMove
- && pos.pseudo_legal(move)
- && !pos.capture(move))
- return move;
/* fallthrough */
- case KILLERS:
- ++stage;
- move = killers[1]; // Second killer move
- if ( move != MOVE_NONE
- && move != ttMove
- && pos.pseudo_legal(move)
- && !pos.capture(move))
- return move;
+ case KILLER0:
+ case KILLER1:
+ do
+ {
+ move = killers[++stage - KILLER1];
+ if ( move != MOVE_NONE
+ && move != ttMove
+ && pos.pseudo_legal(move)
+ && !pos.capture(move))
+ return move;
+ } while (stage <= KILLER1);
/* fallthrough */
case COUNTERMOVE:
/* fallthrough */
case QUIET:
- while ( cur < endMoves
- && (!skipQuiets || cur->value >= VALUE_ZERO))
- {
- move = *cur++;
-
- if ( move != ttMove
- && move != killers[0]
- && move != killers[1]
- && move != countermove)
- return move;
- }
+ if (!skipQuiets)
+ while (cur < endMoves)
+ {
+ move = *cur++;
+
+ if ( move != ttMove
+ && move != killers[0]
+ && move != killers[1]
+ && move != countermove)
+ return move;
+ }
++stage;
cur = moves; // Point to beginning of bad captures
/* fallthrough */
}
break;
- case PROBCUT_INIT:
- cur = moves;
- endMoves = generate<CAPTURES>(pos, cur);
- score<CAPTURES>();
- ++stage;
- /* fallthrough */
-
case PROBCUT_CAPTURES:
while (cur < endMoves)
{
}
break;
- case QCAPTURES_INIT:
- cur = moves;
- endMoves = generate<CAPTURES>(pos, cur);
- score<CAPTURES>();
- ++stage;
- /* fallthrough */
-
case QCAPTURES:
while (cur < endMoves)
{
}
break;
- case QSEARCH_RECAPTURES:
- cur = moves;
- endMoves = generate<CAPTURES>(pos, cur);
- ++stage;
- /* fallthrough */
-
case QRECAPTURES:
while (cur < endMoves)
{