Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

Launch price

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year, or $19.50 for your first year with LAUNCH50, ends 1 Nov, 18:30 UTC.

See plansStart free instead

Module 10 · System Design · Six more low-level rounds

Design chess (pieces that know their own moves)

Design Chess
Design Chess · Open board

Pieces that answer one question, legal moves as pseudo-legal minus check, the move as a command, and two players pressing at once.

Before you start. You need three lessons. Has-a beats is-a (composition over inheritance) showed a class holding another class as a part (composition) and many classes answering one call in their own way. Tell everyone who cares (Observer and State) showed a state machine: a thing that is always in exactly one named state and moves between them on events. Design a parking lot (the first whole round) showed the shape of a whole interview round, questions first, then entities, then one tricky interaction. You do not need to play chess.

Lesson 49 of 73 in System Design

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year, or $19.50 for your first year with LAUNCH50, ends 1 Nov, 18:30 UTC.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • May 1997: a machine that had to know every legal move
  • The obvious way: one function with a long if-chain
  • Each piece answers moves: polymorphism
  • The board knows where everyone stands
  • Move validation: the move that exposes your own king
  • A move is an object: the command pattern
  • Game state: whose turn it is, and what is happening

Terms it explains: polymorphism, board, file, rank, pinned, move validation, command pattern, game state, chess clock, expected move number.

Review System Design