# Tic Tac Toe online game - How to win Tic Tac Toe game

Tic Tac Toe rules: Tic Tac Toe is a turn-based board game for two players, X and O. The game board is a 3x3 grid of squares, where the players alternatively mark one square. Winnner is the first player to get a horizontal, vertical or diagonal row of three squares.

## Tic Tac Toe games

Play with Tic Tac Toe like games. The games are puzzles which begin at level 1 and you can raise a level by winning (and drop a level by losing) a game. Play Tic Tac Toe with time limit and with to get more time and try to win as many games as possible within time.

Try if you can win these Tic Tac Toe games. It's important to play good and fast.

## How to win Tic Tac Toe

A good rule is better than a long lecture. Here are six good rules about how to win Tic Tac Toe:

1. Make a winning row
2. Block a winning row
3. Make a fork of winning rows
4. Block a fork of winning rows
5. Exploit opening mistake
6. Avoid opening mistake

These simple rules are all you need to win Tic Tac Toe games - or better not lose, if your opponent knows them too.

### 1. Make a winning row

The first player to get three in a row wins, so you should claim a winning row right away.

Where X should play next to win?

### 2. Block a winning row

If your opponent is missing only one in a row, you should block it immediately.

Where O should play next to not lose the game?

### 3. Make a fork of winning rows

A "Fork" means two separate winning rows, from which your opponent can block just one.

X can make a fork by playing in two squares, which ones?

### 4. Block a fork of winning rows

You are losing if your opponent can create a fork, so prevent it.

Why it's bad for O to play in a corner?

### 5. Exploit opening mistake

If you start at the center and your opponents responds by playing in an edge, you can force a win.

X wins by playing in any but one square, which one?

### 6. Avoid opening mistakes

A corner is a good square to start, because your opponent has more room to make a mistake.

O can play only in one square or X enforces win, which one?

### Game must be played

How to always win Tic Tac Toe? Not possible. If the both players play by these rules the game would always be a draw. So it's impossibile to always win Tic Tac Toe, but it's possible to never lose a game if you play well.

But a good game is hard to play. Especially, when playing fast you will make mistakes and to win this game you need to play fast due to time limit.

## Tic Tac Toe online

This game runs almost on any, also mobile, browsers and devices:

1. Mobile with touchscreen
2. Computer with mouse
3. Arrow keys and spacebar
4. D-pad controller with a B-key
5. Game controller with Gopher360

## Tic Tac Toe logic

How do we check that the Tic Tac Toe winning rules presented here are the whole truth and nothing but the truth? That's easy! We will just play all possible game combinations to find all possible ways to win.

Tic Tac Toe is a simple game, but it still can have tens of thousands of different game plays. We must use computer to "calculate" all possible combinations.

### Minimax artificial intelligence

Minimax is a widely used artificial intelligence algorithm in games. The way Minimax works is that it tries all possible game states one-by-one and evaluates winning condition after each move. With that kind of brute-force calculation "intelligence" may be a bit of an overstatement, but as a Tic Tac Toe opponent, Minimax actually looks quite intelligent and fun to play with.

Minimax is a general-purpose algorithm and it needs game specific winning condition to evaluate board after each move. In Tic Tac Toe, a good enough evaluation function is to search for three-in-a-row after each (simulated) move. That kind of loop is easy to code, but it actually requires very much calculation. In practise it's not possible (or necessary) to evaluate all possible moves, especially if game is more complex than Tic Tac Toe.

### Minimax search-depth

Minimax search-depth defines how many moves ahead are evaluated, so limiting search-depth can alleviate much of Minimax calculation. Tic Tac Toe has at most 9 turns so Minimax can evaluate all possible moves and play perfect game when search-depth is 9.

What about, if search-depth is less than 9?

The table illustrates (in blue), how Minimax wins more games against a random player as search-depth increases from 0 to 6. The reason why here is 6 instead of 9 is explained later.

At search-depth 0 Minimax peeks zero moves ahead so it actually plays randomly, and thus, it wins about as many games as the random player. Minimax gets better as the search-depth increases, and at search-depth 6 Minimax does not lose a single game anymore. This is important finding, because it allows us to limit search-depth to 6 instead of calculating moves all the way up to 9.

For completeness sake, it should be pointed out that in this very simple experiment with a million randomly played games, there is a minor chance that some winning patterns might still be unnoticed. However, since the purpose of this writing is not scientific, let's just ignore that possibily now.

We can devise search-depth 6 is enough to play perfect Tic Tac Toe and to calculate six moves ahead sounds better than nine, but that's still tens of thousands of game plays on each move... That might be ok-ish for a computer, but definitely not for me.

### Human like intelligence

Minimax intelligence is not human-like. It's not immediately obvious why Minimax plays better when search-depth is increased. We need to analyze games Minimax won to see how it "thinks". Fortunately, we don't need to analyse all games, but we can focus on the games which Minimax won after search-depth was increased.

Minimax plays randomly at search-depth 0 and perfect game at search-depth 6. If we can discover the difference between its random and perfect play, we could actually define ALL the rules how to win Tic Tac Toe.

That's interesting!

### Tic Tac Toe tactics

"Tactics" is here an alias to the six winnings rules presented above.

As you recall search-depth means how many moves Minimax tries ahead. To make row-of-two to row-of-three takes only one move, so the first tactic at search-depth 1 is intuitively to "Make a winning row" in the current move.

Tic Tac Toe is turn-based, so at search-depth 2 Minimax tries all possible opponent's moves. If the opponent is about to get a winning row on the next move, Minimax tries to prevent it, and thus, the second tactic is obviously "Block a winning row".

The first two tactics didn't take too much analysis, but it's more challenging to find new tactics when the search-depth increases. That kind of logical puzzles are intriguing, so let's try to analyse Tic Tac Toe tactics.

### New Tic Tac Toe tactics?

In the experiment above, we see that each time search-depth was increased Minimax did won more games. There must be at least one new tactic to discover on each search-depth from 1 to 6. I have found one new tactic per each search-depth, but there might be more tactics depending on how strictly you define each tactic.

The picture illustrates how Minimax loses at search-depth 5, but wins at search-depth 6. Human player would have played the second move intuitively right, but can you analyze how Minimax is thinking? Minimax makes a mistake which reveals the logical pattern behind the hardest winning tactics of Tic Tac Toe :)

## Games like Tic Tac Toe

You may like about games similar to Tic Tac Toe: