Sealing seams

What are the secrets of tic-tac-toe? Board game secrets: how to win at tic-tac-toe

Tic-tac-toe is a pretty simple game. A small number of cells - there are only nine of them - leads to a limited number of moves. Therefore, it was quite easy for mathematicians to study this game. Therefore, classic tic-tac-toe is a solvable game, that is, there is a single strategy that clearly leads to a win or a draw. How to defeat your opponent?

When the first move is given to you

If you must go first, then, without further ado, place your “figure” - let it be a cross - in the very corner. This can ensure your victory if your opponent does not think of placing his zero on the central field. If his zero will be in the extreme, but not the corner field, then you should place a second cross in another corner, spaced from the first in the vertical or horizontal direction (but not in contact with this zero). The opponent will have to place his piece between your crosses, and you calmly place the third cross in the third corner. Then two winning directions are formed at once. Your opponent cannot place two zeros at the same time, so you win.

But what if your partner drew their first zero in the center? Then you won’t be able to win, but you can lead the game to a draw. The next cross should be in the opposite corner to create a diagonal line X-O-X. If after this the opponent places his zero in one of the corner fields, then you win - just place the third cross in the remaining corner, forming two winning lines. If the opponent makes a move to another square, this will lead to a draw - unless, of course, you make a mistake.

You can also place a second cross in the outermost, but not the corner, square that does not touch your first cross. If the enemy makes his next move in the corner, then with your third cross you must block his line and create a winning situation. Otherwise, the outcome of the game will be a draw.

If you play second

If the opponent moves first and makes error-free moves, then the only possibility is to create a draw. From the above, you can understand that your first move must be made on the central field. Your second cross should be placed in the side, but not the corner, square if there is no need to block the opponent’s line. By following this strategy, you can create the desired draw.

If the opponent makes his initial move in the center, then you place your cross in the corner. In the future, you need to fend off the enemy’s threats by blocking his winning lines.

The player going second can only win if the opponent makes a mistake.

Varieties of tic-tac-toe

It is believed that tic-tac-toe gave rise to many other, more complex and interesting board games. But this game itself also has complicated variants.

For example, “volumetric” tic-tac-toe. This game was present on the old Atari 2600 game console. Four planes measuring 4 x 4 cells are located one below the other. A winning situation of four crosses or zeros can be created not only on one plane, but also on all four, and there are many options: for example, each cross or zero has the same coordinate on each plane, and this is considered a win.

Gomoku, or Renju, is a Japanese game played on large fields. In competitions, this field is 15 by 15 or 19 by 19 cells, but there are also options on an “endless” field. Moves are made not into cells, but at the intersections of lines; Instead of crosses and toes, black and white checkers are usually used, but the essence of the game is still the same. The one who places five of his checkers in a row wins.

Tic-tac-toe is a solvable game. This means that there is a mathematically proven strategy that can be used to achieve the best result in every game. In tic-tac-toe, two players who use the correct strategy will always end the game in a draw, that is, without a winner. Against an opponent who does not know this strategy, it is still possible to win if he makes a mistake. Once your friends get the hang of your strategy, try a more complex version of the rules.


Learn the basic rules if you don't know how to play tic-tac-toe.

Steps

