'A private helper function to update self.group_sets and self.liberty_sets
given that a stone was just played at `position`'

def _update_neighbors(self, position):

    (x, y) = position
    merged_group = set()
    merged_group.add(position)
    merged_libs = self.liberty_sets[x][y]
    for (nx, ny) in self._neighbors(position):
        self.liberty_sets[nx][ny] -= set([position])
        if (self.board[nx][ny] == (- self.current_player)):
            new_liberty_count = len(self.liberty_sets[nx][ny])
            for (gx, gy) in self.group_sets[nx][ny]:
                self.liberty_counts[gx][gy] = new_liberty_count
        elif (self.board[x][y] == self.board[nx][ny]):
            merged_group |= self.group_sets[nx][ny]
            merged_libs |= self.liberty_sets[nx][ny]
    count_merged_libs = len(merged_libs)
    for (gx, gy) in merged_group:
        self.group_sets[gx][gy] = merged_group
        self.liberty_sets[gx][gy] = merged_libs
        self.liberty_counts[gx][gy] = count_merged_libs
