Three in a row — against a computer that never loses
← Back to Fun TimeThis game is split into small library files inside funtime/lib/, and every function has a comment saying exactly what goes in, what comes out, and the algorithm in plain English. Empty any function out, read its comment, and write it yourself.
| File | What it does | Good functions to try re-writing |
|---|---|---|
| lib/tictactoe-rules.js | The rules, and the computer's brain | winningLine, isDraw, computerMove |
| lib/tictactoe-draw.js | Painting the grid, the Xs and the Os | drawMark, drawWinningLine, squareAtPixel |
| lib/tictactoe-main.js | The glue: clicks, keyboard, the scoreboard | doAction, connectBoard, updateScoreboard |
💡 The big idea: the computer plays by trying a move on a copy of the board and seeing what happens. That is why placeMark returns a new board instead of changing the old one — it lets you imagine a move without making it.
🛠️ Want to be walked through it? Build Tic-Tac-Toe Yourself takes you through the key functions one step at a time and tests each one you write. There is a Python version too.