Currently I’m trying to make a random maze generator; I got the maze generation working, now I’m confuse of how I would be able to draw the maze:
local function Find(table : {}, other : any)
for _, value in next, table do
if ((value[1] == other[1]) and (value[2] == other[2])) then
return true
end
end
end
return function(self : {}, start : {}, speed : number)
local currentSquare = start or {1, 1}
local mazeSquaresData = self:PrecomputedSquareData()
local maxIndex = (self:GetSizeX() * self:GetSizeY())
local visited = {currentSquare}
local stack = {}
local start = tick()
while (#visited < maxIndex) do
local selected = mazeSquaresData[currentSquare[1]][currentSquare[2]]
local targetSquare = selected[math.random(1, #selected)]
if (Find(visited, targetSquare)) then
local available = false
for _, value in next, selected do
if (not (Find(visited, value))) then
targetSquare = value
available = true break
end
end
if (not available) then
currentSquare = table.remove(stack, #stack)[2] continue
end
end
table.insert(stack, {currentSquare, targetSquare})
table.insert(visited, targetSquare)
task.wait(speed)
end
local completedIn = (tick() - start)
print(("Time: %ims or %is"):format(math.floor(completedIn * 1000), math.floor(completedIn)))
end
I feel like you should try random stuff with this one. Try applying vector2 values into vector3 etc etc.
You may find answer with almost no logical thinking.
After I woke up I got an idea of just generating 2 parts which is the north wall and the east wall, there’s is a slight problem I’m having trouble calculating the position so it’s centered:
I got the maze working it was pretty simple, but still have not found the solution to set it the position so its centered:
Not much coding was actually done, still I plan on making it on a different algorithm, currently this is the Recursive implementation also know as the recursive backtracker; I think I’ll go with the hunt and kill algorithm next.