Design tic-tac-toe
easy 70 minModel 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:
rowsandstatus - Network: tokens in front of
play
When they push for patterns
Interviewer
Would you not use the State pattern for the game status?
You
There is one event, a move, and three of the four states answer it in the same way: refused. An enum and one
ifsay that in a line.Interviewer
And if players may pause, offer a draw and resign?
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.