🔴 CONNECT FOUR

Drop your counters and get four in a row — the computer is trying to stop you

← Back to Fun Time
You
0
Computer
0
Draws
0

⌨️ Controls

  • aim above a column
  • Space, Enter or drop a counter
  • Clicking or tapping a column works too
  • R next round  •  P pause
  • 🎮 Xbox controller? Just plug it in or pair it — the stick and D-pad are the arrow keys, A is SPACE, Menu pauses and View starts again

🎯 How to play

  • You are the solid counters; the computer is the rings.
  • Counters fall to the lowest free hole in the column you pick.
  • Get four in a row — across, down or diagonally.
  • The computer replies straight away, so every drop is a whole turn.

🤖 How the computer thinks

  • 1. If it can make four, it does.
  • 2. If you are about to make four, it blocks you.
  • 3. Otherwise it plays as near the middle as it can — the middle column is part of more possible lines than any other.
  • 4. And it never drops a counter that lets you win by landing on top of it.
  • To beat it, build two threats at once. It can only block one!

🧑‍💻 For young coders: build this game yourself

This 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.