Win or draw if you go first

    Place the first X in the corner. The most experienced players, if making the first move, place an X in the corner. This will give your opponent the greatest number of opportunities to make a mistake. If your opponent responds by placing an O in any other place, except for the central cell, this guarantees you victory.

    Try to win if your opponent places the first O in the center square. If your opponent places his first O in the center, you will have to wait until he makes a mistake before you can win. If he continues to play correctly, then the result of the game can be guaranteed to be a draw. Here are two options for your next move, with instructions on what to do next if your opponent makes a certain move (and if not, just keep blocking his moves to tie the result):

    You win automatically if your opponent places his first O in any square other than the central one. If your opponent places his first O in any square near the center, you can win. In response, place your second X in any other corner so that there is an empty square between the two Xs.

    Place the third X to get two possible winning moves. Most likely, your opponent will see that you have two X's in a row and block you. (If not, then win by making a row of three X's). After this, there should be an empty square in line with your first and second X, and no enemy O blocking that line. Place the third X in this square.

    • For example, draw a tic-tac-toe board on a piece of paper that has "X O__" on the top line, "O___" on the middle line, and "X___" on the bottom line. If you place the third X in the lower right corner, it will be in line with your other X's.
  1. Win by betting the fourth X. After your third X, there are two squares left, occupying which will win the game. Since your opponent can only make one move, he will only be able to block one of these squares. Place the fourth X in an unlocked square and you win!

    How not to lose when you go second

    1. Bring the game to a draw by going second. If your opponent starts first and places an O in the corner, always place an X in the center square. The second X should be placed in the middle, Not corner, cage, If only you don't have to block your opponent's move so that he doesn't line up three O's in a row. When using this strategy, each game usually ends in a draw. Theoretically, you can win in this situation, but your opponent must make a fatal mistake, such as not seeing that you have two X's on the same row.

      • In this section, your opponent still plays zeros, but remember that he starts moving first.
    2. Achieve a draw if your opponent starts moving from the center square. When your opponent starts the game by placing an O in the center square, place the first X in the corner. After that, simply block your opponent's moves and it will be a draw. There is no way to win in this situation unless your opponent stops trying to win!

      Try to win if your opponent starts moving from the outer square. Most likely, your opponent will move as described above. However, if he places his first O in the outer square, not the corner or central one, you have a small chance of winning. Place the first X in the center. If your opponent places his O on the opposite edge so that it forms an O-X-O line, place your third X in the corner square. Then, if your opponent puts his third O in the outer square next to your X so that you get an O-X-O line, place a third X in the square to block the line of two O. From now on, you can always win by betting your fourth X.

    Varieties of tic-tac-toe

      Try these variations if your tic-tac-toe games always end in draws. It may be fun to be unbeatable at tic-tac-toe for a while, but even without this article, your friends can figure out how to stop you from winning. Once this happens, every game you play with them will end in a draw. But with the help of the basic rules of tic-tac-toe, you can play games that have not yet been solved. Try them - these games are described below.

The first article examines various options for solving the problem, but there is no implementation in the form of a game; in the second, there is a game, but the computer “plays” rather poorly. I decided to make my version of the gomoku blackjack game a fairly strong computer game. A publication about what happened in the end. For those who like to jump straight into battle - the game itself.

To begin with, I want to decide on the main points. Firstly, there are many varieties of the gomoku game, I settled on this version: the playing field is 15x15, the crosses go first, the one who is the first to build 5 in a row wins. Secondly, for simplicity, I will call the game algorithm for calculating the computer's moves AI.

Thank you for your attention. I hope you enjoyed reading and playing as much as I enjoyed implementing it :)

P.S. A small request, if you win easily, please attach a screenshot of the game and moves (from the console logs) for analysis and improvement of the algorithm.

Update 1
1. Increased the importance of scales for attack by 10%. Now attack for AI is preferable to defense, all other things being equal. For example, if the AI ​​and the user have 4ka, then the AI ​​will prefer to win.

2. Changed the values ​​of the weights according to the templates. By balancing the weights more clearly, you can achieve better AI performance.
Template weights are now as follows:
99999 - xxxxx - five in a row (final winning line)
7000 - _xxxx_ - open four
4000 - _xxxx - semi-closed four (two such fours are preferable to one open one, perhaps the “game” will be more interesting)
2000 - _x_xxx, _xx_xx, _xxx_x - semi-closed four with a gap (2 such fours are equal to one open four and are “preferred” to an open three; but if there is only 1 such four, then an open three is preferable)
3000 - _xxx_ - open three
1500 - _xxx - semi-closed threesome
800 - _xx_x, _x_xx - half-closed three with a gap
200 - _xx_ open deuce
There are also small weights (from 1 to 20-30) around all moves to create a “slight randomness of the move.”

