Connect Four AI — Play Against a Minimax Engine
Play Connect Four against a real AI opponent that searches the game tree with negamax and alpha-beta pruning, backed by a genuine center-weighted position heuristic — pick your color and difficulty and drop discs on an animated board.
Result
This Connect Four AI is a genuine search-based opponent, not a scripted or random bot. Choose to play as red or yellow (red always opens, as in standard Connect Four), pick a difficulty, and start dropping discs by clicking a column or the arrow above it. The disc animates down to its landing row, four-in-a-row is detected instantly in every direction — horizontal, vertical, and both diagonals — and a short status line always tells you whose turn it is or announces the winner.
The engine behind the AI is a negamax search with alpha-beta pruning, the same family of algorithm used by classic board-game engines: it explores the tree of possible future moves, has each side try to maximize its own outcome while assuming the opponent plays well too, and prunes away branches that cannot change the result once a better line has already been found. Because Connect Four has only seven columns to choose from, this search can look several moves ahead quickly. It runs with iterative deepening — searching one ply, then two, then three, and so on — inside a short time budget per move (roughly a quarter of a second on Easy up to about a second and a half on Hard), so the browser never freezes waiting for a move.
When the search cannot reach the end of the game within its depth, moves are judged by a real position-evaluation heuristic instead of a guess: every possible four-in-a-row window on the board is scored based on how many of each color already occupy it (an empty window worth nothing, a window with only your discs worth more as it fills up, a window blocked by both colors worth nothing), and cells in the center columns count for more because they participate in more possible lines. Easy and Medium add a little controlled randomness among moves that score nearly the same, so the AI feels more human and beatable; Hard always plays its strongest found move. This is an honestly strong minimax opponent built from real search and evaluation — not a claim of unbeatable or perfect play, and not a simulation of anything: every move is the actual output of the algorithm above.