- // Case 1: Stalemate
- if ( stm == BLACK
- && !(k_attacks<BLACK>() & ~(k_attacks<WHITE>() | p_attacks())))
- return DRAW;
-
- // Case 2: King can capture undefended pawn
- if ( stm == BLACK
- && (k_attacks<BLACK>() & psq & ~k_attacks<WHITE>()))
- return DRAW;
-
- // Case 3: Black king in front of white pawn
- if ( bksq == psq + DELTA_N
- && rank_of(psq) < RANK_7)
- return DRAW;
-
- // Case 4: White king in front of pawn and black has opposition
- if ( stm == WHITE
- && wksq == psq + DELTA_N
- && bksq == wksq + DELTA_N + DELTA_N
- && rank_of(psq) < RANK_5)
- return DRAW;
-
- // Case 5: Stalemate with rook pawn
- if ( bksq == SQ_A8
- && file_of(psq) == FILE_A)
- return DRAW;
-
- return UNKNOWN;
- }
-
- template<Color Us>
- Result KPKPosition::classify(const Result db[]) const {
-
- // White to Move: If one move leads to a position classified as RESULT_WIN,
- // the result of the current position is RESULT_WIN. If all moves lead to
- // positions classified as RESULT_DRAW, the current position is classified
- // RESULT_DRAW otherwise the current position is classified as RESULT_UNKNOWN.
- //
- // Black to Move: If one move leads to a position classified as RESULT_DRAW,
- // the result of the current position is RESULT_DRAW. If all moves lead to
- // positions classified as RESULT_WIN, the position is classified RESULT_WIN.
- // Otherwise, the current position is classified as RESULT_UNKNOWN.
+ // 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);