Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("clear")
- print("Enter maze size")
- write("X:");x=math.floor(tonumber(read())/2)
- write("Y:");y=math.floor(tonumber(read())/2)
- print("Horozontal Influence (NYI)")
- print("Vertical Influence (NYI)")
- read()
- shell.run("clear")
- visited={}
- nodes={}
- for i=1,y*2-1 do
- if i%2==1 then
- nodes[i]=string.rep("- ",x):sub(1,x*2-1)
- else
- nodes[i]=string.rep(" ",x*2-1)
- end
- end
- term.setBackgroundColor(colors.white)
- for i=1,x do
- visited[i]={}
- for j=1,y do
- visited[i][j]=false
- term.setCursorPos(i*2-1,j*2-1)
- write(" ")
- end
- end
- visited[1][1]=true
- function done()
- for i=1,x do
- for j=1,y do
- if visited[i][j]==false then return false end
- end
- end
- return true
- end
- function fn(sx,sy)
- u,r,d,l=false,false,false,false
- if sy>1 then if not visited[sx][sy-1] then u=true end end
- if sy<y then if not visited[sx][sy+1] then d=true end end
- if sx>1 then if not visited[sx-1][sy] then l=true end end
- if sx<x then if not visited[sx+1][sy] then r=true end end
- return {u,r,d,l}
- end
- function nt(tbl)
- local num=0
- for i=1,#tbl do
- if tbl[i] then num=num+1 end
- end
- return num
- end
- function npos(xps,yps)
- nodes[yps]=nodes[yps]:sub(1,xps-1).."-"..nodes[yps]:sub(xps+1,x*2-1)
- end
- while not done() do
- lst=nil
- lst={}
- for i=1,x do
- for j=1,y do
- if visited[i][j] and nt(fn(i,j))>0 then table.insert(lst,{i,j}) end
- end
- end
- rnd=#lst
- rnd=math.random(1,rnd)
- nbr=fn(lst[rnd][1],lst[rnd][2])
- nls=nil
- nls={}
- for i=1,4 do
- if nbr[i] then table.insert(nls,i) end
- end
- dir=nls[math.random(1,#nls)]
- if dir==1 then --Up
- visited[lst[rnd][1]][lst[rnd][2]-1]=true
- npos(lst[rnd][1]*2-1,lst[rnd][2]*2-2)
- term.setCursorPos(lst[rnd][1]*2-1,lst[rnd][2]*2-2)
- elseif dir==2 then --Right
- visited[lst[rnd][1]+1][lst[rnd][2]]=true
- npos(lst[rnd][1]*2,lst[rnd][2]*2-1)
- term.setCursorPos(lst[rnd][1]*2,lst[rnd][2]*2-1)
- elseif dir==3 then --Down
- visited[lst[rnd][1]][lst[rnd][2]+1]=true
- npos(lst[rnd][1]*2-1,lst[rnd][2]*2)
- term.setCursorPos(lst[rnd][1]*2-1,lst[rnd][2]*2)
- elseif dir==4 then --Left
- visited[lst[rnd][1]-1][lst[rnd][2]]=true
- npos(lst[rnd][1]*2-2,lst[rnd][2]*2-1)
- term.setCursorPos(lst[rnd][1]*2-2,lst[rnd][2]*2-1)
- end
- write(" ")
- sleep(0)
- end
- os.pullEvent()
- handle=fs.open("LstMz","w")
- for i=1,y*2-1 do
- handle.writeLine(nodes[i])
- end
- handle.close()
- term.setBackgroundColor(colors.black)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement