Learning on Web Dev Open is free for all.

Interview Prep · Low Level DesignDesign a chess game
← Low Level Design

Design a chess game

Hard45 minFree, no account

Piece movement is the easy half. Check, castling and en passant are the design.


The question

Design the classes for a two-player chess game: board, pieces, moves, turns, and end conditions.

Handle castling, en passant, promotion, check and checkmate.

Functional
  • Validate and apply a move; reject illegal ones with a reason.
  • Detect check, checkmate and stalemate.
  • Castling, en passant, promotion, the fifty-move rule and threefold repetition.
  • Undo, and move history in algebraic notation.
Non-functional
  • Adding a new piece type must not require editing the board.
  • Rule checks must be fast enough for a move to validate instantly.
45:00Commit to an answer before you open the solution. Reading it first teaches you to recognise good answers, which is not the skill being tested.

Stuck?

0 of 3 hints taken

The worked solution

written by a person · not a grade

Score yourself

0 of 5 marked
  • Separated pseudo-legal movement from legality, with the filter written once30
  • Derived the full game state including castling rights and en passant20
  • Handled all three special moves correctly, promotion as an input20
  • Defined checkmate and stalemate precisely from the same computation15
  • Covered draws: fifty-move, repetition on full state, insufficient material15

We run no AI here and nothing on this page grades you. The score is yours, and the useful number is the one you get on the same problem a month from now, cold.

kept in this browser only