Chess Game – Low Level Design Interview Practice
Practise the Chess Game low level design problem the way an LLD round actually runs. You are asked for requirements first, then a class model, and then to extend the design when a new requirement lands part way through – the follow-up that separates a design that was memorised from one that was understood.
The round checks the things interviewers grade: whether your classes carry single responsibilities, whether you reached for a design pattern or reinvented one, whether the design absorbs a new requirement without rewriting what exists, and whether you can explain a trade-off out loud. Feedback covers class modelling, SOLID principles, use of patterns, extensibility and communication.
What this question is really testing
Polymorphism done properly, and undo. Move legality belongs to the piece; game legality - check, turn order - belongs above it.
Requirements to establish first
- An 8x8 board with the six piece types and their movement rules.
- Validate a move: the piece's own rule, the path, the destination occupant, and whether it leaves your king in check.
- Alternate turns and detect check, checkmate and stalemate.
- Support castling, en passant and promotion - the three rules that break a naive model.
- Maintain move history, and support undo.
Core classes
- Piece – Abstract. Each subclass answers "can I move from here to there on this board?" for its own geometry.
- Board / Cell – The 8x8 grid and what occupies each square.
- Move – From, to, piece, captured piece, and the flags castling and en passant need. Rich enough to be undone.
- Game – Turn order, check detection and the end conditions.
- Player – Colour, and whether it is a human or an engine.
Design patterns that apply
- Command – Undo. A Move that knows how to reverse itself is what makes history more than a log, and it is what the interviewer is probing with "now add takeback".
- Strategy – Per-piece movement, if you prefer composition to a subclass per piece - and the choice between the two is worth defending out loud.
- Factory – Setting up the opening position, and promotion creating a new piece.
Follow-up questions to expect
- Castling moves two pieces and depends on history - neither king nor rook may have moved. Where does that live?
- En passant is legal for exactly one move after the trigger. What in your model expires?
- Add threefold repetition. What does your move history need to store that it does not today?
Where candidates lose marks
- Check detection inside Piece, which gives a bishop an opinion about the king.
- A Move that stores only from and to, so undo cannot restore a captured piece or a castled rook.
- A switch on piece type instead of polymorphism - the exact thing the question tests.