- switch(PhaseTable[phaseIndex]) {
-
- case PH_GOOD_CAPTURES:
- assert(!pos->is_check());
- assert(movesPicked >= 0);
- while(movesPicked < numOfMoves) {
- bestScore = -10000000;
- bestIndex = -1;
- for(int i = movesPicked; i < numOfMoves; i++) {
- if(moves[i].score < 0) {
- // Losing capture, move it to the badCaptures[] array
- assert(numOfBadCaptures < 63);
- badCaptures[numOfBadCaptures++] = moves[i];
- moves[i--] = moves[--numOfMoves];
- }
- else if(moves[i].score > bestScore) {
- bestIndex = i;
- bestScore = moves[i].score;
- }
- }
- if(bestIndex != -1) { // Found a good capture
- move = moves[bestIndex].move;\r
- moves[bestIndex] = moves[movesPicked++];
- if(move != ttMove && move != mateKiller &&
- pos->move_is_legal(move, pinned))
- return move;
- }
- }
- break;
-
- case PH_NONCAPTURES:
- assert(!pos->is_check());
- assert(movesPicked >= 0);
- while(movesPicked < numOfMoves) {
- bestScore = -10000000;
-
- // If this is a PV node or we have only picked a few moves, scan
- // the entire move list for the best move. If many moves have already
- // been searched and it is not a PV node, we are probably failing low
- // anyway, so we just pick the first move from the list.
- if(!All_zero && (pvNode || movesPicked < 12)) {
- bestIndex = -1;
- for(int i = movesPicked; i < numOfMoves; i++)
- if(moves[i].score > bestScore) {
- bestIndex = i;
- bestScore = moves[i].score;
- }
- }
- else
- bestIndex = movesPicked;
-
- if(bestIndex != -1) {
- move = moves[bestIndex].move;\r
- moves[bestIndex] = moves[movesPicked++];
- if(move != ttMove && move != mateKiller &&
- pos->move_is_legal(move, pinned))
- return move;
- }
- }
- break;
-
- case PH_EVASIONS:
- assert(pos->is_check());
- assert(movesPicked >= 0);
- while(movesPicked < numOfMoves) {
- bestScore = -10000000;
- bestIndex = -1;
- for(int i = movesPicked; i < numOfMoves; i++)
- if(moves[i].score > bestScore) {
- bestIndex = i;
- bestScore = moves[i].score;
- }
-
- if(bestIndex != -1) {
- move = moves[bestIndex].move;\r
- moves[bestIndex] = moves[movesPicked++];
- return move;
- }
- }
- break;
-
- case PH_BAD_CAPTURES:
- assert(!pos->is_check());
- assert(badCapturesPicked >= 0);
- // It's probably a good idea to use SEE move ordering here, instead
- // of just picking the first move. FIXME
- while(badCapturesPicked < numOfBadCaptures) {
- move = badCaptures[badCapturesPicked++].move;
- if(move != ttMove && move != mateKiller &&
- pos->move_is_legal(move, pinned))
- return move;
- }
- break;
-
- case PH_QCAPTURES:
- assert(!pos->is_check());
- assert(movesPicked >= 0);
- while(movesPicked < numOfMoves) {
- bestScore = -10000000;
- if(movesPicked < 4) {
- bestIndex = -1;
- for(int i = movesPicked; i < numOfMoves; i++)
- if(moves[i].score > bestScore) {
- bestIndex = i;
- bestScore = moves[i].score;