Design tic-tac-toe
easy 70 minModel a game everybody knows: marks on a grid, turns, a full line wins.
Watch lesson4:32
How to approach it
What this question tests, where it gets hard, and how to spend the time.
Read the question
What this problem tests
Everybody can play it, so nobody is impressed by a program that works. It tests whether rules have owners, whether a wrong call can do harm, and how calmly you take the next three wishes.
Four moves
- 1
Ask about size and winning
These two decide the win check.
- 2
Give each rule an owner
Taken: board. Turn and end: game. Line: counts.
- 3
Write play
Questions, then changes, then the result: win before full.
- 4
Trace the bad cases
Wrong turn, taken, after the end, the winning ninth move.
Time
Spend the 45 minutes
| Minutes | Do | Have at the end |
|---|---|---|
| 0 to 4 | Questions | Any size, full line, undo |
| 4 to 9 | Owners of rules, rejected nouns | Four types |
| 9 to 15 | Class diagram | The pairs put and clear, add and remove |
| 15 to 28 | Code | Board, counts, game, about 70 lines |
| 28 to 33 | Trace | Win, draw, refusal, undo after a win |
| 33 to 45 | Wishes | Computer, k in a row, two phones |
Memory
SAND
S: Squares store
The board refuses a taken one and knows no rules.
A: Ask before act
All checks before all changes.
N: N on a line
Count, four lines at most, win before full.
D: Do has an undo
Each change has an opposite with the same owner.