@Override
    public void generate() {
        BSP root = new BSP(0, 0, width, height);
        List<BSP> bus = new ArrayList<>();
        List<BSP> fin = new ArrayList<>();
        List<BSP> con = new ArrayList<>();
        bus.add(root);
        while (!bus.isEmpty()) {
            BSP cur = bus.remove(0);
            if (cur.split()) {
                bus.add(cur.first());
                bus.add(cur.second());
            } else {
                fin.add(cur);
            }
            if (cur.whatSplit() != BSP.NOSPLIT) {
                con.add(cur);
            }
        }

        for (BSP b : fin) {
            room(b.rectangle());
        }

        while (!con.isEmpty()) {
            path(con.remove(con.size() - 1));
        }
        /*for (BSP b : con) {
         if (b.whatSplit() == BSP.HSPLIT) {
         int sx = b.x() + b.width() / 2;
         int sy = b.y() + 1;
         for (int i = sy; i < sy + b.height() - 1; i++) {
         if (data[i][sx] != null) {
         if (data[i][sx] instanceof Wall) {
         data[i][sx] = new Door(sx, i, true);
         break;
         }
         } else {
         data[i][sx] = new Floor(sx, i);
         }
         }
         } else {
         int sx = b.x() + 1;
         int sy = b.y() + b.height() / 2;
         for (int i = sx; i < sx + b.width() - 1; i++) {
         if (data[sy][i] != null) {
         if (data[sy][i] instanceof Wall) {
         data[sy][i] = new Door(i, sy, false);
         break;
         }
         } else {
         data[sy][i] = new Floor(i, sy);
         }
         }
         }
         }*/
        while (true) {
            int x = new Random().nextInt(width);
            int y = new Random().nextInt(height);
            if (data[y][x] != null) {
                if (data[y][x].set(player)) {
                    break;
                }
            }
        }
    }