Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Run()
- GameObjects = {}
- CIRCLE = 1
- RECTANGLE = 2
- io.stdout:setvbuf"no"
- local ObjectsThatDidntMakeIt,
- OriginalLengthOfPotentialObjects,
- FinalLengthOfPotentialObjectsIgnoringNils,
- TotalFailedAssigns;
- local t = os.clock()
- math.randomseed(os.time())
- do
- local rand = math.random
- local UX, UY;
- local i = 1;
- local potential_objects = {}
- for x=256,1,-1 do
- for y=256,1,-1 do
- potential_objects[i] = {x, y, CIRCLE, 10}
- -- x, y, shape, radius
- i = i + 1;
- end
- end
- local len = #potential_objects
- local finallen = len
- local failedAssignments = 0
- for i = 1, 50000 do
- ::redo::
- local ind = rand(len)
- if not potential_objects[ind] then
- failedAssignments = failedAssignments + 1
- goto redo
- end
- GameObjects[i] = potential_objects[ind]
- potential_objects[ind] = nil;
- finallen = finallen - 1
- end
- ObjectsThatDidntMakeIt = potential_objects
- OriginalLengthOfPotentialObjects = len
- FinalLengthOfPotentialObjectsIgnoringNils = finallen
- TotalFailedAssigns = failedAssignments
- end
- print( "Creating " ..
- #GameObjects ..
- " GameObjects. Time Elapsed: " ..
- (os.clock() - t) ..
- " seconds")
- print("Potential Objects started: ".. OriginalLengthOfPotentialObjects)
- print( "Potential Objects remaining: " .. FinalLengthOfPotentialObjectsIgnoringNils)
- print ("Total Failed Assignments from Potential Objects to Game Objects: ".. TotalFailedAssigns)
- end
- function love.keypressed(key)
- if key=="r" then
- Run()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement