Connect Four — 6×7 (classic) vs Ordenador
Connect Four is a classic two-player game. Red moves first; Yellow responds.
On your turn you choose a column. Your disc falls by gravity to the lowest free cell of that column — you never choose the row.
The first player to line up four discs in a row — horizontal, vertical or diagonal — wins immediately.
If the board fills up with no line of four, it is a draw.
Boards: 6×7 (classic) (6 rows × 7 columns, the classic) · 7×8 (large) (7 rows × 8 columns, more room).
You pick the column; the disc falls to the bottom. Four red discs in a row complete a horizontal line — and win.
The game in one sentence. Connect Four is a perfect-information, zero-sum game on a vertical grid where gravity constrains where each disc lands. Few rules, but a beautiful laboratory for threats, parity and game-tree search.
Mathematical ideas:
• Constrained moves — only 7 (or 8) moves are ever available, one per non-full column; gravity removes the row as a free choice.
• Game-tree search — minimax with α-β pruning; the full 6×7 tree has ~4.5×10¹² reachable positions.
• Threats and double threats — a "threat" is a cell that would complete a four; two threats stacked in one column, or two on the same row, can be unstoppable.
• Parity — who is forced to play each square is decided by how many discs sit below it (odd/even threat theory).
Connect Four is a solved game. On the standard 6×7 board the first player wins with perfect play by opening in the centre column (Victor Allis and James Dow Allen, independently, 1988). Opening on an edge column loses; the centre is worth gold because it participates in the most possible lines.
The pedagogical core: think one threat ahead. Beginners only block the opponent's immediate three-in-a-row. They discover that:
• The centre column belongs to more potential fours than any other → grab it.
• Creating two threats at once wins, because the opponent can only block one.
• Odd/even threats: as first player, an odd-row threat (counting from the bottom) tends to win; the second player wants even threats.
• Filling a column can force the opponent to hand you the square right under your threat.
To discuss in class:
• Why is the centre column the strongest opening?
• How many distinct columns can you ever choose from? (Compare with chess or Go.)
• What changes on the larger 7×8 board — more room to build threats, or more room to defend?
• If the first player always wins on 6×7, why is the game still fun? (Humans don't play perfectly.)
Hard-mode AI: minimax with α-β pruning to depth 5 (Hard) or 3 (Easy). Evaluation scores every aligned window of four by how many of each player's discs it holds (three-in-a-row ≫ two-in-a-row), weights opponent threats more heavily so it blocks, and adds a bonus for the centre column. A solid school-level opponent; an attentive human beats it.
Variants and extensions: Pop Out (discs can be removed from the bottom), Power Up, 3-D Connect Four, and larger boards like the 7×8 here. The theory of threats and zugzwang carries over directly.