Is there an easy way of finding the neighbours (that is, the eight elements around an element) of an element in a two-dimensional array? Short of just subtracting and adding to the index in different combinations, like this:
array[i-1][i] array[i-1][i-1] array[i][i-1] array[i+1][i]
… And so on.
(pseudo-code)
Of course, that takes almost as many lines as the original hard-coded solution, but with this one you can extend the ‘neighborhood’ as much as you can (2-3 or more cells away)