Bird
0
0

Which code snippet correctly checks if an en passant move is possible in a chess game for an opponent pawn landing to the right?

easy📝 Conceptual Q12 of 15
LLD - Design — Chess Game
Which code snippet correctly checks if an en passant move is possible in a chess game for an opponent pawn landing to the right?
Aif pawn.just_moved_two_squares and opponent_pawn.position == pawn.position + (1, 0): allow_en_passant()
Bif pawn.just_moved_two_squares and opponent_pawn.position == pawn.position + (0, -1): allow_en_passant()
Cif pawn.just_moved_two_squares and opponent_pawn.position == pawn.position + (0, 1): allow_en_passant()
Dif pawn.just_moved_two_squares and opponent_pawn.position == pawn.position + (-1, 0): allow_en_passant()
Step-by-Step Solution
Solution:
  1. Step 1: Understand en passant position logic

    En passant capture happens when an opponent's pawn moves two squares forward and lands beside your pawn horizontally.
  2. Step 2: Identify correct position offset

    The opponent pawn must be exactly one square horizontally adjacent (x+1 or x-1), so position + (1, 0) is correct for right side.
  3. Final Answer:

    if pawn.just_moved_two_squares and opponent_pawn.position == pawn.position + (1, 0): allow_en_passant() -> Option A
  4. Quick Check:

    En passant horizontal check = if pawn.just_moved_two_squares and opponent_pawn.position == pawn.position + (1, 0): allow_en_passant() [OK]
Quick Trick: En passant checks horizontal adjacency after two-step pawn move [OK]
Common Mistakes:
  • Checking vertical instead of horizontal adjacency
  • Using wrong coordinate offsets
  • Ignoring the two-square move condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes