cadence / Connect Four / helpBack to the demo

Connect Four

You play Connect Four against a brain made with Cadence. On the right you watch that brain think: every neuron, every region, and the messages between them while it settles on its move.

What it shows about CadenceCadence brains excel at games. This one proposes every move by settling its whole brain, and judges the game in the same settle. With a small search over the rules to check its moves, it wins 363 of 400 games against a perfect player from the first seat. Show it a better move and it learns in your browser, with a local rule and no backward pass.

What you see

MOTOR NEURONS New game · Brain + search | alone · Teach it The whole brain settled in 64 sweeps 1 visual cortex the board, 3 ways 2 module 0 3 association 4 prefrontal silent 5 motor strip 6 verdict 7 verdict + search 8 the board and its controls
The page after a move. The numbers match the list below.
  1. Visual cortex: the board. Three small 6 by 7 boards at the back of the brain: one neuron for each cell holding its own stones, one for each cell holding yours, and one for each cell where the next stone in a column would land. These 126 neurons are the brain's eyes on the game.
  2. Module 0. 1,024 neurons that read the board cells and pass on what they see. Each sits where the cells it reads are.
  3. Association. 1,024 neurons wired both ways with module 0 and with the motor neurons. Here the settle comes to agree on a move. Each sits under the column it drives.
  4. Prefrontal, silent. Where Cadence's working memory enters a brain. A Connect Four board shows everything there is to know, so this brain settles fresh on each move, without memory, and the region stays dark.
  5. Motor strip. Seven neurons, one per column. The bars above the board are the same seven neurons. The strongest one whose column has room is the brain's own move.
  6. Verdict. Three neurons that judge the game for the side to move: loss, draw or win. They settle together with the move. The line "Its verdict before this move" above the board reads them. The move does not read them.
  7. Verdict and search. After a move, a small panel at the bottom left of the brain shows the verdict and the search's score for each column. A dashed box and a dashed arc mark the brain's own column when the search played another one.
  8. The board. Your stones are orange, the brain's teal. Under the board, a line says what is happening and what you can do next, and the buttons start games and teach the brain.

The lines between regions are synapses, drawn in bundles like the fibre tracts of a real brain. A line glows with the message it carries in this sweep: warm when it excites the neuron it reaches, cool when it inhibits it. Rest the pointer on any neuron and a card shows its activity and its strongest inputs at that moment. Every part with a small ? explains itself the same way.

Why it matters

A brain that plays well. Connect Four is a solved game: whoever moves first can always win, but only by playing perfectly from the first stone to the last. A perfect player in the second seat loses to nothing less. Against such a perfect player, moving first, this brain with its search won 363 of 400 games, drew 25 and lost 12. The brain alone, with no search, won 119 of 200. Moving second, it lost every game, as every player does against perfect play.

An answer that settles. A conventional neural network answers in one pass from input to output. A Cadence brain answers by settling: its regions send messages both ways, each neuron adjusts to the others, sweep by sweep, until the whole brain agrees and nothing changes. The page draws that settle as it happens. The move and the verdict come out of the same settle.

A brain that learns during its life. Press Teach it and show the brain a better column: it takes a lesson right there, in your browser, and the same board settles again with the changed synapses. A Cadence lesson is local: the brain settles again with its output nudged toward your column, and each synapse changes by how the activity of the two neurons it joins differs between the two settles. No error is sent backwards through layers, and there is no separate training mode: the brain that plays is the brain that learns.

No conventional network was trained for this demo, so the page makes no claim that Cadence plays better than one. It shows a Cadence brain playing strong games, the settle behind every move, and a lesson changing it.

What you can do

How it works

Senses. 126 neurons see the board: the 42 cells of the side to move (on its turn, the brain), your 42 cells, and the 42 cells where a stone would land.

Thinking. On its turn the whole brain settles from rest. Every sweep, each neuron updates from the neurons it reads, in both directions between regions, until no neuron changes by more than 0.003 (at most 1,024 sweeps; a move here takes about 50 to 120). Nothing is carried from one move to the next: the board shows everything.

Acting. The strongest of the seven column neurons whose column has room is the brain's move. With Brain + search, a search then looks ahead over the rules of the game, 9 to 12 moves deep: it plays a win it can prove, drops columns it proves lost, and otherwise keeps the brain's column unless another scores clearly higher. The search is ordinary code: it knows the rules, has no neurons, and does not learn. In the 400 games against the perfect player it changed the brain's column on 3.9% of moves.

Learning. Offline, the brain learned from a perfect Connect Four player, 80,000 lessons in three stages, each on a batch of positions from that player's games: the best move, and the verdict. On the page it learns only from you, one lesson at a time.

Where it runs. In your browser tab: Python and NumPy in Pyodide, the released cadence-net library and the trained brain, all checked against their hashes before anything runs. No server chooses the moves.

The numbers

ReadingValue
Brain + search against the perfect player, brain first (won, drawn, lost)363 · 25 · 12 of 400
Brain + search against the perfect player, brain second0 · 0 · 40 of 40
Brain alone against the perfect player, brain first119 · 50 · 31 of 200
Brain alone against the perfect player, brain second0 · 0 · 40 of 40
Moves where the search changed the brain's column (brain + search, first, 400 games)327 of 8,381 (3.9%)
Brain alone: the perfect player's own move, on 3,000 positions it never saw77.3%
Brain alone: a move that keeps the game's result, in positions it can win or draw92.3%
Brain alone: an immediate win taken · a forced block made68.0% · 85.3%
The verdict agrees with the perfect player's result89.2%
The brain3,208 neurons · 3,295,232 synapses
One move in the browser (Apple M4, a busy machine): the settle · the search1.2 to 3.0 s · 0.30 to 0.53 s
One lesson on the empty board: synapses changed2,124,800

The games: evidence/search_reading.json (brain + search, and the brain alone moving second), evidence/reading.json (the brain alone moving first, and the readings on positions it never saw). The browser timings and the lesson: evidence/page_check.json. The perfect player is Pascal Pons' Connect Four solver, which knows the result of every position. The page's promise, played on the page itself: evidence/promise_test-20261113.json. All in the connect-four/ folder of the repository.

Limits

Keys

1 to 7Drop a stone in that column, or, while teaching, teach that column.