Gomoku against the computer

Play Gomoku online against the computer: line up five in a row before the machine does. Free, no sign-up, in the browser.

What this game is

Noughts and crosses grown to adult size. A 15×15 board, five in a row to win — and suddenly the game has depth.

Draws are rare on a board this size as long as somebody attacks: there is room for everybody, and such a game almost always ends with somebody completing a five. Two players who only ever block can fill the whole board instead. Threats decide everything. A three with both ends free already demands an immediate answer, and a move that creates two such threats at once usually ends the game, because only one of them can be blocked.

Hence the characteristic feeling of gomoku: you spend most of the game answering the other side's threats, and the winner is whoever first manages to answer in a way that creates a threat of his own.

Rules

How to play better

A bit of history

Row-building games are very old in East Asia. The Japanese name for gomoku — gomoku narabe, 五目並べ, literally "five stones lined up" — was already in common use in the Edo period. In Korea the same game is called omok.

Japanese players long suspected that with accurate play the first move settles everything. In the early 1990s Victor Allis proved it by computer search: free-style gomoku on a 15×15 board is a win for the player who moves first.

That is why the tournament variant, renju, restricts the first player specifically: certain shapes are forbidden to him, such as a double three or a row longer than five, while the second player has no restrictions at all. Here the rules are the plain free-style ones — and you move first, so the theoretical advantage is yours. Converting it is another matter.

This version follows the Gomoku applet that ran on this site from 2005. The marks are drawn deliberately crooked, with a thick pen and a slight tilt, the way the original had them: four different noughts and four different crosses, so that neighbouring marks never look stamped from the same die.

About the levels

Easy looks exactly one move ahead. It scores every empty cell near the existing marks by what it would build for itself and what it would take away from you, weighting your shapes slightly higher — which is why it blocks your open three instead of building its own. It will take a five and block a five, and an open four of its own comes before blocking your open three, since it wins first. But it never calculates your reply: a fork prepared two moves in advance is invisible to it and it walks calmly into it.

Hard checks the obvious first: it takes its own five and blocks yours. After that comes a four-ply search with alpha-beta pruning, cut off after four tenths of a second, though a move normally takes a few hundredths. It evaluates the whole board: every line is scanned with a six-cell window whose value comes from a precomputed table. Its blind spots: at each node it only examines the ten best-looking cells, so a fork that starts on the eleventh does not exist for it; and it has no special rule against an open four, so it can let one happen.

Expert deals with threats first and calculates second. It takes its own five, blocks yours, and plays its own open four immediately since nothing can stop one. If it is you who threatens an open four, it restricts itself to moves that either take that point away or answer with a four of its own — nothing else is worth playing. In a quiet position it deepens gradually: two plies, four, six, as far as it gets within seven tenths of a second, and an unfinished pass is thrown away entirely rather than trusted. The limits are the same as before: a dozen or so candidates per move, and cells more than two steps away from any existing mark are never considered — a genuinely distant move lies outside its world.

Where to go from here