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

Deep dives

Compare the options before you open them, then say which you would pick.

Dig

Where they go next, and your first sentence

They askFirst sentenceFull page
Faster win check?A move touches four lines, so I count.Win in O(1)
Redo, sharing a game?The list of moves is the truth.Undo and replay
A computer?5,478 positions: I can know them all.Computer player
Many games?One lock for each game, a short one for the list.Many games
New rules?Let me name the class that changes.New rules
k in a row?Counting forgets where, so I walk from the last move.Four in a row

Numbers

Five to have ready

WhatNumber
Ways to fill the board in order (9!)362,880
Games255,168
of them won by X, by O, drawn131,184, 77,904, 46,080
Positions that can be reached5,478
Positions, turned and mirrored ones as one765
All computed by the runnable block on the computer page.