Gomoku (Five in a Row, vs Computer)

Be the first to connect five stones of the same color in a row β€” horizontally, vertically, or diagonally. You play black, the computer plays white, and you go first.

Record 0W 0D 0LMoves 0

The rules this board follows

The game is played on a 15 x 15 grid. You play black and move first; the computer plays white. As soon as one side has five or more stones of its own color connected in a straight line (horizontal, vertical or either diagonal), that side wins immediately. If all 225 squares fill up with no winner, the game is a draw. Click an empty intersection to place a stone; the last stone played is marked so you can follow the sequence. Reading the code, the win test is simply "the connected line is at least 5 long", which means an overline of six or more also wins, and there are no forbidden moves such as the 3-3 or 4-4 bans that some rule sets impose on Black. This is usually called free-style Gomoku. The table compares it with Renju as it is generally described; Renju and tournament rules differ in details from one organization to another, so check the official rules of any event you plan to enter.

PointThis tool (free-style)Renju (general description)
Black double-three (3-3)AllowedForbidden for Black
Black double-four (4-4)AllowedForbidden for Black
Black overline (6+)Five or more winsForbidden for Black; usually a win for White
Forbidden moves for WhiteNoneNone
Opening restrictions or swap rulesNone (start freely)Tournaments often add a special opening procedure

It has long been argued that the player who moves first has an edge, and forbidden moves and opening rules are commonly explained as ways to reduce that edge. No single percentage can honestly be attached to it, though. Here you always start as black and face no restrictions, so the setup is as friendly to you as the game allows.

The board in numbers

On a 15 x 15 grid each row has (15 - 4) = 11 windows of five squares, which is where the line counts below come from. The table is computed when the page is built.

ItemValue
Intersections (squares)225 (15 x 15)
Places a horizontal five can sit165 (15 rows x 11 positions)
Places a vertical five can sit165
Places on a "\" diagonal121 (11 x 11)
Places on a "/" diagonal121
All possible winning fives572
Stones placed when the board is fullup to 113 black, 112 white

Every stone you place touches several of those potential fives at once. Squares near the center belong to many more windows than squares at the edge, so they carry more value for both attack and defense. That is why the first move is normally played near the middle.

Terms: threes, fours and what "open" means

How the computer chooses a move

The computer only considers empty squares within two squares of an existing stone. For each candidate it computes how good the square is for white (offense) and how dangerous it would be if black played there (defense). The final score is offense + defense x 1.1, so when two squares look equally valuable the computer slightly prefers the one that blocks you. For every direction the value depends on how many stones are connected and how many ends are open.

Connected shapeOne open endTwo open ends
5 or more100000 (win)100000 (win)
Four in a row100010000
Three in a row1001000
Two in a row10100
A single stone110

A shape blocked at both ends scores zero. Difficulty only changes how faithfully the computer follows this ranking: Easy takes the top-scored square 30% of the time and otherwise picks any candidate at random; Medium picks randomly among the five best squares; Hard always plays a highest-scoring square (random among ties). You can change the difficulty at any time and it applies from the computer's next move. The important limit is that the evaluation looks one move deep. It does not calculate several moves ahead to see a double threat coming, so even Hard can be beaten by a prepared double attack.

Three worked examples

Example 1: the square next to an open three gets blocked first. Say black has three stones in a row with both ends empty and white's stones are far away. The computer's score for the square right next to the three is 11064; for the square one step further out it is 84. Black playing next to the three would form an open four (worth 10000), so the defensive part dominates, and on Hard the computer blocks directly beside the three (either end, if tied).

Example 2: two open fours with one stone. If black has a horizontal three and a vertical three that meet at an empty square, playing there creates an open four in both directions at once. For black that square scores 10000 + 10000 + 10 + 10 = 20020 from the four directions. In free-style Gomoku this simply wins. In Renju it would be a forbidden 4-4 for Black. Here it is legal, so the computer must block that intersection beforehand or lose.

Example 3: filling the gap makes seven. If a row holds three black stones, one empty square, then three more black stones, playing in the gap produces a line of seven. The win test here is "five or more", so this wins at once. Rule sets that count only exactly five, or that forbid Black from making an overline, would not treat it as a win.

Strategy for winning

  1. Start near the center. It sits on the most potential fives and lets you grow in every direction.
  2. Spread your stones across directions instead of building one long line. A straight three is easy to block, but stones whose lines cross (horizontal, vertical, diagonal) set up double threats.
  3. Always block a four, and block an open three as early as you can. If your own attack is only a closed four, defend first.
  4. Save forcing fours for the moment they build a double threat. A four makes the opponent reply, but if you spend them randomly you lose them as weapons later.
  5. A three against the edge is a closed three. The board edge counts as a blocked end, so you need not treat it as a serious threat.

Misunderstandings and limits

Getting more out of each game

After a loss, look back at the last few moves and find where, two or three moves before the opponent's double threat appeared, you could have blocked a key square. That is the quickest way to improve. If you win several Medium games in a row, move up to Hard, and use Undo to test a different reply from the same position.

Frequently Asked Questions

What kind of game is Gomoku?

Gomoku, also called Five in a Row, is a two-player board game. Players alternate placing stones on a grid, and the first to connect five of their own color in a line wins. Black moves first. The name comes from Japanese, where gomoku means roughly "five points".

Does going first (black) help?

The first player is generally regarded as having an advantage, which is why rule sets such as Renju restrict Black. This tool uses free-style rules with no forbidden moves, and you always play black and move first.

Can I win with a 3-3 or 4-4?

Yes. Bans on double-three and double-four are restrictions Renju-style rules place on Black. This board only checks whether five or more stones are connected.

Does a line of six or more count as a win?

Yes. A connected length of five or more is a win here. Some rule sets require exactly five, so do not mix them up with this one.

Can I beat Hard difficulty?

It is possible. The computer only evaluates one move ahead, so it is vulnerable to a double attack where open threes or fours appear in two directions at once.

Are my record and game saved?

No. Reloading the page resets the record and the board, and there is no syncing between devices.

More board and logic games

For a simpler three-in-a-row game try Tic-Tac-Toe; for flipping stones to take territory there isReversi; Connect 4 in a Row uses gravity; and for a number-deduction puzzle see Number Baseball.