AlgoViz

Design tic-tac-toe

easy 70 min

Model a game everybody knows: marks on a grid, turns, a full line wins.

Watch lesson4:32

Agree on the scope

Ask what changes the design, then commit to a short list.

Agree

The scope in one minute

In

  • Any size, full line wins
  • Two marks, turns enforced
  • Undo, also after the end
  • No input or output inside

Out, and where it would go

  • Names and scores: a match around the game
  • Computer: a caller with choose
  • Screens: rows and status
  • Network: tokens in front of play

When they push for patterns

  1. Interviewer

    Would you not use the State pattern for the game status?

  2. You

    There is one event, a move, and three of the four states answer it in the same way: refused. An enum and one if say that in a line.

  3. Interviewer

    And if players may pause, offer a draw and resign?

  4. You

    Then there are four events with different answers in each state. At that point I would write a table of states and events first, and the classes if the table has many different cells.