For a two-dimensional array of any size:
var board = [ [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0], [0,0,0,0,0,0,0,0] ];
... and the given [y] [x] point in this array, such as:
board[3][4]
... and a given number of spaces that it can move (up / down / left / right, rather than diagonally), for example:
var distance = 3;
... how would a loop function through a 2D array and create a list of only those coordinates that can be moved?
(Here's a good example of a given coordinate (*) in an array and the surrounding moving coordinates.)
0 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 3 2 3 0 0 0 0 3 2 1 2 3 0 0 3 2 1 * 1 2 3 0 0 3 2 1 2 3 0 0 0 0 3 2 3 0 0 0 0 0 0 3 0 0 0 0
Link: JS: how to algorithmically select a diamond choice of x / y coordinates? (I asked this question before, but I can't figure out how to enter a coordinate and get a list of coordinates)