Tic-Tac-Toe vs Computer
Play X vs O against the AI. Can you beat Hard mode?
How to play
You are X, the computer is O. Take turns placing your mark. Get three in a row (horizontal, vertical, or diagonal) to win. Choose your difficulty — Hard uses the Minimax algorithm and never makes a mistake!
Why Tic-Tac-Toe Teaches More Than It Seems
Tic-Tac-Toe is one of the few games where mathematicians have completely solved all possible plays. With perfect play from both sides, the game always ends in a draw — a mathematical certainty, not a coincidence. This is why the Hard mode uses the Minimax algorithm: it explores every possible game state and picks the move that minimizes your maximum possible gain. Playing against it and forcing a draw is genuinely satisfying precisely because you know the AI is playing perfectly — you haven't gotten lucky, you've matched an optimal strategy. Meanwhile, Easy and Medium modes intentionally introduce weaknesses, giving beginners and intermediate players a realistic chance to win.
Key Features
- Three AI difficulty levels: Easy picks random moves; Medium blocks your wins and takes its own wins but plays randomly otherwise; Hard uses the complete Minimax algorithm and never makes a suboptimal move.
- Minimax AI on Hard: The algorithm recursively explores all possible future board states and scores each based on outcome (win/loss/draw), ensuring the AI always plays the move that maximizes its chance of winning or drawing.
- Win highlighting: The three winning cells are highlighted in yellow when either side wins — making the winning line immediately obvious rather than requiring you to scan the board.
- Session score tracking: Wins, draws, and losses accumulate across games in your session — you can play 10+ games and see your actual record against each difficulty level.
- 400ms CPU move delay: The computer waits briefly before playing — giving you time to see your move resolved before the AI responds, preventing the jarring instant-reply feel.
- Mobile tap support: The grid is touch-optimized — each cell is large enough to tap accurately on any smartphone screen.
Real-Life Use Cases
- Teaching AI and game theory: The Minimax AI is a perfect classroom example of adversarial search algorithms — you can watch it play and understand why it always draws or wins.
- Introducing strategy to children: Easy mode provides an AI that loses, letting kids experience both winning and gradually understanding why certain moves are better than others before facing real challenge.
- Casual quick play: Each game takes under 2 minutes and is entirely self-contained — a good mental break that requires just enough thinking to be engaging without being demanding.
- Computer science education: Minimax is one of the first algorithms taught in AI courses. Playing against it makes the abstract concept of "tree search" concrete and intuitive.
Who Can Use This
Tic-Tac-Toe is arguably the simplest strategy game with a meaningful AI component. Children can start with Easy mode and win; adults and programmers can challenge themselves on Hard and work on consistently drawing against the Minimax algorithm. The three difficulty tiers mean there's a meaningful challenge at every skill level, even within a game whose entire state space fits on a sheet of paper.
Tips & Best Practices
- Always take the center on your first move: The center cell (position 5) participates in 4 of the 8 possible winning lines — it's the highest-value cell on the board. Opening there maximizes your winning options.
- If the center is taken, take a corner: Corners participate in 3 winning lines each and are the second-most valuable cells. Edge cells (middle of each side) only participate in 2 lines.
- To draw against Hard, play perfectly yourself: Against the Minimax AI, even one suboptimal move will cost you the draw. Center → corner → opposite corner is the cleanest opening sequence for forcing a draw regardless of CPU response.
- On Medium, always block before attacking: Medium AI blocks your wins and takes its own — but it doesn't think more than one move ahead. Create a fork (two simultaneous threats) and it can only block one.
- Study the win highlights: When you lose, note which line won. Understanding which threats you failed to block teaches you the attack patterns to watch for in your next game.