Stones, liberties and capture
P72.go-board.01 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Lists — a row of things, Doing something to every item — a loop
Where next?
Go up a level
P72.go-board.01 · Audience: Guest, IT/ML learner, Language professional · Prerequisites: Lists — a row of things, Doing something to every item — a loop
Go up a level
Go is played with nothing but a grid of lines and two bowls of stones, black and white. The players take turns to put one stone on the board, Black first, and a stone never moves once it is down. There are no different pieces and no moves to learn by heart, and yet computers beat the best go players nearly twenty years after they beat the best at chess. Almost everything in it rests on one idea: a stone stays on the board only while it can breathe. This lesson teaches that idea, the liberty, and the capture that follows when a stone has none.
A full go board has 19 lines each way; beginners, and this platform's lessons, use a smaller one of 9 lines each way. The stones are played on the intersections, the points where two lines cross, not inside the squares: a 9 × 9 board has 81 points. The dots on some points are only landmarks.
The points next to a stone, along the lines, are its neighbours: up, down, left and right, never on the diagonals. A neighbouring point that is empty is a liberty of the stone.
Stones of the same colour on neighbouring points are connected, and connected stones form a group. A group shares its liberties: every empty point next to any of its stones is a liberty of the whole group, counted once, even when two of its stones touch it.
Two black stones side by side in the middle have six liberties, not eight: each stone has lost the point the other one stands on. Two stones that meet only at a corner, diagonally, are not connected: they are two groups, with four liberties each.
A stone or group whose last liberty is filled by the other player is captured: all its stones are taken off the board at once and kept by the player who captured them. A group with only one liberty left is in atari: one more stone on that point captures it, unless its owner gives it more liberties first: by playing on that last point, when the stone added there brings new empty neighbours with it, or by capturing one of the stones around the group. On the diagram below, playing in the corner would not save the two edge stones: the longer group would still have a single liberty, the point above the corner.
Liberties count empty points only. A neighbour occupied by any stone, of either colour, is not a liberty, so the two black stones on the lower edge have one liberty left: the corner.
One more rule follows from capture. You may not play a stone where it, or the group it joins, would have no liberties at all, unless that stone captures first: the capture is resolved first, and the points it empties become liberties. One recapture is restricted: when a single stone has just captured a single stone, the other player may not take it straight back, or the two players could repeat the same pair of captures for ever. That position is called ko, and has a rule of its own, in a later lesson.
On a small group you count liberties by eye. On a long, winding group you count them the way a program does, with a flood fill: start from one stone, visit its neighbours, add every neighbour of the same colour that you have not seen yet to the stones still to visit, write down every empty neighbour as a liberty, and stop when there is nothing left to visit. Each liberty is written down once, however many stones touch it. The paint bucket of a drawing program fills a region of one colour with the same steps.
Why it matters — Counting a group's liberties is the first thing any go program does, and the same search fills a region in an image editor.
What this lesson leaves for the next ones: ko, counting territory to see who won, and the coordinates a go diagram uses to name its points.
Both rungs work on a board written as a list of strings, one per row, with
"B" for a black stone, "W" for a white one and "." for an empty point.
The first fills in the one list a short program needs to count a lone stone's
liberties: which points are its neighbours. The second, written from scratch,
counts a whole group's, with a flood fill. Then a short gapped set checks the reading.
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
Off by default. The mentor always gets your file; this only decides whether your own copy stays here. Copies live in this browser only - they do not follow you to another device, and clearing site data removes them.
Loading exercise…
Loading exercise…
Loading the exercise...
Loading your notes...