## How to win five in a row

Gomoku is a logic board game played by two persons. It is played with black and white stones on a 15×15 intersection Go board made of wood.

In the beginning of the game the board is empty. The player who controls the black pieces starts the game always. Moves must be placed on the intersections of the board, not on the squares closed by the lines. Black plays first, then white turns and this process continues until the end of the game. The players alternate in placing a stone of their colour on an empty intersection.

The stones put on the table remain untouched till the end of the game. Getting down, removal or touching of stones are forbidden. It is naturally allowed to adjust a position of a piece when it is preceded by a sign. The winner is the first player to get an unbroken row of five stones either horizontally, vertically, or diagonally.

Winning the game requires a row of exactly five stones; a row of six or more stones – called overline – does not count.

In the diagram below you can see a sample game, in which the numbers written in the stones show the order of the moves. Naturally in real game moves do not contain numbers.

In this case black won at the 21st move with a vertically unbroken row of five stones.

The unbroken row of five stones can be collected in the middle and in the edge of the board as well.

Samples of collecting five stones in a row.

The basics of the game are clear by now.

At first sight this game seems to be a simple one, which doesn’t require so much power of mind, but it’s a common error. The more you get to know the game, the less you think that collecting five stones in a row is such an easy job. You spend a lot of time with building up a good line, and when you reach the winning point your opponent just blocks your line easily and it turns out that your attack was not worth much.

For a more effective play you must understand some notions and structures of game theory. Only the appropriate use of these structures can bring you victory.

The attacking structures of the game are on the basis of using ’threes’ and ’fours’. Victory is yours if these lines are not blocked by your opponent. ’Four’ means a line built up from 4 consecutive stones from the same colour which threatens in the next move with the winning fifth move. So to avoid losing this line must be blocked immediately.

Examples for blocking fours

On the upper diagram you can see all possible types of ’fours’. If black is on the move, he can gain victory by placing his fifth stone to points ’A’ or ’B’.

Points signed with ’B’ show ’half-opened fours’. This means that if white turns, he can avoid being defeated by blocking the four. Points signed with ’A’ show ’opened fours’. In this case white cannot avoid losing, because no matter which end he blocks black will add a fifth stone to the opposite side and will have won the game. Thus the main goal of the game is to create an open line of four stones in a row before your opponent does.

Opened fours can only be made from opened threes.

So if you want to win it is indispensible to create opened three (points signed with ’C’ show places where opened fours can be made).

Examples for creating opened fours

As you know already, if your opponent has an opened four, you will have lost the game. But before it, your opponent needs an opened three so as to create an opened four, that’s why you always have to be so careful and pay attention to defence inevitably when you have discovered that your opponent has an opened three, only if you have win.

At any points signed with ’D’ white can easily stop black’s opened three lines and after that those lines won’t be dangerous anymore. It’s also important to pay attention to the points signed with ’E’, because these points mean possible defences for white as well. Thanks to the edge of the board or an earlier put white stone there are several ways to block your opponent’s opened three. Putting your white stone to the ’E’ points black is not able anymore to create opened four in those planned lines. In practice such blocking ways are seldom used, because they aren’t as safe as the blocks at points ’D’.

Possible ways for blocking opened threes

By now the meaning of the basic structures, the notion of threes and fours are clear.

A wise player blocks all of your threes and fours to prevent you from reaching victory. For the sake of beating a wise opponent – who is aware of the basic structures and knows what to block and at which moment – you need deeper-constructed structures.

It means you must try to create a ’fork’- a move that creates two attacking lines at the same time. If you succeed in creating a fork you will have won the whole game, because your opponent won’t be able to block two opened lines with one stone.

’Fork’ means a move that creates at the same time:

· 1 four and an opened three (3×4)

· 2 opened threes (3×3)

4×4 forks (double fours)

Both G and F points show double fours. The only difference between G and F points is that double fours signed with G are more beautiful than F points. J

4×3 forks (a four and a three)

Points signed with ’H’ are winning forks, because the threes are opened ones, so the opponent should block both lines at the same times, but it’s impossible.

Points signed with ’I’ are not winning forks, because the threes are not opened ones due to the closeness of the white stones or the edge of the board. In these situations only the four must be blocked to avoid losing the game.

3×3 forks (double threes)

A fork consist of two threes can only be winning if both threes are opened. Points signed with ’J’ show winning forks because of opened threes.

Points ’K’ don’t mean a winning fork because one of the threes is a closed one.

By now you must be aware of the minimal basics of the game. You know the basic attacking structures and the theoretical part is clear.

How does it pass off in practice?

How do forks come into existence in real game?

Here’s an example:

In the eleventh move black had created a 4×3 fork; therefore white could resign, because there’s no chance to defense. The mistake was the tenth move, because if white had blocked on the other side, black would not have been able to create a winning fork and the game would have gone on.

The next step of game theory is also about the way that leads to victory so you need to be aware of two more basic notions.

VCT (Victory by Continuous Threats)

