Task: it is necessary to implement AI when playing tic-tac-toe on Java. The very first step is a random cell selection and verification of neighboring cells for, say, zeroes. implemented in the forehead:
if (map[i+1][j] == DOT_O || map[i+1][j+1] == DOT_O || map[i+1][j-1] == DOT_O || map[i][j+1] == DOT_O || map[i][j-1] == DOT_O || map[i-1][j] == DOT_O || map[i-1][j+1] == DOT_O || map[i-1][j-1] == DOT_O ) { x = i; y = j; } but there was an error right away, because when accessing a cell of type i + 1, you can go beyond the edge of the array. Now I myself do not understand how to approach the problem. Help, please.