Hey all, for a few of my college assignments I\'ve found the need to check neighbouring cells in 2-dimensional arrays (grids). The solution I\'ve used is a bit of a hack usi
why can't you check row+rowMod and col+colMod for validity before array access?
something like:
r=row+rowMod;
c=col+colMod;
if (r < 0 || c < 0 || r >= grid.length || c >= grid.length) continue;
alternatively (no continue):
if (r >= 0 && c >= 0 && r < grid.length && c < grid.length &&
someVar == grid[r][c]) { /* do something */ }