Gomoku

Play Gomoku against the computer: five in a row wins.

Moves0
Streak0
Best streak0

You play black and move first; the AI plays white. Tap an intersection to place a stone (or move the cursor with arrow keys and press Enter). Line up five in any direction to win: the AI balances attack and defence.

FAQ

What are the rules?
Two players alternate stones on a 15-line board, black first. The first to line up five or more stones horizontally, vertically or diagonally wins; a full board is a draw. This version uses freestyle rules with no forbidden-move restrictions.
How does the AI play?
The AI scores every candidate point for attack and defence: completing five, making four or open threes is prioritised on offence, while it blocks your fives and open threes on defence. Offence is weighted slightly higher: a friendly mid-strength opponent for casual games and practice.
How many moves does Undo take back?
One Undo removes both your last stone and the AI's reply, keeping the turn yours. Undo is locked once the game is decided: start a New game for the next round.
How does the streak work?
Consecutive wins add up, and a loss or a draw resets the count. Your best streak is stored locally in the browser and survives page reloads.

How to use

  1. Play black, move first

    You take black: tap an intersection to place a stone, or move the cursor with arrow keys and press Enter. The AI answers with white.

  2. Five in any direction wins

    Line up five stones horizontally, vertically or on either diagonal. Freestyle rules apply: overlines also win and there are no forbidden moves.

  3. Read the AI game

    The AI completes its own fives and fours and blocks yours, weighting offence slightly over defence. Your open threes often trade into its counter-attacks.

  4. Undo to explore

    One undo removes both your last stone and the AI reply, perfect for testing alternative attacks. Undo locks once the game is decided.

  5. Build a win streak

    Consecutive wins accumulate, and a loss or draw resets the count; your best streak is stored locally across games.

About this tool

Gomoku originated in China, and it is among the most widely played board games in the world. The rules take a minute, yet the strategy is bottomless. It is lighter than Go and far deeper than tic-tac-toe. Its charm lives in the exchange of threats, with open threes, fours and double threats trading initiative back and forth.

This build ships a heuristic AI that scores every candidate for attack and defence. It balances fives, fours, open threes and blocks at a friendly mid-strength level. The 15-line board renders and computes entirely in your browser, with undo, streak tracking and full keyboard play. It is an ideal brain break between tasks.

The AI scoring table is visible right in the code. A completed five counts 100000, a live four 10000, a blocked four and an open three 1200 each, and an open two 120. Every candidate is summed across four directions. Attack is then multiplied by 1.05 before the defence score is added, which makes the machine slightly aggressive. That single weighting explains its habit of answering your open three with its own offence, gambling that it connects first. Once you can read the table, you can bait it into defence and build a double threat behind its back.

How it works

Gomoku speaks in threat levels. Five is absolute, a four demands an instant answer, and an open three with both ends free converts into a four on the next move. The advanced core is the double threat. One move can create two open threes, or a four plus a three, and the opponent can only block one. Most games at every level are decided by these double attacks, not by slow stone-building. Under freestyle rules overlines win too, so a long line is a weapon, not a bug.

The simple rules hide a game that mathematics has already solved. In the early 1990s the computer scientist Victor Allis proved, with threat-space search, that free-style gomoku is a first-player win under perfect play. The practical lesson is that initiative compounds move by move. Every stone should answer one question: did this add a threat of mine, or remove one belonging to the opponent? The built-in AI scores every candidate for attack and defence. Once you can read its priorities, double threats it cannot cover both become your standard winning route.

The AI answers after a delay of roughly 300 milliseconds, so stones arrive at a human pace and collapses never come instantly. Undo removes your last stone and the AI reply together. The board stays pinned to the state before your move, so every experiment is traceless. Your streak and best streak are stored locally under the key t55k6-gomoku. A loss or draw resets the current run, while the best survives across sessions. The board is 15 by 15, and corners offer the fewest growth directions, which is exactly why openings belong near the centre.

When to use it

  1. A first board game

    Rules in one minute, a game in three to five: the lowest-pressure entry into board-game thinking. Once a child learns to block a three, games become genuinely contested, and confidence arrives early.

  2. A desk-break match

    Arrow keys plus Enter place a stone, so a discreet game fits between tasks. Undo removes both your stone and the reply, which makes experiments free, and that is the ideal way to rehearse a new attack line.

  3. Two-way scanning practice

    Every move answers two questions: do I have the faster five, and where does the opponent connect next? That bidirectional habit is the heart of board-game thinking, and the streak counter scores it.

  4. Reading the machine

    Blocked fours and open threes carry the same value in its table, so its threat ranking is fully predictable. Sacrificing a fake open three to drag it aside is a cheap sandbox for learning threat exchanges.

Tips & tricks

  • Claim the centre early: stones near the middle radiate into the most directions.
  • Make open threes early: two crossing open threes are practically impossible to block both at once.
  • Defend one move ahead: before blocking an opponent four, check whether you have a faster five of your own.
  • Against this slightly attacking AI, defence first pays. Force it with a four, let its reply drift away from your main front, then return to your own open three.

Things to watch

  • Building only your own lines

    Laying out your own threes while the opponent completes theirs loses quickly. Before each stone, check the longest enemy line, because its threat level outranks your own progress almost always.

  • Leaving open threes alive

    An ignored open three becomes a four, then a five, so block it before it upgrades. Reacting only at the check moment means running two moves late, the number one way newcomers lose.

  • Opening in the corners

    Edge and corner stones grow in two or three directions at most, while centre stones radiate everywhere. Keep the first few moves near the middle, and your later connections multiply.

  • Getting loose on a streak

    The rising streak invites offence, yet the AI scores its own fours just as high. One missed block can wipe the count, so every three moves scan both ways: my fastest five, and theirs.

Related Tools