How the Walled In networks work

Walled In took two network shapes. The first, the same small shape used for the other games, couldn't afford to look even one cell ahead, so it had to work around that. The second was built for the board, and it measures how much of the board each move would claim. It plays far better, with fewer weights. The positions and values below come from the networks' real weights.

The game

Two players move at once on a 10x10 board, each leaving a permanent wall. Crash into an edge or any wall and you lose, the last player able to move wins, and if both crash on the same step it's a draw.

The network plays against three ordinary programs, from weakest to strongest:

Scores on this page are percentages: a won game counts 1, a draw ½ and a lost game 0, averaged over 1,000 games, so 50% means even. A network's overall score is the average of its scores against the three programs. When two players meet directly, the same rule gives one player's score against the other.

Part 1: a small general network

Breakout and Airplane use a network with two hidden layers of 32 units each, and Walled In started with the same shape. That size was fixed in advance so that PPO, a standard reinforcement learning method, could train exactly the same network, for a fair comparison. Claude wrote its weights by hand. The first attempt was written blind, without ever running the network, and later attempts could learn from practice games. This part covers attempt 2, the best of four, with an overall score of 47.6%.

The problem the network has to solve

The obvious question is: if I move right, will I crash? The answer needs two facts together: where the head is, and whether the cell next to it has a wall. A single unit can check one exact combination, such as "the head is here and that cell is blocked". It fires only if both inputs are on.

But a unit's weights are fixed, so it can't change which wall matters as the head moves. A wall that's dangerous when the head is beside it means nothing from across the board. So there has to be one unit for every combination of head position and direction. Click a cell to see this.

Pick a head position

Head positionCellsNeighboursChecks
Corner428
Edge32396
Middle644256
Total100360

This network has 32 units in that layer, so it can't have these checks. That's the constraint behind everything below.

The strategy in plain words

If the network can't look ahead, it shouldn't need to:

  1. Follow a fixed route. Each half of the board has a closed loop through all 50 of its cells, so following it can't hit the network's own wall for 50 moves.
  2. Use rough sensors for the opponent. Each stretch of the route gets one sensor, which fires if the head is on that stretch and an opponent wall is somewhere on its next cells.
  3. Sidestep when a sensor fires, onto a neighbouring part of the route.

Which way to go is a lookup on the head's cell. The head is in exactly one cell, so one unit per direction can hold the whole route.

The layers

The route, read from the weights

Each arrow is what the route units say at that cell, with no sensor firing. Pick a sensor to see the head cells it covers and the cells it watches.

Route, with the selected sensor

  • head cells for this sensor
  • watched for opponent walls

Sidestep used while a sensor fires

One move, followed through the network

These positions are from one real game against the space seeker.

Board, row 0 at the top

  • network
  • opponent
  • arrow: head

Layer 1

Layer 2

Output

How the design got here

Only attempt 1 was written blind. Revising the sensors barely helped.

AttemptOverallWhat changedWhat happened
1, blind43.2%Route, sensors and sidestepsSome sidesteps hit its own wall
247.6%Removed sensors from the column 0 stretchFewer own-wall crashes, but it ran into opponent walls
343.9%Restored them, silenced near wallsOnly the mix of crashes changed
426.1%Ignored walls and charged the opponent's headMostly hit walls the opponent had just left

What the small network shows

Part 2: a network shaped for the board

The small network's trouble is that each unit is tied to fixed cells. The second network uses a different shape that removes this, and it answers the question the route avoided: how much of the board would each move leave me?

What a flood fill is

The name comes from the paint-bucket tool in drawing programs. Click inside a region, and the colour spreads from cell to neighbouring cell until it reaches a border. This network does the same from each player's head at once, with walls as the borders, to see how much of the board each player would reach first.

How the shape makes it possible

The small network would need 360 units just to check the next cell, one for every head position and direction. A convolution avoids this: it writes a rule once, as a small pattern of weights, and applies the same weights at every cell. So one rule does the work for the whole board.

Repeating that step also solves a bigger problem. Whether a move leaves room depends on the shape of the whole board. Spreading outwards one cell per step can follow walls around corners, which no fixed-size check can do. This network repeats its spreading step 30 times, with the same weights each time, so it has only 203 weights in all.

Where the idea comes from

This isn't a new strategy. Comparing who reaches more of the board first is how the territory player chooses its moves. Put in the network's seat, that program serves as a yardstick on this page, under the name lookahead program, and it scores 59.7%. What's new is writing that algorithm directly as weights, plus a few changes that turned out to matter.

