Bird
Raised Fist0

Which of the following code snippets correctly represents a basic move validation check for a rook in chess?

easy🧠 Conceptual Q12 of Q15
LLD - Design — Chess Game
Which of the following code snippets correctly represents a basic move validation check for a rook in chess?
A<code>if abs(start_row - end_row) == 1 and abs(start_col - end_col) == 1: return True else: return False</code>
B<code>if start_row == end_row or start_col == end_col: return True else: return False</code>
C<code>if abs(start_row - end_row) == abs(start_col - end_col): return True else: return False</code>
D<code>if end_row == start_row + 2 or end_col == start_col + 2: return True else: return False</code>
Step-by-Step Solution
Solution:
  1. Step 1: Recall rook movement rules

    A rook moves any number of squares along a row or column, so either row or column must be the same.
  2. Step 2: Match code to rules

    if start_row == end_row or start_col == end_col: return True else: return False checks if start and end share the same row or column, which matches rook moves.
  3. Final Answer:

    if start_row == end_row or start_col == end_col: return True else: return False -> Option B
  4. Quick Check:

    Rook moves = same row or column [OK]
Quick Trick: Rook moves straight: same row or same column [OK]
Common Mistakes:
MISTAKES
  • Confusing rook moves with diagonal moves
  • Using absolute difference for rook incorrectly
  • Checking only fixed steps instead of any distance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes