private boolean isConnectedToCapital(int x, int y, Player player, boolean[][] searched, boolean isInitial) {
        if (x < 0 || x >= width || y < 0 || y >= height) {
            return false;
        }
        if (searched[x][y]) {
            return false;
        }
        searched[x][y] = true;

        Building b = buildings[x][y];
        if (b == null || !b.owner.equals(player) || b.isRubble) {
            if (!isInitial) {
                return false;
            }
        } else {
            if (b.isCapital) {
                return true;
            }
        }
        return isConnectedToCapital(x - 1, y, player, searched, false)
                || isConnectedToCapital(x + 1, y, player, searched, false)
                || isConnectedToCapital(x, y - 1, player, searched, false)
                || isConnectedToCapital(x, y + 1, player, searched, false);
    }