Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- size=15
- wayLenght=20
- minLenght=20
- trys=0
- avtrys=0
- function newMap(size)
- map={}
- for x=1,size do
- map[x]={}
- for y=1,size do
- map[x][y]=0
- end
- end
- return map
- end
- function goForward(map,dir)
- if x+2<=size and y+2<=size and x+2>0 and y+2>0 and x-2<=size and y-2<=size and x-2>0 and y-2>0 then
- if dir==1 then
- if map[x][y+2]==nil or map[x][y+2]==1 then return false else map[x][y+2]=1 map[x][y+1]=1 y=y+2 end
- end
- if dir==3 then
- if map[x][y-2]==nil or map[x][y-2]==1 then return false else map[x][y-2]=1 map[x][y-1]=1 y=y-2 end
- end
- if dir==2 then
- if map[x+2][y]==nil or map[x+2][y]==1 then return false else map[x+2][y]=1 map[x+1][y]=1 x=x+2 end
- end
- if dir==4 then
- if map[x-2][y]==nil or map[x-2][y]==1 then return false else map[x-2][y]=1 map[x-1][y]=1 x=x-2 end
- end
- else
- return false
- end
- end
- function getPathLenght(map)
- wert=0
- for x=1,size do
- for y=1,size do
- wert=wert+map[x][y]
- end
- end
- return wert
- end
- function writeMap(map,file)
- shell.run("rm "..file)
- fp=fs.open(file,"w")
- size=#map[1]
- for x=1,size do
- for y=1,size do
- fp.write(tostring(map[x][y]))
- end
- fp.write("\n")
- end
- fp.close()
- end
- while true do
- way=newMap(size)
- x=math.random(1,size)
- y=math.random(1,size)
- way[x][y]=1
- for i=1,wayLenght do
- goForward(way,math.random(1,4))
- end
- --writeMap(way,"weg")
- if getPathLenght(way)>=minLenght then
- paintutils.drawImage(way,1,1)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1,1)
- term.write(trys)
- avtrys=(avtrys+trys)/2
- term.setCursorPos(1,2)
- term.write(avtrys)
- sleep(0.5)
- term.clear()
- trys=0
- else trys=trys+1
- end
- end
Add Comment
Please, Sign In to add comment