Consider my solution using movement constant:
int [] movx ={-1, -1, -1, 0, 0, 1, 1, 1};
int [] movy ={-1, 0, 1, -1, 1, -1, 0, 1};
This are the offset you move from (x,y)
. So your method will be
public void zeros(int[][] m, int[][] v, int x, int y) {
//Already visited?
if (v[x][y] == 1) return;
//Mark as visited
v[x][y] = 1;
for (int i = 0; i < 8; i++){
//neighbors coordinates
int nx = x + movx[i];
int ny = y + movy[i];
//check boundaries
if (nx >= 0 && nx < m.length && ny >= 0 && ny < m[x].length){
//if there is no mine check it
if (m[nx][ny] == 0)
zeros(m, v, nx, ny);
}
}
}
for example if you have (x=2,y=2)
your neighbors will be:
(x=1,y=1)
(x=1,y=2)
(x=1,y=3)
(x=2,y=1)
(x=2,y=2)
(x=2,y=3)
(x=3,y=1)
(x=3,y=2)
(x=3,y=3)