Tic-Tac-Toe Online Game
Play the classic Tic-Tac-Toe game online. Challenge a friend or play against the computer with adjustable AI difficulty.
Play the classic Tic-Tac-Toe game online. Challenge a friend or play against the computer with adjustable AI difficulty.
Tic-Tac-Toe (also called Noughts and Crosses) is a classic 3×3 grid game where two players take turns marking cells with X or O. The first player to align three of their marks horizontally, vertically, or diagonally wins. With perfect play by both sides, the game always ends in a draw — the game is solved, meaning optimal strategies exist for both players.
Despite the simple rules and solved nature, Tic-Tac-Toe remains popular for casual play and is a foundational example in game theory and AI courses. Computer opponents using minimax algorithms play optimally; against an optimal opponent, the human can at best draw. Against weaker opponents, victory is achievable.
This implementation supports two-player local play and play against an AI. The AI difficulty is configurable: random moves (easy), heuristic-based (medium), or minimax-optimal (hard). At hard difficulty, the AI never loses; at most it draws.
Quick games (typically under a minute) make Tic-Tac-Toe a perfect short break activity. Five-minute breaks accommodate several games. The simplicity also makes it accessible to children and adults alike.
It is also instructive. Playing against a perfect AI teaches the structure of the game — first player can force a draw with center opening, certain corner moves are preferable, etc. The game theory lessons transfer to more complex domains.
Mark cells, get three in a row.
Game state: a 3×3 array tracking each cell's content (X, O, or empty). Win check after each move: scan all 8 lines (3 rows, 3 columns, 2 diagonals) for three identical non-empty marks.
AI: minimax with alpha-beta pruning. The full game tree has 9! = 362,880 leaf nodes (most pruned by symmetry and game ending early). Computing optimal play in browser is instant.
First player advantage: with perfect play by both, X can force a draw against any O strategy and win against suboptimal O. With perfect play by both, the game ends in a draw.