Chess
Design a chess game with polymorphic pieces, move validation, turn handling and check, checkmate and stalemate detection.
Requirements
Chess is large, so the first job in the interview is to cut it down. Say the cuts out loud.
Clarifying questions:
- Two human players on one screen, or a network game? (One process, two players taking turns.)
- Do we need every rule? (No. See the scope below.)
- Do we need a computer opponent or a clock? (No.)
- How are moves entered? (As two squares in algebraic form, like
e2toe4.)
Scope for this lesson:
- 8x8 board with the standard starting position.
- Six piece types, each with its own movement rule.
- White moves first; players alternate.
- A move is legal if the piece can reach the target and the move does not leave the mover's own king in check (the king is attacked and could be captured next move).
- After each move report the state: ongoing, check, checkmate (in check with no legal move) or stalemate (not in check but no legal move, a draw).
Out of scope, and worth mentioning as extensions: castling, en passant, pawn promotion, draw by repetition or the fifty move rule, a clock, and move notation like Nf3.
1 of 10