Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bit32 = require("bit32")
- -- going clockwise direction is 1 for 12 oclock 2 for 3, 3 for 6 and 4 for 9
- local direction = 1
- term.clear()
- term.setCursorPos(0, 0)
- print("Welcome to HilbertTurtle the turtle mining program which uses a sudo HilbertCurve")
- print("Please input an order for the hilbert curve:")
- local order = io.read()
- print("Please input a thickness between tunnels:")
- local thick = io.read()
- local N = 2^order
- local total = N*N
- local volume = total*(thick*2)
- local pathX = {}
- local pathY = {}
- print("Thank you, Estimate blocks mined is: " .. volume)
- local function digforward(num)
- local k = num
- for i = 1, k, 1 do
- while turtle.detect() == true do
- turtle.dig()
- end
- turtle.forward()
- turtle.digDown()
- end
- end
- local function turnTo(targetDir)
- local tDir = targetDir
- while direction ~= tDir do
- turtle.turnRight()
- direction = direction + 1
- if direction > 4 then
- direction = 1
- end
- end
- end
- local function goTo(x,y,u,v)
- local xx = x
- local yy = y
- local uu = u
- local vv = v
- local targetDir
- if uu > xx then
- targetDir = 2
- elseif uu < xx then
- targetDir = 4
- elseif vv > yy then
- targetDir = 1
- elseif vv < yy then
- targetDir = 3
- end
- if direction ~= targetDir then
- turnTo(targetDir)
- end
- local num = (math.abs(xx - uu)) + (math.abs(yy - vv))
- digforward(num)
- end
- local function hilbert(k)
- local i = k
- local pointsX = {0,0,1,1}
- local pointsY = {0,1,1,0}
- local index = bit32.band(i,3)
- local vx = pointsX[index+1]
- local vy = pointsY[index+1]
- for j = 1, order, 1 do
- i = bit32.rshift(i,2)
- index = bit32.band(i,3)
- local len = 2^j
- if index == 0 then
- local tmp = vx
- vx = vy
- vy = tmp
- elseif index == 1 then
- vy = vy + len
- elseif index == 2 then
- vx = vx + len
- vy = vy + len
- else
- local tmp = len - 1 - vx
- vx = len - 1 - vy
- vy = tmp
- vx = vx + len
- end
- end
- return vx,vy
- end
- local function createPoints()
- for i = 0, total, 1 do
- local path = table.pack(hilbert(i))
- pathX[i+1] = path[1]
- pathY[i+1] = path[2]
- local len = thick
- pathX[i+1] = pathX[i+1] * len
- pathY[i+1] = pathY[i+1] * len
- end
- end
- createPoints()
- for i = 1, total, 1 do
- goTo(pathX[i],pathY[i],pathX[i+1],pathY[i+1])
- end
Advertisement
Comments
-
- https://bigwarp.io/7txvvw88j47z
- https://bigwarp.io/37cal9qxtkfd
- https://bigwarp.io/yojwi7en1pvq
- https://bigwarp.io/qijd9p456n3q
- https://bigwarp.io/8q8rweiy8jbr
- https://bigwarp.io/twu7014koab0
- https://bigwarp.io/a52gx3me2yb6
- https://bigwarp.io/vbg8tr63zpg7
- https://bigwarp.io/0buj2xybbiya
- https://bigwarp.io/bpkjblxxvcne
- https://bigwarp.io/2uybz9tn4ylx
- https://bigwarp.io/zgj5po6pvxzi
- https://bigwarp.io/mku1zg635c3p
- https://bigwarp.io/ehrx7oehy8dz
- https://bigwarp.io/sgrz07aqfp65
- https://bigwarp.io/xrhv7lzwf1lg
- https://bigwarp.io/lng31yy8nn5t
- https://bigwarp.io/1m2pzph656py
- https://bigwarp.io/qigrntkn99pb
- https://bigwarp.io/8zndb2n6jiwy
- https://bigwarp.io/8ekzkk952yu3
- https://bigwarp.io/1u99fslfyel0
- https://bigwarp.io/n6cq48ytrt2i
Add Comment
Please, Sign In to add comment
Advertisement