← Gomoku against the computer

Gomoku Strategy: Threes, Fours, Forks and How to Beat the Computer

The numbers on this page come from the game as it is played here — a 15×15 board, free-style rules, you move first — using the page's own code for all three computer levels: 3,000 simulated games for each figure against Easy, 1,000 against Hard, 500 against Expert. The winning lines were replayed move by move against the real engine, and the shortest win over Easy was found by checking every possible game.
The short answer

Gomoku is won with a fork: one stone that makes two threats at once — two open threes, or a four and a three — because only one of them can be blocked. To get there you need the initiative: in simulation, a player who blocks only real threats and otherwise builds his own line beats Easy here in 74% of games, while a player who blocks first, the way Easy itself plays, wins 5% and draws 91%. Easy and Hard always answer the same position the same way, so a fixed list of moves beats them every time: seven moves against Easy, which is the minimum, and nine against Hard.

Four shapes, counted in moves to five

Everything in Gomoku is measured by one question: how many more stones does this row need to become five, and how many points can stop it? Four shapes cover nearly every decision.

Open three. Blue is you. Either marked point makes an open four, so it has to be answered now.
Split three. The same threat with a gap: the marked point makes an open four.
Four. Red (the computer) holds one end, so there is one winning point, and it must be blocked at once.
Open four. Two winning points and one move to block: the game is over.
  • A four is one move from winning. The reply is forced, and that is its value: you choose where your opponent's next stone goes.
  • An open four cannot be stopped. Only a five made first beats it.
  • An open three, split or not, is two moves from winning and one move from an open four. It must be answered immediately, either by blocking or by a four of your own.
  • A closed three — one end blocked by a stone or by the edge — threatens nothing yet. It becomes a plain four, which is blocked in one move.

All three computer levels here know these shapes. In test positions each of them blocked an open three at one end, took the gap of a split three and blocked a four. None of them can be beaten by a single row; what beats them is two rows at once.

The rules here are free-style: a row of six or more also wins, and neither side has forbidden moves. That is how the code works, not just what the rules page says — a win is any unbroken row of five or longer.

Forks: 4-4, 4-3 and 3-3

A fork is a stone that makes two of those threats together. There are three kinds, and they differ in speed:

  • 4-4 — two fours at once. Two winning points, one block: you win next move.
  • 4-3 — a four and an open three. The four must be blocked, then the three becomes an open four. You win in two more moves, and your opponent never gets a free move.
  • 3-3 — two open threes. One is blocked, the other becomes an open four. Also two more moves, but the opponent gets one free move after the fork — so it only works if he has no four of his own to play first.

Here is a 3-3 against Hard, from the winning line given below. One of the two threes has a gap in it, which makes the fork point harder to see — for a person and for a program.

Against Hard after six moves each; blue is you, red the computer, whose last stone is ringed. The marked point j9 makes two threes: the diagonal h7–i8–j9 and the row g9, h9, gap, j9.
Hard blocked the diagonal (ringed). Now the gap i9 turns the row into an open four with two winning points, f9 and k9.

The gap matters most against Easy. Easy scores a point by the unbroken row a stone would make there, so a three with a hole in it is invisible to it until the hole is the only thing left. When two unbroken lines of yours cross on an empty point, Easy takes that point; when one of them has a gap, it does not see the fork coming.

In renju, the tournament form of the game, the first player is not allowed to play 3-3 or 4-4 at all. Here both are legal, and you are the first player: the fork is your main weapon, not a trick.

Initiative: build first, block only what is real

The most expensive habit in Gomoku is answering everything. We tested it directly, playing against Easy with the rule Easy itself uses — score every point by what it builds for you and what it takes from the opponent, with blocking weighted slightly higher. That player won 4.6% of 3,000 games, lost 4.3% and drew 91%: the board simply filled up.

Turn the priorities around — block only a real threat, otherwise extend your own best line — and the same Easy loses most of the time:

  • blocking nothing but a four: 56% wins, but 42% losses;
  • blocking fours and open threes: 65% wins;
  • also playing your own forks, counting threes with a gap, and taking the point where the computer could fork: 74% wins, 14% losses.

A real threat is short to list: a four, an open three (split or not), and an empty point where two of the opponent's lines would become threats together. A closed three is not one. Two stones in a row are not one. Every move spent on those is a move in which your own position did not grow.

Easy has one more weakness worth knowing. It values blocking your open three slightly above making its own open four. In a test position where both sides had an open three and it was the computer's move, Easy blocked instead of winning; Hard and Expert played the open four. So against Easy every three or four you make buys a move, even when the computer is about to win.

Draws are rare between attacking players, but not in general. Easy against a copy of itself drew 84% of 2,000 games, with the board filled to the last point, and Hard against Hard drew 30% of 1,000.

The first move and the centre

With free-style rules on a 15×15 board the first player wins with perfect play: this was proved by computer search in the early 1990s (Victor Allis and colleagues). That is a known result, not ours, and nobody plays perfectly — but the advantage is visible in ordinary games too.

We let each level play itself, with the first two stones placed at random near the centre. Hard against Hard: the first player won 47% of 1,000 games and the second 23%, the rest were draws. Expert against Expert, held to four moves of lookahead: 69% against 20% in 500 games. Of the games that somebody won, the first player took two out of three at Hard's strength and nearly four out of five at Expert's. Here the first move is always yours.

