Hello the idea could be
Make an array of empty cell n * m
It is possible to add a shape like =>1 cell or 2 cells in column,
When you add this shape on free place suppress the possibility to add shape on adjacent cells … redo that until it is OK
I made something like this here
It was not too difficult to modify the script, without a lot of test.