Drop your counters and get four in a row — the computer is trying to stop you
← 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/connect4-rules.js | The rules, the win check and the computer | dropRow, countInDirection, isWinAt, computerColumn |
| lib/connect4-draw.js | Painting the holes and counters | drawCounter, drawDropMarker, columnAtPixel |
| lib/connect4-main.js | The glue: clicks, keyboard, the scoreboard | doAction, connectBoard, updateScoreboard |
💡 The big idea: you never have to search the whole board for four in a row. Only the counter that was just dropped can have made a new line, so you look outwards from that one square — in four directions, both ways. That trick keeps the check fast no matter how big the board gets.
🛠️ Want to be walked through it? Build Connect Four Yourself takes you through the key functions one step at a time and tests each one you write. There is a Python version too.