R, 117 63 6359 bytes
@Giuseppe with most of the bytes saved:
function(m)sum(colSums(as.matrix(dist(which(m==8,T)))<=2^.5<2)<2)
dist
computes distances (default is Euclidean) among rows of a matrix. which
with second argument TRUE
returns the coordinates where the predicate is true.
Coordinates are neighbours if the distance between them is not more than the square root of 2, but the inner <2
is good enough because the possible distance jumps from sqrt(2)
ro 2
.
Original:
function(m,p=which(m==8,T))sum(sapply(split(p,1:nrow(p)),function(y)sum(apply(p,1,function(x)all((c(y-x)^2<2)))))==1)