cells = {
let cells = [[1, 1, 10, 10]];
while (true) {
let choice = cells
.filter(c => (c[2] - c[0]) + (c[3] - c[1]) > 2)
.sort(() => Math.random() - 0.5)[0];
if (!choice) return cells;
let cellSize = [choice[2] - choice[0], choice[3] - choice[1]];
let splitAxis = cellSize[0] == 1 ? 1 :
cellSize[1] == 1 ? 0 :
Math.round(Math.random());
let replacementCells;
if (splitAxis === 0) {
let splitPoint = Math.floor(Math.random() * (cellSize[0] - 2)) + choice[0] + 1;
replacementCells = [
[choice[0], choice[1], splitPoint, choice[3]],
[splitPoint, choice[1], choice[2], choice[3]]
];
} else {
let splitPoint = Math.floor(Math.random() * (cellSize[1] - 2)) + choice[1] + 1;
replacementCells = [
[choice[0], choice[1], choice[2], splitPoint],
[choice[0], splitPoint, choice[2], choice[3]]
];
}
cells.splice(cells.indexOf(choice), 1, replacementCells[0], replacementCells[1]);
yield Promises.delay(100, cells);
if (cells.length === 20) return;
}
}