Connect Four Online Game
Play Connect Four online! Drop colored discs and be the first to connect four in a row. Challenge a friend or play against AI.
Play Connect Four online! Drop colored discs and be the first to connect four in a row. Challenge a friend or play against AI.
Connect Four is a two-player game played on a 7-column, 6-row vertical grid. Players take turns dropping colored tokens into columns; tokens stack from the bottom up. The first player to align four tokens horizontally, vertically, or diagonally wins. The game was published commercially by Milton Bradley in 1974 but the underlying rules are older.
Connect Four is solved: with perfect play, the first player wins. The proof was completed in 1988. In practice, most players don't play perfectly, so games are often interesting and competitive. The game is more strategic than Tic-Tac-Toe — the much larger state space (4.5 trillion possible positions) supports deep tactics around forks, threats, and column control.
This implementation offers two-player and single-player against AI. AI difficulty is configurable: random (easy), heuristic-based (medium), and search-based with depth limit (hard). At hard difficulty, the AI plays well but not perfectly — perfect play would require a much deeper search than reasonable in a browser.
Connect Four scales nicely between casual and serious. Quick games for entertainment, longer thoughtful games for strategy practice. The deeper-than-Tic-Tac-Toe game tree means there's genuine room for strategic improvement over time.
Two-player play is also a solid social game. Easy to learn, hard to master, satisfying to win. Good for relaxed time with friends or family — accessible to children but interesting to adults.
Drop tokens into columns, get four in a row.
Game state: a 7×6 array tracking each cell's color (red, yellow, or empty). When a player places in a column, the token lands at the lowest empty row in that column. Win check after each move: scan all winning lines (4-in-a-row patterns horizontally, vertically, diagonally).
AI: minimax with alpha-beta pruning, often with iterative deepening (search to depth 2, 4, 6, etc., until time runs out). Transposition tables cache evaluated positions. Position evaluation function counts threats, blocked threats, central control, and tempo.
Game tree: about 4.5 trillion possible positions. Full search is infeasible in browser; depth-limited search (typically 6-9 plies) plays well but not perfectly. Endgame databases enable perfect play but are too large to ship in browser.