The code needs to be broken up into smaller functions that do less. Ideally a function does only a single thing. That way it becomes much easier to test whether what you’ve written actually works the way you intended.
I started with some cleaning, but there’s too much going on at once for me to understand what the code is supposed to do.
I’d recommend not nesting loops deeper than one level. If you find yourself writing a loop inside a loop, try and refactor the inner loop into a separate method. You’re also probably better off creating a custom type for your panel grid which has bounds-checked accessor methods, so you can get rid of all that low level code in the main algorithm.
If you can explain the steps this algorithm is supposed to take I may be able to help you further.
What I want to do is to find some wall pattern with following conditons.
1.Two panels are not arranged side by side continuously
2.three or more panel are not arranged verticaly continuously
3.all panel are connected
Now,in my script
When p[i,j] is 1, a panel is arranged in that cell.
my algorithm is
1, I randomly place a panel
2, Cells that can not be placed are set to 0
3, Find blank cell around the cell had 1(the cell arranged panel)
4, Choose blank cells(in 3) randomly and place a panel
Sorry for bad explanation…
I am glad if you help me.