Ferramentas Guias
Games Gratuito Sem cadastro

Tic-Tac-Toe Game

Play Tic-tac-toe against an unbeatable AI with three difficulty levels.

Carregando ferramenta…

Sobre esta ferramenta

Challenge the CPU to a classic game of Tic-tac-toe right in your browser. Choose Easy mode for a casual opponent that makes random moves, Medium for a strategic challenger, or Hard for a perfect minimax AI that cannot be beaten. Winning squares are highlighted, scores are tracked across games, and a New Game button resets the board whenever you're ready for another round.

Como usar

  1. 1 Select a difficulty level: Easy, Medium, or Hard.
  2. 2 Click any empty square on the 3×3 grid to place your X.
  3. 3 The CPU automatically responds with its O move.
  4. 4 Continue until someone wins or the game is a draw.
  5. 5 Click 'New Game' to reset the board and play again.

Why Tic-Tac-Toe is a "solved" game

Tic-tac-toe looks trivial, but it is one of the simplest games that is mathematically solved: with perfect play from both sides, the result is always a draw. There are only 9 squares, so the entire tree of possible games is small enough for a computer to explore completely. That is exactly what the Hard mode here does — and it is why you can never beat it. You play X and always move first; the CPU plays O. The best you can hope for against a perfect opponent is a tie, and the only way to lose is to make a mistake the AI can punish.

Three difficulty levels, three different brains

The same board drives three very different opponents, and seeing how they differ is the most instructive part of the tool.

  • Easy picks a completely random empty square. It has no plan, so it will miss obvious wins and fail to block you — a gentle warm-up.
  • Medium follows a short priority list of human-style heuristics: first, if it can win this turn, it takes the winning square; otherwise, if you are one move from winning, it blocks you; otherwise it grabs the center if it is free; and failing all that, it moves randomly. This catches careless play but can still be beaten with a known opening trap.
  • Hard runs the full minimax algorithm and plays perfectly.

How minimax thinks ahead

Minimax is the classic algorithm for two-player, turn-based games with no hidden information. The idea: one player tries to maximise a score while the other tries to minimise it. From the current board, the AI imagines every move it could make, then every reply you could make, then every counter, all the way to the end of each line. It scores finished boards as +10 if the AI (O) wins, -10 if you (X) win, and 0 for a draw. It then assumes you will always pick the move that is worst for it, and chooses the move that gives the best guaranteed outcome against that perfect defence.

A worked example: if O can complete three in a row immediately, that branch scores +10 and minimax takes it. If instead O has two threats at once — a "fork" — you can only block one, so every line leads to an O win, and minimax steers toward that fork. Because it always assumes you play optimally, it never sets up a position you could exploit.

Alpha-beta pruning: the same answer, faster

Searching every branch is wasteful, so the Hard AI uses alpha-beta pruning. It tracks the best score the maximiser is already assured of (alpha) and the best the minimiser is assured of (beta). The moment a branch cannot possibly beat what has already been found, it stops exploring that branch — the result would not change the decision. Pruning never alters the chosen move; it just skips work, which is why the CPU responds instantly even though it is, in principle, considering thousands of game continuations.

Strategy tips for human players

  • Take the center first. The center square is part of four of the eight winning lines — more than any corner (three) or edge (two).
  • Then play corners. Corners create more two-way threats than edges, setting up forks.
  • Aim for a fork. The only way to actually win is to create two simultaneous threats so your opponent cannot block both — which is precisely what Medium and Hard try to prevent.
  • Against Hard, play for the draw. Block every threat, never leave two of your opponent's lines open, and you will tie every time.

About the scoreboard

The tool tracks wins, draws, and losses across rounds. Switching difficulty starts a fresh board but keeps your running score, so you can climb from Easy to Hard without losing your tally. The score only clears when you press Reset Score. Winning squares are highlighted at the end of each game so you can see exactly which line decided it.

Common misconceptions

  • "There must be a way to beat the Hard AI." There is not — perfect tic-tac-toe is a forced draw, and minimax plays perfectly. A win against Hard would mean the algorithm had a bug.
  • "Going first guarantees a win." First move is an advantage against weak play, but a perfect opponent neutralises it into a draw.
  • "Medium is just slower Hard." No — Medium uses fixed heuristics and can be tricked by a double-threat opening, while Hard searches the whole tree and cannot.

Perguntas frequentes

{# Alpine.js — self-hosted. (The previous jsdelivr CDN tag had a stale SRI integrity hash, so the browser refused to run it and window.Alpine was never defined — silently breaking every FAQ accordion and Alpine tool.) #}