- bool next_iteration() {
- KPKPosition p;
- int previousUnknownCount = UnknownCount;
-
- for(int i = 0; i < IndexMax; i++)
- if(Bitbase[i] == RESULT_UNKNOWN) {
- p.from_index(i);
+ // The position is an immediate win if it is white to move and the
+ // white pawn can be promoted without getting captured.
+ if ( square_rank(pawnSquare) == RANK_7
+ && sideToMove == WHITE
+ && whiteKingSquare != pawnSquare + DELTA_N
+ && ( square_distance(blackKingSquare, pawnSquare + DELTA_N) > 1
+ || bit_is_set(wk_attacks(), pawnSquare + DELTA_N)))
+ return RESULT_WIN;
+
+ // Check for known draw positions
+ //
+ // Case 1: Stalemate
+ if ( sideToMove == BLACK
+ && (bk_attacks() & ~(wk_attacks() | pawn_attacks())) == EmptyBoardBB)
+ return RESULT_DRAW;
+
+ // Case 2: King can capture pawn
+ if ( sideToMove == BLACK
+ && bit_is_set(bk_attacks(), pawnSquare) && !bit_is_set(wk_attacks(), pawnSquare))
+ return RESULT_DRAW;