What does this notion mean in fact?

VCT means a winning structure when somebody reaches victory by the continuous use of opened threats (that is, making a three which threatens to become a straight four, or making a four which threatens to become a five). This means if somebody has a VCT she/he has a win that results from making threats or series of consecutive threats.

Black has a VCT because if he attacks continuously from the seventh move by way of using his threes he reaches victory.

You can see below that black used his VCT correctly.

Black used consecutive threats by the way of using his threes until white gave up.

VCF (Victory by Continuous Fours)

VCF is based on the same principle as VCT, the only difference is that continuous fours are used for the way of attacking instead of opened threes.

Therefore VCF means a bit stricter structure than VCT. If you have a VCF you can continuously use your fours one after another to attack which means your opponent has no choice where to put, s/he has to block your pulled out fours.

Although VCT is sure win because continuous opened threats are used for the way of attacking, the opponent has a possibility to use his/her own fours to hold back or postpone defeat. In the case of a VCF this option is out of question because fours must be blocked immediately.

At the position below black has a VCF from the 14 th move although it seems white has won the game with his double threes (stone 14). In fact the 14 th move has been a mistake and it means white will have lost the game because black can reach victory by using his consecutive fours as you can see below.

Black used his VCF wisely and without mistakes and therefore won the game.

This notion means such a position where one of the colours has a sure win.

When you have surewin it means a position where your opponent cannot have good answers to avoid losing if you play your position correctly.

Here black has a surewin-position, which means that white doesn’t have a defence against black’s upcoming attack. This sw-position is a VCT at the same time.

Black used correctly his sw-position and VCT from the 11 th move and won the game.

It follows from the explanations that every VCT and every VCF is a surewin as well. If somebody has a VCT or a VCF it means that s/he has a surewin-position at the same time.

In contrary with this not every sw-positions mean VCT or VCF at the same time.

There are positions where one of the colours has a surewin but victory cannot be reached by consecutive attack, which would mean using VCT or VCF. This case is very rare but important as well. These positions need very deep analysing to find out the correct move which leads to a victory without the use of continuous threes or fours or consecutive threats

These situations are very hard to recognize. Most players immediately start to use their threes or fours when they meet a situation that is presumably a surewin, so they let the opportunity to win slip away and destroy their own surewin. Beginners don’t have to recognize these situations temporarily because finding the appropriate move needs deep analyzing.

Here you can see an example:

In the following illustration black has a surewin but victory cannot be reached by continuous attack. Black has only one opportunity to attack continuously:

· 12th move: H11 or M7

· 13th move: L10 or H7

It is noticeable that if black starts to attack directly he will be in trouble at the 13th move because white can block black’s attack with an open three. If white can stop black’s attack and take over control from black, black must waive surewin and the game will go on. That’s why black must figure out that it’s a surewin position and must find the perfect move so as not to let white take control of the game. If black succeeds in finding the right move white cannot avoid losing the game.

Do you have any idea where to move as black? 🙂

How to win five in a row Gomoku is a logic board game played by two persons. It is played with black and white stones on a 15×15 intersection Go board made of wood. In the beginning of the

## How to approach writing five-in-a-row Tic Tac Toe game AI?

I was challenged by coworker into creating a Tic Tac Toe game AI that plays five-in-a-row games (not the traditional 3). My initial thoughts are that I create a “scoreboard”, i.e. every cell in the game gets a score between 0 and infinite. The AI finds shapes and determines which places hold how much value and give score to the cells. In the end, highest scored cell is the choice.

Is there a better way to approach this problem?

### 1 Answer 1

5×5 Tic-Tac-Toe might still be small enough to solve directly, depending on your time constraints, if you’re clever about the board symmetries. Oddly enough, I just wrote a description of the general technique last night, for this question:

If not, that’s still a good starting point. The next most obvious thing to me would be to change the board evaluation function and search only as deep in the tree as is feasible for your time constraints. The idea is that you, as a human, might have some ideas about what strong and weak positions are. So, as a guess, we know five in a row wins, so assign X wins as +5 and O wins as -5. One way to win is to get four in a row prior to that, so if X has four in a row, that might be worth 4, and if O has four in a row, that might be worth -4. The idea is that if you can’t search all the way down the tree, you search as far as you can with the minimax technique, confident that you’re working your way toward a strong position.

That board eval function is only an example. Coming up with a good board evaluation function can be tricky, and the one I described misses some obvious details.

Another thing to try is to use a genetic algorithm and neural networks to *evolve* the board evaluation function. Now the idea is to feed board positions into neural networks, which do the board evaluations, and let them play according to the technique I described above, tournament style. Then, after tournament rounds, new neural networks are created (through genetic algorithm) from the winners and losers are eliminated. The board evaluation function evolves naturally.

How to approach writing five-in-a-row Tic Tac Toe game AI? I was challenged by coworker into creating a Tic Tac Toe game AI that plays five-in-a-row games (not the traditional 3). My initial