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

Explain your choices

Answer first. Then compare your reasoning.

13 questions 0 got it 0 to review13 not marked

Defend

Choice, reason, cost, trigger

ChoiceReasonCostI would change it when
CountersAny size in O(1)Must follow undoA win is not a full line
Moves as historySmall, replayableOppositesPictures are needed at once
Mark in playWrong callers are seenOne argumentOnly one local caller, ever
Enum for statusOne eventNonePause, offer, resign
Cells as valuesNo behaviourNoneSquares with bonuses
No lockOne game, one threadNoneA server: one for each game

Which way to undo?

WorksKeep a copy of the board for each move
How
Nine pictures.
Limit
n squared for each move. For n = 1,000 a million squares a move.
Choose when
Small boards, user interfaces with immutable values.
StrongOpposites of the last move
How
Clear, uncount, give back the turn.
Limit
Each change needs an owner with an opposite.
Choose when
The base design.
BreaksSwitch the turn and clear the last square
How
Two lines in the screen.
Limit
The counts stay. After a win the turn is wrong.
Choose when
Never.