Connect 4 vs AI
Drop your red pieces and try to connect four in a row before the AI does. Choose your difficulty and outsmart the computer.
Wins: 0Losses: 0Draws: 0
Idle
Ready to Play?
Controls:
Click a column or press 1-7 to drop • Space to pause • Enter to start
Tap a column to drop your piece • Tap Start to begin
How to Play Connect 4
Drop a piece in any column and try to be the first to connect four in a row — horizontally, vertically, or diagonally — before the AI does the same.
Game Rules
- The board is 6 rows by 7 columns. You play red, the AI plays yellow.
- Click or tap a column to drop your piece. It falls to the lowest empty row.
- The first player to connect four pieces in a row (horizontal, vertical, or diagonal) wins.
- If the entire board fills up with no winner, the game is a draw.
- Wins, losses, and draws are tracked across sessions in your browser.
Controls
- Click / Tap: Tap a column to drop your piece
- Digit keys 1-7: Drop a piece in that column
- Enter: Start a new game
- Space: Pause / Resume the current game
Difficulty Levels
- Easy: Shallow minimax search (depth 2) with a 25% chance of a random move — friendly for casual play.
- Medium: Depth-4 minimax with alpha-beta pruning. A solid challenge for most players.
- Hard: Depth-6 minimax with strong center preference. Plan several moves ahead to beat it.
Strategy Tips
- Control the center column — it's part of the most winning lines.
- Watch for two-way threats: setting up two ways to win that the AI can only block one of.
- Block the AI's three-in-a-row immediately, even if it means delaying your own attack.
- Think about the row above your move — dropping a piece can hand the opponent a winning spot above it.
- Diagonal threats are easy to miss. Scan all four directions before each move.
Minimax AIVs ComputerStrategy
GET IN TOUCH
Let's work together
I build fast, accessible, and delightful digital experiences for the web. Whether you have a project in mind or just want to connect, I'd love to hear from you.
Get in touchor reach out directly at hello@mohammadshehadeh.com