Background
This challenge is about the Game of Go. Here are some rules and terminology relevant to this challenge:
Game of Go is a two-player game, played over a square board of size 19x19.
One of the players plays Black, and the other plays White. The game is turn-based, and each player makes a single move each turn, starting with Black. In the diagrams below, we use
O
for White andX
for Black. Any other symbol is a blank.A move consists of placing a new stone of the player's own color on an empty spot on the board.
Given a group of orthogonally connected stones of single color, the liberty is the number of empty positions orthogonally around it. For example, the following group has liberty of 7:
. . . . . O O . . O . . . . . .
and the following configuration has two groups having liberties of 6 and 4 respectively:
. . . . . . O O . . . . . O . . . . . .
The opponent can reduce the liberty by placing their own stones around the target group. The following group of
O
has liberty 1 (the only empty adjacent position beinga
):. X X . X O O X X O X . . a . .
If the Black places another black stone at
a
, the white group's liberty reduces to 0, where capture happens, and the white group is removed from the board.A player cannot make a move where their own stone(s) would be captured, unless it is itself a capturing move. For example, the Black cannot make a move at
a
orb
(where one or two black stones would be captured immediately), but they can make a move atc
because it captures two White stones on its right.. . . . . O . . . O X . . O . . O X O . O X O X O a O . O b O . O c O X . O . . . O . . . O X .
Finally, some terminology that is exclusive to this challenge:
- A configuration is one or more groups of stones of the same color.
- A configuration of White (color fixed for ease of explanation) is fully alive if Black cannot capture any of the given white stones even if arbitrarily many turns are given to Black.
Challenge
Given a Game of Go configuration, test if it is fully alive.
The input is a rectangular 2D array representing the state of the board, where each cell is either occupied (O
in the example below) or empty (.
).
You can choose any two distinct values to represent an occupied and an empty cell respectively.
You can assume the input is always rectangular, and contains at least one stone.
You can assume the input will always contain a margin of empty cells around the entire configuration of stones. For example, you don't need to handle this:
O O O . O . O O . O . O . . O O
which will be given as the following instead:
. . . . . . . O O O . . . O . O O . . . O . O . . . . O O . . . . . . .
You may assume that the entire input (including the margin) will not exceed 19 rows and 19 columns.
For output, you can choose to
- output truthy/falsy using your language's convention (swapping is allowed), or
- use two distinct values to represent true (affirmative) or false (negative) respectively.
Standard code-golf rules apply. The shortest code wins.
Test cases
Truthy (fully alive)
. . . . . . .
. . O O O O .
. O . O . O .
. O O O O . .
. . . . . . .
. . . . . .
. O O . . .
. O . O O .
. O O . O .
. . . O O .
. . . . . .
. . . . . .
. . O O . .
. O . O O .
. O O . O .
. . O O . .
. . . . . .
. . . . . .
. O O . . .
. O . O . .
. O O . O .
. . O O O .
. . . . . .
Truthy since both eyes must be filled in order to capture any of the two groups
. . . . . . .
. . O O O . .
. O . . O O .
. O O O . O .
. . . O O . .
. . . . . . .
Ditto
. . . . . . . .
. . O O O . . .
. O . . O O O .
. O O O . . O .
. . . O O O . .
. . . . . . . .
. . . . . . .
. . O O O . .
. . O . . O .
. O . O O O .
. O O . O . .
. . . O O . .
. . . . . . .
. . . . . . .
. . . O O O .
. . . O . O .
. O O . O O .
. O . O . . .
. O O O . . .
. . . . . . .
. . . . . . . . .
. . O O O O O O .
. O . . O . . O .
. O . . O . . O .
. O O O O O O . .
. . . . . . . . .
Falsy (not fully alive)
. . .
. O .
. . .
. . . . .
. O O O .
. O . O .
. O O . .
. . . . .
. . . . . . . . .
. O O O . . O O .
. O . O . O . O .
. O O . . O O O .
. . . . . . . . .
. . . . . . .
. O O . O O .
. O . O . O .
. O O . O O .
. . . . . . .
The right group can be captured by Black, since Black doesn't need to fill
the upper area (of size 2) to capture it
. . . . . . .
. O O O . . .
. O . . O O .
. O O O . O .
. . . . O O .
. . . . . . .
The center singleton can be captured by Black
. . . . . . . . .
. . . O O O . . .
. O O O . O O O .
. O . . O . . O .
. O O O . O O O .
. . . O . O . . .
. . . O O O . . .
. . . . . . . . .
. . . . . . . . .
. . O O O O O O .
. O . . . O . O .
. O . . . O . O .
. O . . . O . O .
. O O O O O O . .
. . . . . . . . .
One part is fully alive but the other is not
. . . . . . . . . .
. O O O . . . O O .
. O . O O . O . O .
. . O . O . O O . .
. . O O . . . . . .
. . . . . . . . . .
OOO\\O.O\\OOO
can be captured too. \$\endgroup\$.XXXXXXXX/XXOOOOOOX/XOXXXOXOX/XOX.XOXOX/XOXXXOaOX/XOOOOOOXX/XXXXXXXX.
\$\endgroup\$