private int findDirectionOfSquare(int x, int y, int[][] path) { // grid system
		int sq2 = path[x][y] + 1;
		try {
			if (y > 0) if (sq2 == path[x][y - 1]) return NORTH;
			if (x < getColumns() - 1) if (sq2 == path[x + 1][y]) return EAST;
			if (y < getRows() - 1) if (sq2 == path[x][y + 1]) return SOUTH;
			if (x > 0) if (sq2 == path[x - 1][y]) return WEST;
		} catch (ArrayIndexOutOfBoundsException e) {
			e.printStackTrace();
		}
		return -1;
	}