Play free Gomoku (five in a row) against the computer at three levels, or against a friend on the same screen. Freestyle rules, three board sizes.
You, solid 0
Computer, ring 0
Your move (solid)
Moves 0
Session You 0, Computer 0, Draws 0
Fewest moves in a win -
Wins saved 0
Take turns placing a stone on an empty point. The first to make an unbroken line of five or more stones, across, down or diagonally, wins. Solid stones go first, ring stones second. Arrow keys move around the board, Enter or Space places a stone. Undo takes back your last move and the computer's reply, and is off once a game is over.
At every level the computer first takes a win if it has one, then blocks your win if you have one. After that, Easy plays a random point next to an existing stone. Medium scores every point within two steps of a stone by the shapes it would build for itself (twos, threes, fours, open or closed) and the shapes it would stop you building, and plays the best one. Hard uses the same scores, looks for a win made only of fours, and otherwise searches three moves ahead with alpha-beta pruning over the 12 best-scoring points, for at most about a second. It is a heuristic search, not a perfect player, and a careful player can beat it. A game where you used Undo is not saved as a record.
As-is, no warranty. These apps are free under their listed license and run entirely in your browser. Use at your own risk — don't blame me if your PC catches fire, your dog runs away, or the math turns out wrong. Verify anything that actually matters. None of this is professional financial, medical, legal, or engineering advice.
Players take turns placing one stone on an empty point. Solid stones move first and ring stones move second, so the two sides are told apart by shape as well as colour. The first player to make an unbroken line of five or more of their own stones, across, down or on either diagonal, wins. If the board fills up with no such line, the game is a draw.
These are the freestyle rules: a line of six or more also wins, and the first player has no extra restrictions.
Click or tap a point to place a stone. With the keyboard, the arrow keys move around the board, Home and End jump to the ends of a row, and Enter or Space places a stone. The board is a soft teal; solid stones are sky blue and ring stones are amber with a hollow centre. The newest stone carries a small dot on a lime-tinted point, and a winning line is highlighted in green with a ring that pulses twice (not at all if your system asks for reduced motion). With a mouse, hovering an empty point shows a faint preview of the stone you would place. Undo takes back your last move and the computer’s reply, or one move in a two-player game. Once a game is over, undo is off.
The engine is a plain module with no page code in it, so the tests can play thousands of moves against it.
The board and the win check. The board is one flat array of n x n cells. After each move the game looks along the four line directions from the new stone, counting same-coloured stones in both directions, and reports every line of five or more it finds. Because it walks by row and column rather than by array index, a run cannot wrap from the end of one row to the start of the next; the tests check that case at the edges and corners of all three sizes.
A pattern table instead of pattern matching. To judge a point, the engine looks at the nine cells along a line centred on it. Each of the other eight cells is empty, one of the player’s own stones, or blocked (an enemy stone or the edge of the board). That gives 3^8 = 6,561 possible lines, and each is classified once when the page loads: nothing, two, open two, three, open three, four, open four or five. An open three is one that a single extra stone turns into an open four, which has two ways to finish and cannot be stopped with one block. Scoring a point is then four table lookups per side, one per direction.
Medium. Every empty point within two steps of an existing stone gets a score: the shapes a stone there would build for the computer, plus the shapes it would stop you from building (weighted slightly higher, so a threat is blocked rather than ignored), plus bonuses for combinations such as a double four or a four with an open three. It plays the best-scoring point, breaking ties at random. It has no look-ahead.
Hard. It uses the same scores and adds two searches. First it looks for a win made only of consecutive fours, up to four in a row: each four forces the opponent to block the single finishing point, so the sequence can be searched exactly. If there is none, it runs an alpha-beta search three moves ahead over the 12 best-scoring points at each step, deepening one move at a time so the answer is still sensible if the time cap of about one second is reached. The search ends by scoring the position: every window of five cells that holds only one colour counts, longer windows count more, and so does the best next shape each side could build.
Every level first takes a win if one is on the board, then blocks the opponent’s win. Easy otherwise plays a random empty point next to an existing stone.
How strong are they? The test suite plays seeded games with Hard’s one-second time limit lifted, so these results repeat exactly. On the page Hard keeps the limit, so on a slow device it may stop at a shallower search than in these games. On 13 x 13, alternating who moves first, Hard beat Easy in all 16 games, and Hard beat Medium in 8 of 16 with 3 losses and 5 draws. Medium beat Easy in at least 9 of 10.
Nothing is uploaded and there is no account. After a win against the computer, the page saves your number of wins and your fewest moves in a win for that difficulty and board size, in your browser’s local storage under one key, as small whole numbers inside a small JSON object. Only games against the computer where you did not use Undo count. The session tally lives in memory and resets when you leave the page, and the board size, opponent, difficulty and side are kept in the page address. Clearing site data removes the saved records.
Everything runs locally in your browser.
For informational purposes only. Not financial, medical, or legal advice. You are solely responsible for how you use these tools.