PUZZLTHINK

DEV NOTE

WallgoWallgo II

How the Wallgo AI plays

From one scoring formula to a search that reads to the end of the game.

Wallgo was the first board game built for PUZZLTHINK, and its AI was rewritten more often than any other. This note follows the commit history to explain what each Wallgo and Wallgo II difficulty actually computes, and why it changed.

Nothing is hidden: every level's calculation is written out, including where the Very Hard AI stops reading. If you only want to win, skip to the last section, "Gaps a human can use".

Play now

Published · 2026-11-26

Day one: a single formula

Wallgo went live on the afternoon of 16 November, with a very simple AI. It tried every "move + wall" combination and scored the result with one formula: closed territory × 7, largest own area × 2, minus the best rival’s territory × 3, plus a little for mobility, plus some randomness. Easy picked any of them, Normal one of the top four, Hard the best.

The trouble is that Wallgo areas hardly ever close before the end. A formula that only counts closed areas sees almost every opening and middle-game move as "no difference", so the random term was really choosing. Placement was the same: it only followed distance rules such as "keep my pieces apart, stay near the centre".

That night: counting the squares you reach first

Around 10 pm the same day came the first big rewrite (commit message: "reach-first territory estimate, 2-ply hard mode"). The idea is to count territory before it is closed. A breadth-first search runs from every player’s pieces at once and finds, for each empty square, who reaches it in the fewest steps. Walls and pieces block the way; a square two players reach in the same number of steps belongs to nobody. It is the "Voronoi territory" idea familiar from Go programs.

Today’s evaluation is: my expected territory × 3, minus the strongest rival’s × 2, minus the other rival’s × 0.6, plus already-settled squares × 0.5, and a "trapped" penalty of 4 for a piece with no open side and 1.5 for a piece with one. Once the board is fully separated the game is decided, and ±10,000 (5,000 for a shared win) replaces the estimate.

How Easy, Normal and Hard choose

All three levels start from the same candidate list: every "move + wall", scored with the evaluation above and sorted. They differ in what they take from it.

LevelChoosing a movePlacement
EasyRandom from the better half; it can miss a winning move.Any empty square
NormalA move that wins on the spot if there is one, otherwise random from the top 3Territory estimate + large noise (±1.5)
HardFor the top 10–14 candidates, reads the next player’s best reply and compares 75% of that result with 25% of the current scoreTerritory estimate + small noise (±0.3)

Hard assumes the opponent answers with the same one-move evaluation. It reads 14 candidates in 1:1 and 10 in 1:1:1.

Why 1:1:1 Hard was no harder than Normal

When the levels were retuned from play data on 26 November, 1:1:1 Hard showed an odd number. As the code comment records, people were winning about 47% against both Hard and Normal, where three equal players would each win 33%. The cause: Hard only read the reply of the next player, not the third. In 1:1:1 it now reads the third player’s answer too, with 10 candidates instead of 14 to pay for the extra work.

Very Hard: a search that reads to the end

The hell-mode AI added on 24 November, 1:1 only. Wallgo and Wallgo II share the engine.

Hard looks two plies deep: my move, then the reply. Very Hard was written from scratch to remove that limit, in the way chess engines are built: iterative-deepening negamax with alpha-beta pruning and a transposition table. Here one ply is a whole turn — a placement, or a move plus the wall that follows it. The placement phase is searched with the same tree.

  1. STEP 01

    The board as numbers

    The 7×7 board becomes a 49-cell array and each cell keeps its walls in 4 bits. Every position gets a Zobrist hash, so results can be reused from a transposition table of about 520,000 (2^19) slots when the same position comes up again.

  2. STEP 02

    Fewer candidates

    There are too many moves to read them all, so they are ordered by the static evaluation and only the top 28 are read at the root, then 16 → 11 → 8 → 7 → 6 deeper down (forward pruning).

  3. STEP 03

    One depth at a time

    It searches 2 plies, then 3, then 4… Reading the previous depth’s best move first lets alpha-beta cut far more. From the second move on, a quick null-window probe checks whether a move can beat the best so far, and only then is it searched exactly.

  4. STEP 04

    Everything at the end

    Once 14 or fewer squares are still contested, pruning is switched off and every move is read. If that finishes in time the result is not an estimate but the exact outcome.

