A chess game is a strategic board game played between two players on a square board with 64 squares arranged in an 8×8 grid.
Each player controls an army of 16 pieces and takes turns moving them according to specific rules, with the goal of trapping the opponent’s king in a position where it cannot escape. This is called checkmate.
Loading simulation...
In this chapter, we will explore the low-level design of a chess game in detail.
Let's start by clarifying the requirements:
Before starting any design, it's important to ask thoughtful questions to uncover hidden assumptions, clarify ambiguities, and define the system's scope.
Here is an example of how a discussion between the candidate and the interviewer might unfold:
Candidate: "Are we building a standard two-player chess game on an 8x8 board with all standard piece types?"
Interviewer: "Yes, standard chess rules with two players, one controlling white pieces and the other controlling black."
Candidate: "Should we support all standard piece movements, including special moves like castling, en passant, and pawn promotion?"
Interviewer: "Yes, implement all standard movement rules. Castling, en passant, and pawn promotion should all be supported."
Candidate: "How should we handle check and checkmate? Should the system automatically detect when a king is in check and prevent illegal moves that leave the king exposed?"
Interviewer: "Yes, the system must detect check, prevent moves that would leave your own king in check, and detect checkmate and stalemate conditions to end the game."
Candidate: "Should we support move history so we can track what happened during the game?"
Interviewer: "Yes, maintain a history of all moves made. This is also needed for en passant detection since it depends on the previous move."
Candidate: "Should we support game termination by resignation, or only through checkmate and stalemate?"
Interviewer: "Support resignation as well. Either player should be able to resign at any time."
After gathering the details, we can summarize the key system requirements.