Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Short thanks to scipy.ndimage.label solution in 3rd party category for Boundary Blocks by Phil15
from scipy.ndimage import label
import numpy as np
neighbors = lambda M, i, j: map(int, M[max(0, i-1):i+2, max(0, j-1):j+2].flat)
def boundary_blocks(grid):
grid, nb_zones = label(np.array([[x != 'X' for x in row] for row in grid]))
if nb_zones > 1: # otherwise, no boundary block.
for i, row in enumerate(grid):
for j, nb_zone in enumerate(row):
if not nb_zone and len(set(neighbors(grid, i, j))) > 2:
yield i, j
May 16, 2019
Comments: