Ejemplo n.º 1
0
 def connected_component_dia(self, point):
     marker = np.full(self.maxpoint, False, dtype=bool)
     pointstack = [point]
     color = self.get_color(point)
     assert is_black_white_empty(color)
     marker[point] = True
     while pointstack:
         p = pointstack.pop()
         neighbors = self.neighbors_of_color_dia(p, color)
         for nb in neighbors:
             if not marker[nb]:
                 marker[nb] = True
                 pointstack.append(nb)
     return marker
    def _block_of(self, stone):
        """
        Find the block of given stone
        Returns a board of boolean markers which are set for
        all the points in the block 
        """

        color = self.get_color(stone)
        assert is_black_white(color)

        #<--connected_component--->
        marker = np.full(self.maxpoint, False, dtype=bool)
        pointstack = [stone]
        assert is_black_white_empty(color)
        marker[stone] = True
        while pointstack:
            p = pointstack.pop()
            neighbors = self.neighbors_of_color(p, color)
            for nb in neighbors:
                if not marker[nb]:
                    marker[nb] = True
                    pointstack.append(nb)
        return marker