- // 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;
-
- // Case 3: Black king in front of white pawn
- if ( blackKingSquare == pawnSquare + DELTA_N
- && square_rank(pawnSquare) < RANK_7)
- return RESULT_DRAW;
-
- // Case 4: White king in front of pawn and black has opposition
- if ( whiteKingSquare == pawnSquare + DELTA_N
- && blackKingSquare == pawnSquare + DELTA_N + DELTA_N + DELTA_N
- && square_rank(pawnSquare) < RANK_5
- && sideToMove == WHITE)
- return RESULT_DRAW;
-
- // Case 5: Stalemate with rook pawn
- if ( blackKingSquare == SQ_A8
- && square_file(pawnSquare) == FILE_A)
- return RESULT_DRAW;
-
- return RESULT_UNKNOWN;
- }
-
- Result KPKPosition::classify(int index, Result db[]) {
-
- from_index(index);
- db[index] = (sideToMove == WHITE ? classify_white(db) : classify_black(db));
- return db[index];
- }
-
- Result KPKPosition::classify_white(const Result db[]) {
+ // Black to move: If one move leads to a position classified as DRAW, the result
+ // of the current position is DRAW. If all moves lead to positions classified
+ // as WIN, the position is classified as WIN, otherwise the current position is
+ // classified as UNKNOWN.
+ const Result Good = (stm == WHITE ? WIN : DRAW);
+ const Result Bad = (stm == WHITE ? DRAW : WIN);