public double energy(int x, int y) {
        if (x < 0 || x >= width || y < 0 || y >= height) {
            throw new IndexOutOfBoundsException(
                    "x = " + x + ", width = " + width + ";y = " + y
                    + ", height = " + height);
        }
        if (x == 0 || y == 0 || x == width - 1 || y == height - 1) {
            return BORDER_ENERGY;
        } else {
            return energyx(x, y) + energyy(x, y);
        }
    }