- if ( square_distance(wksq, bksq) <= 1 || wksq == psq || bksq == psq
- || (us == WHITE && (StepAttacksBB[PAWN][psq] & bksq)))
- return res = INVALID;
-
- if (us == WHITE)
- {
- // Immediate win if pawn can be promoted without getting captured
- if ( rank_of(psq) == RANK_7
- && wksq != psq + DELTA_N
- && ( square_distance(bksq, psq + DELTA_N) > 1
- ||(StepAttacksBB[KING][wksq] & (psq + DELTA_N))))
- return res = WIN;
- }
- // Immediate draw if is stalemate or king captures undefended pawn
- else if ( !(StepAttacksBB[KING][bksq] & ~(StepAttacksBB[KING][wksq] | StepAttacksBB[PAWN][psq]))
- || (StepAttacksBB[KING][bksq] & psq & ~StepAttacksBB[KING][wksq]))
- return res = DRAW;
-
- return res = UNKNOWN;
+ if ( distance(ksq[WHITE], ksq[BLACK]) <= 1
+ || ksq[WHITE] == psq
+ || ksq[BLACK] == psq
+ || (stm == WHITE && (PawnAttacks[WHITE][psq] & ksq[BLACK])))
+ result = INVALID;
+
+ // Immediate win if a pawn can be promoted without getting captured
+ else if ( stm == WHITE
+ && rank_of(psq) == RANK_7
+ && ksq[stm] != psq + NORTH
+ && ( distance(ksq[~stm], psq + NORTH) > 1
+ || (PseudoAttacks[KING][ksq[stm]] & (psq + NORTH))))
+ result = WIN;
+
+ // Immediate draw if it is a stalemate or a king captures undefended pawn
+ else if ( stm == BLACK
+ && ( !(PseudoAttacks[KING][ksq[stm]] & ~(PseudoAttacks[KING][ksq[~stm]] | PawnAttacks[~stm][psq]))
+ || (PseudoAttacks[KING][ksq[stm]] & psq & ~PseudoAttacks[KING][ksq[~stm]])))
+ result = DRAW;
+
+ // Position will be classified later
+ else
+ result = UNKNOWN;