Bird
0
0

How would you combine en passant logic with move history to ensure correct validation in a chess engine?

hard📝 Trade-off Q9 of 15
LLD - Design — Chess Game
How would you combine en passant logic with move history to ensure correct validation in a chess engine?
AStore the last move and check if it was a two-step pawn advance adjacent to the capturing pawn
BStore all pawn positions and check if any moved two steps in the last 10 moves
CIgnore move history and allow en passant anytime a pawn is adjacent
DTrack only captures and ignore pawn moves
Step-by-Step Solution
Solution:
  1. Step 1: Understand en passant timing dependency

    En passant is only valid immediately after an opponent pawn moves two squares forward.
  2. Step 2: Use move history to validate

    Storing the last move allows checking if it was a two-step pawn advance adjacent to the capturing pawn.
  3. Final Answer:

    Store the last move and check if it was a two-step pawn advance adjacent to the capturing pawn -> Option A
  4. Quick Check:

    En passant validation with move history = A [OK]
Quick Trick: Check only last move for en passant validity [OK]
Common Mistakes:
  • Checking too many past moves
  • Ignoring move history
  • Tracking only captures misses en passant

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes