# Winning strategy for NxN Tic-Tac-Toe

In a standard 3x3 Tic-Tac-Toe board, there is a strategy to win if the opponent makes a mistake. As far as I know, the strategy goes like:

• Capture the centers
• Capture the edges
• Capture a square which can lead to multiple immediate wins
• Be careful of immediate threats

I'm looking for a common strategy which works for all NxN board variants. Is there one?

EDIT:

The variant has the same rules as the standard one. All squares in a diagonal, row, or column occupied by a player is a win. And of course, if there isn't any moves to make, it's a tie.

• On larger boards usually you need more than 3 in a row. Do you mean 5 in a row on a NxN board? Commented Apr 26, 2019 at 9:07
• Thanks for pointing it out! I have edited the question accordingly.
– Sriv
Commented Apr 26, 2019 at 16:40

Optimal play on NxN boards where you need N in a row leads to a draw for all N > 2.

Contemporary Combinatorics, by Bela Bollobas has a proof of it. Below is a summary of this. The images below are from this book.

All board sizes 5x5 and up can be proven to be a draw by the second player employing a pairing strategy, namely where the second player plays a piece in a location next to or near the location of the first players move that most limits the options the first player has to play further.

For example, in the 5x5 game, optimal play for player 2 involves playing in the space with the same number as that played by player 1. If player 1 goes in the center, or if the matching space is already occupied, player 2 can go anywhere.

Similarly, for 6x6:

3x3 tic-tac-toe can be proven a draw by brute force method, and 4x4 can be proven a draw by creating 3 different pairing strategies based on each of the three possible opening moves by player 1 (ignoring symmetry and rotation).

So, under optimal play, there is no winning strategy.

However, if you want to write a good strategy, it seems the thing you want to do in general would be to play pieces that give you as many options to win as possible. This would be central locations at the beginning and locations that are part of multiple lines of your pieces in the mid-game and late-game. Early game, I'd go for spaces on the optimal move chart where the blocking move is the furthest away. Late game, I'd go for moves that win the game or block winning moves, and otherwise ones that give the most options in conjunction with existing pieces.

• This video generalizes even further, also dealing with 3 or higher dimensional boards: youtu.be/FwJZa-helig Commented Apr 28, 2019 at 13:59
• the link weijima.com/article-11-15.html is broken Commented Mar 11, 2020 at 13:32
• @Cohensius Thanks. I updated it to a different source and added more of the related content
– Zags
Commented Mar 11, 2020 at 14:15

There are several generalizations to tic-tac-toe. The most natural one (imho), is the m,n,k-game, which is the game of k-in-a-row played on an (m,n) board.

In (n,n,n) games, for n>2, the second player can force a draw. See m,n,k-game for many other results.

• If n<3, it's impossible for player 1 to lose, as they will always win on their nth turn no matter what plays are taken for an n,n,n game. Commented Mar 12, 2020 at 2:15