Thanks
Quote: "I guess your solution is a "greedy" one"
Not entirely sure what would be described as "greedy". It's pretty brute force.
I was very surprised when I discovered that using
array insert at top was quite a bit faster than
array insert at bottom. I would have assumed DBPro's array's internally used a vector or similar and adding on the end would be faster than shuffling down and adding at the start. I've been using
array insert at bottom for years
I was doing some tests earlier, and it turns out that adding the elements to the array is by far the slowest part, so I'll see if I can come up with a more elegant solution over just adding one when necessary.
Weirdly, I just tried it again and it was completing in just 16ms!!

I must have had more background stuff running last time than I thought!
Lastly, I think there's still some bugs in it. I studied the resulting combinings of a few random generations and I'm pretty sure it's ignoring my wishes occasionally and favouring Y-combining over X-combining... bit strange.
Latest code with a couple of fixes:
sync on
sync rate 0
autocam off
hide mouse
set display mode desktop width(),desktop height(),32,1
sync
global debug=1
type pointinfo
exists as boolean
object as integer
endtype
type boxinfo
object as integer
startx as integer
starty as integer
endx as integer
endy as integer
endtype
dim points(64,64) as pointinfo
dim boxes(0) as boxinfo
move camera -55
move camera up 30
move camera right 30
position light 0,camera position x(),camera position y(),camera position z()
precount=0
for y=0 to 63
for x=0 to 63
if rnd(2)=1
points(x,y).exists=1
points(x,y).object=findfreeobject()
make object cube points(x,y).object,1
position object points(x,y).object,x,y,0
precount=precount+1
endif
next x
next y
for y=0 to 63
for x=0 to 63
if points(x,y).exists=1 then color object points(x,y).object,rgb(rnd(255),rnd(255),rnd(255))
next x
next y
sync
sync
wait key
for y=0 to 63
for x=0 to 63
if points(x,y).exists=1 then delete object points(x,y).object
next x
next y
oldtime=hitimer()
for y=0 to 63
for x=0 to 63
if points(x,y).exists=1
if pointinsidebox(x,y)=-1
array insert at top boxes()
startx=x
starty=y
endx=x
endy=y
sizex=0
sizey=0
checkx=x+1
checky=y+1
continuex=1
continuey=1
do
if continuex=1
found=1
for i=0 to sizey
if points(checkx,y+i).exists=0 then found=0
next i
if found=1
if x+sizex<63 //and checkx<65
sizex=sizex+1
checkx=checkx+1
endx=endx+1
else
continuex=0
endif
else
continuex=0
endif
endif
if continuey=1
found=1
for i=0 to sizex
if points(x+i,checky).exists=0 then found=0
next i
if found=1
if y+sizey<63 //and checky<65
sizey=sizey+1
checky=checky+1
endy=endy+1
else
continuey=0
endif
else
continuey=0
endif
endif
if continuex=0 and continuey=0 then exit
loop
boxes().startx=startx
boxes().starty=starty
boxes().endx=endx
boxes().endy=endy
if endx<63
x=endx+1
else
x=0
endif
endif
endif
next x
next y
time=hitimer()-oldtime
for i=0 to array count(boxes())
boxes(i).object=findfreeobject()
make object box boxes(i).object,boxes(i).endx-boxes(i).startx+1,boxes(i).endy-boxes(i).starty+1,1
position object boxes(i).object,boxes(i).startx+((boxes(i).endx-boxes(i).startx+1)/2.0)-0.5,boxes(i).starty+((boxes(i).endy-boxes(i).starty+1)/2.0)-0.5,0
next i
for i=0 to array count(boxes())
color object boxes(i).object,rgb(rnd(255),rnd(255),rnd(255))
next i
postcount=array count(boxes())
do
if debug=1
set cursor 0,0
print "--Debug Information--"
print "Graphics card: ";current graphics card$()
print "Frames per second: ";screen fps()
print "Polygons rendered: ";statistic(1)
print "Camera position, x: ";camera position x();" y: ";camera position y();" z: ";camera position z()
print "Camera angle, x: ";camera angle x();" y: ";camera angle y();" z: ";camera angle z()
print "--Variables--"
print "precount: ";precount
print "postcount: ";postcount
print "time: ";time
endif
sync
loop
function pointinsidebox(x,y)
for i=0 to array count(boxes())
if x>=boxes(i).startx and y>=boxes(i).starty and x<=boxes(i).endx and y<=boxes(i).endy then exitfunction i
next i
endfunction -1
function findfreeobject()
object=1
do
if object exist(object)=0 then exitfunction object
object=object+1
loop
endfunction 0