Don't lose it. Subscribe and receive a link to the article in your email.

Each of us at least once in our lives played the famous tic-tac-toe game, trying to build 3 crosses or 3 zeros in a row or diagonally on a nine-cell field. If you have practiced this game enough, you probably know that two experienced players always end the game in a draw, and this makes the game uninteresting for them. In this article you will read about how to win at tic-tac-toe, or at least not lose, and also learn all the tricks and secrets of beating this popular game.

A little about the rules. The goal of the game is to line up 3 identical figures (3 crosses or 3 zeros) horizontally, vertically or diagonally on a nine-cell field in a row before your playing partner does. The game of tic-tac-toe begins with the player's move, who places a cross in any cell on the three by three playing field (we note right away that he has a much greater chance of winning than his opponent). After this, the second player places a zero in any free cell. Then the cross moves again. Then again zero. And this continues until:

  1. One of the players will not build 3 crosses or 3 zeros in a row or diagonally, and as a result will be declared the winner;
  2. There will be no free cells left, and there will be no three identical pieces in a row on the field - in this case, a draw is declared.

Tactics of crosses

The first move of crosses. The most advantageous position is the middle of the playing field, or as marked in the diagram, cell No. 5. This is where your figure should be entered if this cell is free, and this is why beginner crosses always have an advantage. Through the central cell you can build the largest number of possible winning options: two diagonals, one horizontal and one vertical.

Second move of crosses. After you have made your first move by placing a cross in the center, all you have to do is wait for your opponent's move. In general, he has only 2 possible options: place a zero in one of the “corner” cells (No. 1, No. 3, No. 7 and No. 9) or place his piece in cells No. 2, No. 4, No. 6 or No. 8. And it should immediately be noted that your ability to win fundamentally depends on this move.

If the player chooses one of the off-diagonal cells No. 2, No. 4, No. 6 or No. 8, then you have a win-win strategy. In other words, you can win with 100% probability if you know how to act correctly. This algorithm is described in the diagram below. First of all, you need to place a cross with your second move in the corner square, forcing your opponent to defend. And after that, you occupy another free corner cell, as a result of which you have 2 rows, where only one cross is missing (this is shown in the last field of the diagram). Wherever your opponent puts his zero, you win anyway, having a backup strategy.

If your opponent chooses cells No. 1, No. 3, No. 7 and No. 9 with his first move, then you do not have an absolute winning strategy, and you should rely only on the further inattention of the second player, which is quite rare in such a simple game.

The third and subsequent moves of crosses. Further moves of the “crosses” should be aimed at building 3 of their own pieces in a row, as well as stopping the unlikely, but still possible attempts of the “zeroes” to place 3 pieces in a row.

Also, in order to win, “crosses” can start not only from the central cell, but also from the corner. Read more about this.

Algorithms for moving zeros

If you happen to play with zeros, then in most cases you will only have to fight for a draw. However, you have a chance to win if you are playing with a completely inexperienced player.

The first move of zeros. If player No. 1 for some reason did not occupy the central cell, feel free to put a zero there and proceed further, relying on the strategy of crosses described above. But, most likely, the central cell will already be occupied by the time of your initial move. In this case, do not make the unforgivable mistake and do not put a zero in cells No. 2, No. 4, No. 6 or No. 8, but choose only diagonal cells No. 1, No. 3, No. 7 and No. 9.

Second and subsequent moves. Further moves of the “noughts” should be aimed at stopping the attempts of the “crosses” to place 3 pieces in a row, and also, if possible, at building 3 zeros in a row, which is practically impossible.

All game strategies

The graph below, which can be found on Wikipedia, shows possible strategies for winning and drawing in a tic-tac-toe game on a field of 9 squares.

***