The strategy in plain words

  1. For each of the 4 moves, imagine making it.
  2. Spread outwards from both players at once, one cell per step. Each cell goes to whoever reaches it first, and a tie counts for both.
  3. Count my cells minus theirs.
  4. Adjust that score, then pick the highest.

The layers

The one rule that does the work

Each cell's unit looks at the 3x3 patch around it. It fires if its total reaches the threshold, using these weights on "in my map" and two more on the same cell:

My map, 3x3

Same cell

free: +4
their map: −4
threshold: 4.5

Situation at this cellTotalResult
Already in my mapat least 8 + 4 − 4 = 8fires
Free, unclaimed, one neighbour in my map1 + 4 = 5fires
Free, unclaimed, no neighbour in my map4off
Claimed by them, all 4 neighbours mine4 + 4 − 4 = 4off
A wall, all 4 neighbours mine4off

So 5 reaches the threshold of 4.5 and 4 doesn't, and this one rule covers every case. The opponent's map uses the same rule with the maps swapped. In the actual weights, these numbers are scaled up by 20 and adjusted for the units' −1 to 1 range, so each unit is firmly on or off.

Watch it fill the board

Pick a position from a real game, and a move to try. Then drag the slider or press play to spread both maps. The network here is attempt 2, a revision of the blind attempt 1 described below.

  • network's head and walls
  • opponent's
  • I reach first
  • they reach first
  • tie

The score for each move, in cells

The score

Attempt 1 was written blind. Attempt 2 changed only these settings, after practice games showed many games ending in head-on draws.

PartAttempt 1Attempt 2Why
Not crashing+1,000+1,000Larger than any possible territory
My cells minus theirs1 per cell1 per cellThe main idea
Possible head-on crash at my target−5−80The opponent could enter the same cell, and both would crash
Free neighbours of my target−0.25 each−1 eachHugging walls seems to leave less wasted space

The network's output for each move is 20 times its score. Outputs are turned into move probabilities that rise steeply with the score, and the move is drawn at random. So a one-cell lead is nearly certain to win, and exact ties are broken at random.

Could training find this?

PPO trained these same 203 weights from random values for 1M moves, and it scored 13.9%. It didn't discover the fill. Compare its pattern with the handwritten one, on the same colour scale:

Handwritten: spread, on my map

PPO: the same weights after 1M moves

The handwritten pattern's largest value is 80. PPO's stay below 1, so its units never become sharp on/off logic, and they don't form the cross shape the fill needs. This was one short run, so it shows PPO doesn't find this easily, not that it never could.

Results

NetworkOverallWandererSpace seekerTerritory player
Flood-fill attempt 1, blind70.1%87.4%81.9%41.2%
Flood-fill attempt 2, revised75.8%98.0%94.0%35.3%
Flood-fill shape, PPO for 1M moves13.9%10.1%6.5%25.2%
Lookahead program59.7%69.3%58.8%51.1%
Best small handwritten network47.6%69.2%27.4%46.3%
Best small PPO network, 10M moves39.2%44.0%23.7%50.0%

Head to head

The networks and the lookahead program also played each other. Each cell is the row player's score against the column player, over 1,000 games, with a draw counting as half. Blue means the row player scored above 50%, and orange below.

These results don't form a single ranking. Lookahead beats both flood-fill attempts, the flood-fill attempts beat the small networks, and the small networks hold lookahead close to even, mostly through draws. A likely reason, which wasn't tested directly: giving way at a head-on cell beats an opponent that charges, but hands territory to one that takes it. That's also why attempt 2 scores higher on the fixed opponents yet loses to attempt 1 here.

The same algorithm as a program

If the weights only encode an algorithm, the algorithm can also be written as ordinary code. A program written from attempt 2's design notes, with true/false board maps, cell counts and a loop of 30 spreading steps, but no weights, was compared with the network.

CheckProgram, 30 stepsProgram, uncapped
Positions where the best move differs, of 21,94701
Scored games identical to the network's, of 3,0003,0002,998
Overall score75.8%75.8%
Score against the lookahead program33.7%33.7%

The 30-step program is an exact twin of the network. The uncapped one spreads until nothing changes, and it shows what the network's fixed depth costs: one position in 21,947, which changed 2 games but no results. That limit comes from the number of repeats, not the number of weights, since the same 203 weights are used at every step.

What the flood-fill network shows

The best flood-fill network was also trained further with PPO, and a small PPO network was edited by hand. Both are on Training and hand-editing.