Find the same-colour stones connected to the occupied starting point through horizontal or vertical neighbours. A liberty is an empty intersection adjacent to any stone in that group; shared liberties count once. The board uses 0 for empty, 1 for Black, and -1 for White.
Return a two-item tuple containing the group coordinate list and the liberty coordinate list. Each coordinate is an integer row-column pair; lists or tuples are accepted for individual pairs. Sort both lists by row, then column.
Input: board = [[1,1,0],[0,1,0],[-1,0,0]], row = 0, col = 0
Output: ([[0,0],[0,1],[1,1]], [[0,2],[1,0],[1,2],[2,1]])
Explanation: The three connected Black stones share four distinct liberties.
Input: board = [[-1,0],[0,0]], row = 0, col = 0
Output: ([[0,0]], [[0,1],[1,0]])
Input: board = [[-1,1,-1],[1,1,1],[-1,1,-1]], row = 1, col = 1
Output: ([[0,1],[1,0],[1,1],[1,2],[2,1]], [])
A set of row-column tuples prevents duplicate coordinates.
Use a stack with pop() to visit connected stones.
sorted() orders coordinate tuples by row, then column.
Accepts: array
Accepts: number
Accepts: number
Find the same-colour stones connected to the occupied starting point through horizontal or vertical neighbours. A liberty is an empty intersection adjacent to any stone in that group; shared liberties count once. The board uses 0 for empty, 1 for Black, and -1 for White.
Return a two-item tuple containing the group coordinate list and the liberty coordinate list. Each coordinate is an integer row-column pair; lists or tuples are accepted for individual pairs. Sort both lists by row, then column.
Input: board = [[1,1,0],[0,1,0],[-1,0,0]], row = 0, col = 0
Output: ([[0,0],[0,1],[1,1]], [[0,2],[1,0],[1,2],[2,1]])
Explanation: The three connected Black stones share four distinct liberties.
Input: board = [[-1,0],[0,0]], row = 0, col = 0
Output: ([[0,0]], [[0,1],[1,0]])
Input: board = [[-1,1,-1],[1,1,1],[-1,1,-1]], row = 1, col = 1
Output: ([[0,1],[1,0],[1,1],[1,2],[2,1]], [])
A set of row-column tuples prevents duplicate coordinates.
Use a stack with pop() to visit connected stones.
sorted() orders coordinate tuples by row, then column.
Accepts: array
Accepts: number
Accepts: number