Tic-Tac-Toe
Play Tic-Tac-Toe against a smart computer AI in your browser. Can you win?
How to play
- You are X — click any empty cell to place your mark.
- The CPU (O) responds immediately after your move.
- Get three in a row — horizontal, vertical, or diagonal — to win.
- Use Easy mode for a beatable random opponent, Hard for a perfect AI.
- Click Restart to begin a new round; the score carries over.
You play as X. Click a cell to make your move. The computer plays O and uses Minimax (Hard) or random (Easy) strategy. Can you win?
How it works
Tic-Tac-Toe is a two-player game played on a 3x3 grid. You play as X and the computer plays as O. Players alternate placing their mark, and the first to align three marks in a row — horizontally, vertically, or diagonally — wins.
The AI opponent uses a minimax strategy, meaning it always picks the move that minimizes your chances of winning. On perfect play from both sides the game always ends in a draw, but any mistake by a human player is punished.
The best way to hold off the AI is to take the center square on your first move and then create a fork — a position where you have two ways to win at once, so the AI can only block one.
Use this tool to practice strategy, teach the rules to beginners, or simply enjoy a quick game during a break.
Worked example
Creating a fork to beat the AI
- Take the center square (position 5) on your first move.
- If the AI plays a corner, take the opposite corner.
- Play a third corner so you now threaten two winning lines simultaneously.
- The AI can only block one — complete your winning line on the next move.
You win with three X marks in a row while the AI is unable to block both threats.
Common mistakes to avoid
- Playing edge squares on the first move, which gives up the strategic advantage of the center.
- Focusing only on your own winning threat while ignoring the AI's two-in-a-row setups.
- Not looking two moves ahead — failing to see when the AI is about to create a fork.
Key terms
- Fork
- A board position where a player threatens to win via two different lines at once, making it impossible for the opponent to block both.
- Minimax
- An algorithm the AI uses to evaluate all possible future moves and always choose the one that leads to the best worst-case outcome.
- Draw
- A game result where all nine squares are filled but neither player has three in a row.
Frequently asked questions
- Can I beat the hard AI?
- The hard AI uses Minimax and plays perfectly — the best you can do is draw. Try Easy mode for a beatable opponent.
- How does Minimax work?
- Minimax explores all possible future moves and picks the one that maximises the AI's chance of winning.