Start in the middle. There are 572 different places for a five on this board. Any point of the central 7×7 square lies on 20 of them; a point in the middle of an edge lies on 8, and a corner on 3. A stone near the edge has fewer rows to grow into, and the edge itself acts as a block on every line that reaches it.

From the second move on, play close. The computer never considers a point more than two steps away from every stone on the board, and it has no reason to: a stone that touches nothing builds nothing.

How to beat each level here

Here is how simple ways of choosing a move do against each level. You play blue and move first; the first stone goes in the centre, the second at random within two points of it, and ties between equally good moves are broken at random.

Your rulevs Easyvs Hardvs Expert*
A random point next to a stone0%0%0%
Block first, as Easy does (its own scoring rule)5%15%4%
Extend your best line; block only a four56%1.5%0%
…and block open threes, play your own open four65%18%19%
…and play forks, counting gaps; take the computer's fork point74%36%35%

* Expert is limited by time and searches two, four or six moves deep depending on the device. The Expert column was simulated at a fixed depth of four. At the full depth of six the last rule won 26% of 200 games. The block-first rule mostly draws: 91% of games against Easy, 34% against Hard, 32% against Expert.

Easy and Hard involve no chance: the same position always gets the same reply. So a game that beats them once beats them every time. Points are named like squares on a chessboard, letters a–o from left to right and rows 1–15 from the top (the game itself shows no labels); the centre is h8.

Easy, in seven moves. Play h8, e9, f10, e10, e11, g9, d12. The computer answers g7, h7, d8, d10, e8, i7. Your fifth move, e11, makes two threes at once — the column e9–e10–e11 and the diagonal h8, gap, f10, e11. Easy blocks the column, g9 fills the gap into an open four, and d12 completes the five. No shorter win exists: we checked every game of six moves or fewer from every first move, 16.4 million positions.

Easy after four moves each: blue is you, red the computer. The marked point e11 makes a three in the column and a split three on the diagonal up to h8.
The end: d12 (ringed) completes the diagonal d12–e11–f10–g9–h8.

Hard, in nine moves. Play h8, h6, i8, g9, h9, h7, j9, i9, k9. Hard answers g7, h5, g8, i7, j7, h10, g6, f9. The seventh move, j9, is the fork shown above; i9 makes the open four, and k9 wins. This is the shortest line we found, not a proven minimum.

Hard after your ninth move, k9 (ringed): five in a row from g9 to k9.

Expert depends on the speed of your device, so no line is guaranteed. On a fast computer, where it finishes its full six-move search, it is just as predictable, and this line won every time we replayed it: h8, g5, g6, i5, f7, h4, i6, d7, i7, i2, j6, k5, g9, with Expert answering h6, f6, g7, f5, h5, g4, e6, i3, h3, i8, g3, l4. If its first reply to h8 is g7 rather than h6, your device is cutting the search short and the line will not hold. Then play by the rules below: the last rule in the table won about a third of its games against Expert, and the games it won took 23 moves on average.

The rules of thumb, in order of value

  1. Complete a five if you can; otherwise block the opponent's four.
  2. Make an open four, or a four that also makes a three, whenever one is on offer.
  3. Block an open three, split or not — unless you can answer with a four of your own.
  4. Play a point that makes two threats at once, and count threes with a gap when you look for it.
  5. Take the empty point where two of your opponent's lines would become threats together.
  6. Otherwise extend your own best line, near the centre and close to your other stones. Do not block twos and closed threes.

Against Easy, rules 1 and 6 alone win 56% of games, rule 3 raises that to 65% and rules 4 and 5 to 74%. Against Hard the same steps give 1.5%, 18% and 36%.

Questions and answers

How do you win at Gomoku?

With a fork: one stone that makes two threats at once, such as two open threes or a four and a three. Only one can be blocked. Until you have one, block only real threats — a four, an open three, a point where the opponent could fork — and spend every other move on your own line.

What is the best first move in Gomoku?

The centre. On a 15×15 board there are 572 places for a five; a point in the central 7×7 square lies on 20 of them, a point in the middle of an edge on 8 and a corner on 3.

Does the first player always win in Gomoku?

With perfect play, yes: free-style Gomoku on a 15×15 board was proved a first-player win by computer search in the early 1990s. In our simulations of the computer playing itself, the first player won 47% of games to the second player's 23% at the Hard level. In this game you always move first.

Is a double three (3-3) allowed in Gomoku?

In free-style Gomoku, which is what this game plays, yes: 3-3, 4-4 and rows longer than five are legal for both sides. In renju, the tournament variant, they are forbidden to the first player.

Does six in a row win in Gomoku?

Here it does. The rules are free-style, so any unbroken row of five or more wins. Some rule sets (standard Gomoku, renju for the first player) do not count a row of six.

Can you beat the computer at Gomoku?

Yes. Easy and Hard here are fully predictable, and fixed lines beat them every time: seven moves against Easy (h8, e9, f10, e10, e11, g9, d12), which is the shortest possible, and nine against Hard (h8, h6, i8, g9, h9, h7, j9, i9, k9). Expert is stronger and depends on the speed of your device; simple attacking rules win about a third of games against it.

Should you attack or defend in Gomoku?

Attack, and defend only against real threats. Against the Easy computer here, a player who blocks first won 5% of simulated games and drew 91%; a player who builds his own line and blocks only fours, open threes and fork points won 74%.

Play Gomoku against the computer →
Where to go from here
To cite this page: “Gomoku Strategy: Threes, Fours, Forks and How to Beat the Computer”, You vs Computer, https://youvscomputer.com/games/gomoku-strategy.html