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
- 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.
- Module 0. 1,024 neurons that read the board cells and pass on what they see. Each sits where the cells it reads are.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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
- Play. Click a column (or press 1 to 7) to drop your stone. The brain settles and answers within a few seconds. Four in a row wins.
- Watch it think. While it settles, the motor bars rise and the regions light up as messages spread from the board through the brain and back. The readout at the top right counts the sweeps.
- Read its verdict and the search. After its move, the line above the board says how the brain judged the game, and the next line says what the search did: kept the brain's column, overruled it, or found a forced win.
- Teach it. After a brain move, press Teach it, then click the column it should have played. One lesson changes its synapses (the changed ones flash: gold stronger, blue weaker), and the board settles again. Click the column again to repeat the lesson. Press Done to go back to the game, and Reset brain to undo every lesson.
- Brain alone. Switch off the search and play the brain by itself: one settle, its strongest column.
- Brain starts. Give the brain the first stone, the winning seat.
- Imagine. Tick it, and before its move the brain privately settles on the board each of its columns would leave, from your seat, and shows the reply it would make there. Nothing in it changes, and its move does not use these. It adds a few seconds a move.
- Undo takes back your last move and the brain's reply. New game clears the board; the brain keeps what you taught it.
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
| Reading | Value |
|---|---|
| Brain + search against the perfect player, brain first (won, drawn, lost) | 363 · 25 · 12 of 400 |
| Brain + search against the perfect player, brain second | 0 · 0 · 40 of 40 |
| Brain alone against the perfect player, brain first | 119 · 50 · 31 of 200 |
| Brain alone against the perfect player, brain second | 0 · 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 saw | 77.3% |
| Brain alone: a move that keeps the game's result, in positions it can win or draw | 92.3% |
| Brain alone: an immediate win taken · a forced block made | 68.0% · 85.3% |
| The verdict agrees with the perfect player's result | 89.2% |
| The brain | 3,208 neurons · 3,295,232 synapses |
| One move in the browser (Apple M4, a busy machine): the settle · the search | 1.2 to 3.0 s · 0.30 to 0.53 s |
| One lesson on the empty board: synapses changed | 2,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
- The search is not Cadence. The strongest result, 363 of 400, belongs to the brain and the search together. The brain alone wins 119 of 200 from the same seat.
- Not a perfect player. The brain alone misses about a third of the immediate wins it could take. With the search it takes every win the search can see, and loses some games from the winning seat as well.
- No memory here. Each move settles fresh from the board, which shows everything; this demo does not show Cadence's memory.
- Taught by a perfect player. The brain learned offline from a solver's answers, also on positions from its own games; it did not learn from winning or losing.
- A lesson is one position. Your lesson changes the brain's answer on that board and shifts its synapses a little everywhere; it does not make the brain stronger in general, and it may change its answers on other boards. Lessons stay in the tab: a reload or Reset brain brings back the trained brain.
- A settled state means the brain's equations agree, not that the move is good.
- Brightness is relative within each region, so a quiet region shows its pattern too; the neuron card shows the raw numbers.