Score a terminal Go board using Tromp-Taylor area scoring. The board uses 0 for empty, 1 for Black, and -1 for White. A game is terminal after at least two consecutive passes or at least twice the board area in played actions.
SB=∣B∣+R:boundary(R)={1}∑∣R∣ SW=∣W∣+R:boundary(R)={−1}∑∣R∣+kHere, B and W are the sets of Black and White stones, R is a horizontally or vertically connected empty region, and vertical bars denote the number of intersections. The boundary of R is the set of adjacent stone colours, k is komi, and the two equations give Black's and White's scores. Regions touching both colours or neither colour are neutral.
Return a four-item tuple containing the terminal flag, Black score, White score, and winner. Scores are 64-bit floating-point values; winner is 1 for Black, -1 for White, or 0 for a tie. For an unfinished game, return (False, None, None, None).
Input: board = [[1,1,1],[1,0,1],[1,1,1]], komi = 0.5, consecutive_passes = 2, move_count = 12
Output: (True, 9.0, 0.5, 1)
Explanation: Black owns eight stones and the enclosed center, while White receives only komi.
Input: board = [[1,0],[0,-1]], komi = 0.5, consecutive_passes = 1, move_count = 3
Output: (False, None, None, None)
Input: board = [[1,0,-1],[1,0,-1],[1,0,-1]], komi = 0, consecutive_passes = 2, move_count = 10
Output: (True, 3.0, 3.0, 0)
np.count_nonzero can count stones of one colour.
Use a set to collect the stone colours bordering an empty region.
A boundary set with one colour identifies owned territory.
Accepts: array
Accepts: number
Accepts: number
Accepts: number
Score a terminal Go board using Tromp-Taylor area scoring. The board uses 0 for empty, 1 for Black, and -1 for White. A game is terminal after at least two consecutive passes or at least twice the board area in played actions.
SB=∣B∣+R:boundary(R)={1}∑∣R∣ SW=∣W∣+R:boundary(R)={−1}∑∣R∣+kHere, B and W are the sets of Black and White stones, R is a horizontally or vertically connected empty region, and vertical bars denote the number of intersections. The boundary of R is the set of adjacent stone colours, k is komi, and the two equations give Black's and White's scores. Regions touching both colours or neither colour are neutral.
Return a four-item tuple containing the terminal flag, Black score, White score, and winner. Scores are 64-bit floating-point values; winner is 1 for Black, -1 for White, or 0 for a tie. For an unfinished game, return (False, None, None, None).
Input: board = [[1,1,1],[1,0,1],[1,1,1]], komi = 0.5, consecutive_passes = 2, move_count = 12
Output: (True, 9.0, 0.5, 1)
Explanation: Black owns eight stones and the enclosed center, while White receives only komi.
Input: board = [[1,0],[0,-1]], komi = 0.5, consecutive_passes = 1, move_count = 3
Output: (False, None, None, None)
Input: board = [[1,0,-1],[1,0,-1],[1,0,-1]], komi = 0, consecutive_passes = 2, move_count = 10
Output: (True, 3.0, 3.0, 0)
np.count_nonzero can count stones of one colour.
Use a set to collect the stone colours bordering an empty region.
A boundary set with one colour identifies owned territory.
Accepts: array
Accepts: number
Accepts: number
Accepts: number