I hope this article has become an assistant for you in the tricks of tic-tac-toe, including money and strip, and you now know some necessary tactics and strategies in order to win (or at least not lose) this wonderful game. game. And if you have comments, feedback and suggestions, leave them below.

Hello, readers of my blog, today I will tell you how to win at tic-tac-toe.

A wonderful game that doesn’t require much preparation, just find a pen or pencil, a piece of paper and a partner.

In fact, the game is simple and, at the same time, complex. Many people don’t take it seriously, which is why they lose. To be honest, I myself didn’t understand how to play it, but then I analyzed all the possible moves and realized that it all comes down to mathematics.

Why is this game so simple? The thing is that there are only 9 cells here, that is, you have 1 of 9 initial options, and then this number is reduced by 1. That is, if you made your move, then your opponent no longer has 9 options, but only 8, because 1 cell is already occupied.

Well, I think you understood this without me, today I’m just “Captain Obvious”. Why is it difficult, because there are possible combinations here, and if you want to learn how to win this game, then you will need a pen, as well as a blank piece of paper.

How to win at tic-tac-toe

Basic concepts you need to know:

Field– a conditional field of 3x3 cells, where the battle takes place.

Crosses- these are the “x” icons, they go first.

O's- these are the “0” icons, they come second.

Victory– when a player collects 3 crosses or 3 zeros in a row.

Here is an example of a field.

In order for you to analyze correctly, let's number each cell.

At least so that you understand which field is which.

Winning strategy in 3x3

Remember that if you play for zeros, that is, you need to make the second move, then against a strong opponent you will only make a draw. It's difficult to win with zeros, since they go second and almost always defend against the threats that crosses create (they go first).

Don't be surprised by what I write, as for beginners, I want you to understand how to win with crosses and how to draw with zeros.

Let's begin...

The best strategy. The crosses make a move to the 5th cell, which is in the middle.

Next, REMEMBER that if the zeroes make their second move not on a DIAGONAL CELL, then they lose. It doesn’t matter which square, they make a move: 2, 4, 6, 8, if they put a zero on any of these fields, then they lose forcibly.

For example, you bet on 5, they bet on 2, now you bet on 1 or 3, threatening to make 3 crosses on the diagonal. Well, ok, you bet on 1, it turns out that if you put a cross on the 9th field, you will win. You are forced to place a zero on square 9, but now you win exquisitely by betting a cross on square 7.

It turns out that you are threatening to place three crosses diagonally with a move of 3 and vertically with a move of 4. Beauty, isn’t it?

The best defense for zeros is, after moving 5 for crosses, to make the moves: 1, 3, 7, 9, in this case, if you are careful, you will always make a draw. Remember this simple rule and you will never lose.

Tricky strategy for crosses

But, after all, the player is not at all obliged to make the first move to the middle, that is, to cell 5. There is a very cool trap here: you make the first move to the corner field.

The best defense here would be to occupy the field with zeros - 5, since it is free, then it needs to be occupied. In this case, the zeros will always make a draw, by constantly threatening to put three in a row themselves.

If, for example, the crosses make a move to square 1, then it would be a mistake to move 4 and 9; in these cases, the crosses forcefully win.

Let's look at these options:

A) Crosses– 1, zeros – 4, crosses – 5, zeros – 9 (forced), crosses – 3 with winnings on fields 2 or 7 depending on the answer of the zeros.

C) Crosses – 1, zeros – 9, crosses – 3, zeros – 2 (forced), crosses – 7 with winnings on fields 4 or 5 depending on the answer of the zeros.

Well, that's all, friends, I hope that now you know how to win at tic-tac-toe 3x3. There is nothing complicated in it (the game), with proper defense, there will always be a draw, but, as you can see, there are interesting options for crosses in which you can catch zeros.

I wish you success, if I forgot to write something, then remind me, maybe even in a comment.

Good luck everyone, bye!

Sincerely, Yuri Vatsenko!