Five-in-a-Row — Gomoku Strategy Game
Place stones on a 15x15 grid. First to get 5 in a row wins. Play against a heuristic AI.
How to play
- Click any empty cell on the 15×15 board to place your black stone.
- The AI immediately responds by placing a white stone.
- First player to place 5 stones in an unbroken row (horizontal, vertical, or diagonal) wins.
- Block the AI's threats while building your own sequences.
- Click 'New Game' to start a fresh board at any time.
Place black stones on a 15×15 board. The first player to form an unbroken line of exactly 5 stones (horizontally, vertically, or diagonally) wins. The computer plays white with a heuristic AI.
How it works
Five-in-a-Row, known in Japan as Gomoku, is played on a 15x15 grid of intersections. Players alternate placing stones of their colour. The first player to form an unbroken line of exactly five (or more) of their stones — horizontally, vertically, or diagonally — wins the game.
Unlike Four-in-a-Row, the large open board means threats can develop in many directions simultaneously. Strong players build sequences of three and four stones called open threes and open fours, which each require a defensive response. When two such threats appear at once (a double-three or four-three combination), the opponent cannot block both and loses.
The AI in this widget uses a heuristic scoring function that evaluates the board position and picks moves that build threats and block yours. It provides a challenging game for beginners and casual players. More experienced Gomoku players will find room to experiment with standard opening patterns and forcing-sequence tactics.
Gomoku is an excellent introduction to abstract board game strategy. The rules are simple to learn yet the game has enormous depth, and a single session of play sharpens pattern recognition and multi-step planning.
Worked example
Build an open four to force a win
- Place your first stone near the centre of the board.
- Over several turns, build a row of three stones with both ends open (neither end blocked by the edge or an opponent stone).
- The AI must respond to this open-three threat. Continue extending another line in a different direction.
- Create an open-four (four in a row, one end open) that the AI must block immediately.
- While the AI blocks the four, place your fifth stone to complete the five-in-a-row on a different line.
You win by forcing the AI to block one threat while you complete another.
Common mistakes to avoid
- Placing stones randomly without building connected sequences — scattered stones create no meaningful threats.
- Responding to every AI threat without developing your own attack; pure defence leaves you no path to five-in-a-row.
- Building lines along a single direction only, which is easy for the AI to block; spreading threats across horizontal, vertical, and both diagonals is much harder to counter.
Key terms
- Open three
- Three consecutive stones with both ends open — a threat that must eventually be blocked if the opponent cannot win first.
- Open four
- Four consecutive stones with at least one open end; the player must complete the five on their next turn unless blocked immediately.
- Double-three
- A position where a single stone placement creates two open-three threats simultaneously — very difficult to defend against.
Frequently asked questions
- What is five-in-a-row?
- Also known as Gomoku, it is a classic abstract strategy game where two players alternate placing stones and the first to align 5 in an unbroken row wins.
- Does the AI look ahead?
- The AI scores every candidate cell using a fast heuristic (threats of 4, 3, 2) without deep minimax, so it is beatable with good play.