The evaluation was rewritten too. It still counts squares reached first, but gives 35% of the equidistant squares to the side to move, scores open sides (liberties) and trapped pieces separately, and during placement penalises pieces on the board edge. Finally a tiny per-position jitter (±0.175) makes equal moves vary from game to game.

It thinks for 1.5 s on a computer and 1 s on phones and tablets. The search runs in a Web Worker so the page never freezes, falling back to the main thread where workers are not available. If the next depth would not finish (55% of the time is gone), it stops and plays the best move of the last finished depth.

Real win rates

Signed-in players’ games against the AI, aggregated on 2026-11-26 at 14:00 KST.

1:1, the human’s win rate over all games
LevelWallgoWallgo II
Easy93.9% (33 games)77.3% (22 games)
Normal49.1% (426)51.0% (392)
Hard27.0% (477)31.2% (282)
Very Hard7.6% (158)11.6% (155)

By then 9 players had beaten Very Hard Wallgo and 15 had beaten Very Hard Wallgo II, earning the hell certificate. Counting everyone, signed in or not, Wallgo had been played 8,750 times (7,636 against the AI) and Wallgo II 7,624 times (6,006 against the AI).

Gaps a human can use

Knowing what the AI computes shows where it is weak. Only gaps that can be read straight from the code are listed.

Normal

Luck unless it can win now

Normal picks at random from the top three. Unless a move ends the game, it often plays the second or third best — wait for one slip, then build the wall that splits the board.

Hard

Traps two turns away

Hard sees its move and the opponent’s one-move best reply, no more. A room that closes with two walls on your third turn is invisible to it. And only the top 10–14 one-move candidates are read, so a move that looks like a loss right now is never considered.

Very Hard

Moves outside the pruning

Moves with a poor static score are not read deep in the tree (11 at depth 3, 8 or fewer below). "Sacrifices" that shrink your area now but close a big room a few turns later are the kind most likely to work.

Very Hard

Keep the middle game long

Exact endgame reading starts only at 14 or fewer contested squares; before that it is an estimate. Build your lead while many squares are still open rather than settling areas early.

Very Hard

A little weaker on phones

Same AI, but only 1 s of thinking on touch devices — some positions are one depth shallower.

All

It dislikes the edge

Every level prefers central placements and Very Hard penalises edge pieces. Expect the AI to crowd the middle and place to make your first walls count.

Where this comes from

This note is written only from the code, the commit history and the aggregate numbers below.

  • `src/lib/wallgo.ts` — the AI section (estimateTerritory, evaluatePosition, chooseBotAction, chooseBotPlacement)
  • `src/lib/wallgoHell.ts`, `src/lib/wallgoHellClient.ts`, `src/lib/wallgoHell.worker.ts` — the Very Hard search
  • `scripts/wallgo-selfplay.ts` — the self-play script
  • Commits 2930926 (11/16 first Wallgo), 3f3d32f (11/16 territory estimate, 2-ply Hard), a58d850 (11/19 Wallgo II), 230c126 (11/24 Very Hard and its self-play results), e227318 (11/26 1:1:1 Hard retune)
  • DB aggregates (2026-11-26 14:22 KST): win rates from game_results (mode = ai) by game, player count and level; hell_clears per game; game_plays_daily totals by game and mode

Read next

  • 12 Janggi AI dev notes

    Why a 7-ply Hard was almost unbeatable and went down to 5, the no-third-repetition ban, and a Very Hard that reads 13–19 plies.

  • Russian Janggi AI dev notes

    Even the Very Hard engine that reads to the end must lose to a first-move large cup in the centre — and how that shaped the AI and its win rate.

  • Blind Gomoku AI dev notes

    AIs that remember only the last 3, 8 or 36 moves, and a Very Hard one with full memory and VCF/VCT threat search — and how forgotten stones become a weakness.

All dev notes →