The simplest solution is to keep a "Border" round the four sides of your map.
So if you need a 3x3 map, you declare it as 5x5:
bbbbb
b...b
b...b
b...b
bbbbb
The dots are the
n x n
"play area" and the b's are the border.
Then for play you use indexes 1 to n inclusive.
Set the whole border to empty, and you can use the "play location" plus or minus one without checking the indexes for correctness.