- else 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))))
- result = 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]))
+ // Immediate win if a pawn can be promoted without getting captured
+ else if ( us == WHITE
+ && rank_of(psq) == RANK_7
+ && ksq[us] != psq + NORTH
+ && ( distance(ksq[~us], psq + NORTH) > 1
+ || (PseudoAttacks[KING][ksq[us]] & (psq + NORTH))))
+ result = WIN;
+
+ // Immediate draw if it is a stalemate or a king captures undefended pawn
+ else if ( us == BLACK
+ && ( !(PseudoAttacks[KING][ksq[us]] & ~(PseudoAttacks[KING][ksq[~us]] | PawnAttacks[~us][psq]))
+ || (PseudoAttacks[KING][ksq[us]] & psq & ~PseudoAttacks[KING][ksq[~us]])))