Карьер — программа для черепашки, позволяющая выкапывать вертикальные туннели.
Код карьера, копающего 6x6 блоков (измените в loop ~= 3
на 2 строке число 3 на глубину карьера вниз):
loop = 0 while loop ~= 3 do a = 0 b = 0 c = 0 d = 0 turtle.digDown() turtle.down() while a ~= 5 do turtle.dig() turtle.forward() a = a + 1 end turtle.turnRight() while b ~= 5 do turtle.dig() turtle.forward() b = b + 1 end turtle.turnRight() while c ~= 5 do turtle.dig() turtle.forward() c = c + 1 end turtle.turnRight() while d ~= 4 do turtle.dig() turtle.forward() d = d + 1 end turtle.turnRight() e = 0 f = 0 g = 0 h = 0 while e ~= 4 do turtle.dig() turtle.forward() e = e + 1 end turtle.turnRight() while f ~= 3 do turtle.dig() turtle.forward() f = f + 1 end turtle.turnRight() while g ~= 3 do turtle.dig() turtle.forward() g = g + 1 end turtle.turnRight() while h ~= 2 do turtle.dig() turtle.forward() h = h + 1 end turtle.turnRight() turtle.dig() turtle.forward() turtle.dig() turtle.forward() turtle.turnRight() turtle.dig() turtle.forward() turtle.turnRight() turtle.dig() turtle.turnRight() turtle.dig() turtle.forward() turtle.forward() turtle.forward() turtle.forward() turtle.turnLeft() turtle.forward() turtle.forward() turtle.forward() turtle.turnRight() turtle.turnRight() a = 0 b = 0 c = 0 d = 0 e = 0 f = 0 g = 0 h = 0 loop = loop + 1 end
Также в самой черепахе имеется список предустановленных программ и вместо всей написанной сверху лабуды можно набрать excavate 6. При этом если за спиной черепахи поставить сундук, то она будет возвращаться и складывать дроп. Копает до коренной породы.
Использованные методы:
Название метода | Описание |
---|---|
turtle.forward() | Передвигает черепашку на 1 блок вперёд. |
turtle.down() | Опускает черепашку на 1 блок вниз. |
turtle.dig() | Черепашка добывает блок перед собой (если его можно сломать этим инструментом). |
turtle.digDown() | Черепашка добывает блок под собой (если его можно сломать этим инструментом). |
turtle.turnLeft() | Поворачивает черепашку на 90 градусов влево. |
turtle.turnRight() | Поворачивает черепашку на 90 градусов вправо. |
Черепашка выкапывает комнату высотой в 2 блока и размером N*2 x А зигзагом. В 1 слот необходимо положить осыпающуюся породу (гравий, песок), которая встречается в данной местности. При необходимости программный код можно сократить.
n = 15 while n > 0 turtle.turnRight() if turtle.detect() then turtle.dig() end while turtle.compare() do turtle.dig() end turtle.forward() if turtle.detectUp() then turtle.digUp() end while turtle.compareUp() do turtle.digUp() end turtle.turnRight() a = 30 while a > 0 do if turtle.detect() then turtle.dig() end while turtle.compare() do turtle.dig() end turtle.forward() if turtle.detectUp() then turtle.digUp() end while turtle.compareUp() do turtle.digUp() end a=a-1 end turtle.turnLeft() if turtle.detect() then turtle.dig() end while turtle.compare() do turtle.dig() end turtle.forward() if turtle.detectUp() then turtle.digUp() end while turtle.compareUp() do turtle.digUp() end turtle.turnLeft() a = 30 while a > 0 do if turtle.detect() then turtle.dig() end while turtle.compare() do turtle.dig() end turtle.forward() if turtle.detectUp() then turtle.digUp() end while turtle.compareUp() do turtle.digUp() end a=a-1 end n=n-1 end
Это универсальная программа для копания кубических областей любого размера. Ограничением является только вместительность топливного резервуара черепашки и дальность прогрузки чанков. Эта программа должна быть установлена на золотую черепашку для корректной работы встроенного интерфейса, но на обычных черепахах она тоже будет работать без ошибок. В интерфейсе программы можно настраивать размер области, направление копания (Вверх или Вниз), и необходимость складывать вещи из черепашки в сундук.
Внимание сундук должен быть установлен над черепашкой! Интерфейс программы:
-- Variable section -- A1 = 1 A2 = 1 LineNum = 1 completed = 0 xcor = 0 zcor = 0 ycor = 1 zd = 0 yd = 0 xd = 0 r = 0 -- GUI -- term.clear() term.setCursorPos(1,1) print("Welcome to Digging programm!") sleep(0.5) write("X size(Forward): ") xs = read() xs = xs + 0 write("Z size(Right): ") zs = read() zs = zs + 0 write("Y size(Up/Down): ") ys = read() ys = ys + 0 print("Drop items in chest?") while A1 == 1 do if LineNum == 1 then term.clearLine(6) term.setCursorPos(1,6) print("[Yes] No ") elseif LineNum == 2 then term.clearLine(6) term.setCursorPos(1,6) print(" Yes [No]") end name,data = os.pullEvent() if name == "key" then if data == 28 then if LineNum == 1 then Chest = 1 A1 = 0 elseif LineNum == 2 then Chest = 0 A1 = 0 end end if data == 205 or data == 200 then LineNum = LineNum + 1 elseif data == 203 or data == 208 then LineNum = LineNum - 1 end end if name == "mouse_scroll" then if data == 1 then LineNum = LineNum + 1 elseif data == - 1 then LineNum = LineNum - 1 end end if LineNum == 3 then LineNum = 1 end if LineNum == 0 then LineNum = 2 end end LineNum = 1 while A2 == 1 do if LineNum == 1 then term.clearLine(7) term.setCursorPos(1,7) print("[Dig Up] Dig Down ") elseif LineNum == 2 then term.clearLine(7) term.setCursorPos(1,7) print(" Dig Up [Dig Down]") end name,data = os.pullEvent() if name == "key" then if data == 205 or data == 200 then LineNum = LineNum + 1 elseif data == 203 or data == 208 then LineNum = LineNum - 1 end if data == 28 then if LineNum == 1 then Dir = "up" A2 = 0 elseif LineNum == 2 then Dir = "down" A2 = 0 end end end if name == "mouse_scroll" then if data == 1 then LineNum = LineNum + 1 elseif data == -1 then LineNum = LineNum - 1 end end if LineNum == 3 then LineNum = 1 elseif LineNum == 0 then LineNum = 2 end end LineNum = 1 term.clear() term.setCursorPos(1,1) reqfuel = xs*zs*ys print("Minimum fuel required: ",reqfuel) turtle.select(1) turtle.refuel(10) fuel = turtle.getFuelLevel() print("Fuel : ",fuel) A3 = 0 if reqfuel > 100000 then print("Sorry but selected size is") print("too large :)") sleep(2,5) print("rebooting...") sleep(1.5) os.reboot() end if fuel < reqfuel then A3 = 1 end while A3 == 1 do term.clearLine(2) term.setCursorPos(1,2) print("Fuel: [",fuel,"/",reqfuel,"]") print("Place fuel in slot 1") turtle.select(1) turtle.refuel(10) fuel = turtle.getFuelLevel() if fuel >= reqfuel then term.clearLine(3) term.setCursorPos(1,3) A3 = 0 end end term.clearLine(2) term.clearLine(3) term.setCursorPos(1,3) print("X size : ",xs) print("Y size : ",ys) print("Z size : ",zs) write("Use chest : ") if Chest == 1 then print("Yes")
elseif Chest == 0 then print("No") end print("Mining direction : ",Dir) print("To start press any botton...") print("To reboot press Ctrl...") name,data = os.pullEvent("key") if name == "key" and data == 29 then os.reboot() end size = xs * zs * ys local function monitor() term.clear() term.setCursorPos(1,1) rfuel = turtle.getFuelLevel() print("Fuel : ",rfuel) print("Position : "," X: ",xcor," Y: ",ycor," Z: ",zcor) end -- Mining section -- zcor = 1 completed = 0 finish = 0 A9 = 0 bd = 0 while finish == 0 do monitor() if Chest == 1 and turtle.getItemCount(16) > 0 then A9 = 1 xlcor = xcor zlcor = zcor ylcor = ycor if r == 0 then while xcor > 1 do if turtle.back() then xcor = xcor - 1 end end turtle.turnLeft() while zcor > 1 do if turtle.forward() then zcor = zcor - 1 end end while ycor > 1 do if Dir == "up" then if turtle.down() then ycor = ycor - 1 end elseif Dir == "down" then if turtle.up() then ycor = ycor - 1 end end end turtle.turnRight() end if r == 1 then turtle.turnRight() while zcor > 1 do if turtle.forward() then zcor = zcor - 1 end end turtle.turnLeft() while xcor > 1 do if turtle.forward() then xcor = xcor - 1 end end turtle.turnRight() turtle.turnRight() while ycor > 1 do if Dir == "up" then if turtle.down() then ycor = ycor - 1 end elseif Dir == "down" then if turtle.up() then ycor = ycor - 1 end end end end turtle.back() slotNum = 16 turtle.select(16) turtle.dropUp() while slotNum > 1 do slotNum = slotNum - 1 turtle.select(slotNum) turtle.dropUp() end turtle.forward() while xcor < xlcor do turtle.dig() if turtle.forward() then xcor = xcor + 1 end end turtle.turnRight() while zcor < zlcor do turtle.dig() if turtle.forward() then zcor = zcor + 1 end end if r == 0 then turtle.turnLeft() elseif r == 1 then turtle.turnRight() end while ycor < ylcor do if Dir == "up" then if turtle.up() then ycor = ycor + 1 end elseif Dir == "down" then if turtle.down() then ycor = ycor + 1 end end end end turtle.dig() if ys - yd > 1 and xcor > 0 then if Dir == "up" then turtle.digUp() elseif Dir == "down" then turtle.digDown() end end monitor() if finish == 0 and turtle.forward() then monitor() xd = xd + 1 if r == 0 then xcor = xcor + 1 elseif r == 1 then xcor = xcor - 1 end end if zd + 1 == zs and xd == xs then completed = 1 end if completed == 1 then if r == 0 then turtle.turnLeft() if ys - yd > 1 then if Dir == "up" then turtle.digUp() elseif Dir == "down" then turtle.digDown() end end monitor() while zcor > 1 do turtle.dig() if turtle.forward() then zcor = zcor - 1 end end turtle.turnLeft() while xcor > 1 do turtle.dig() if turtle.forward() then xcor = xcor - 1 end end turtle.turnLeft() turtle.turnLeft() end if r == 1 then r = 0 if ys - yd > 1 then if Dir == "up" then turtle.digUp() elseif Dir == "down" then turtle.digDown() end end turtle.turnRight() while zcor > 1 do if turtle.forward() then zcor = zcor - 1 end end turtle.turnRight() end if ys - yd > 1 then yd = yd + 2 elseif ys - yd == 1 then yd = yd + 1 end end monitor() if completed == 1 and yd < ys then xd = 1 zd = 0 zcor = 1 xcor = 1 completed = 0 ycor = ycor + 2 A8 = 1 if Dir == "up" then while A8 == 1 do turtle.digUp() if turtle.up() then A8 = 0 end end A8 = 1 while A8 == 1 do turtle.digUp() if turtle.up() then A8 = 0 end end elseif Dir == "down" then while A8 == 1 do turtle.digDown() if turtle.down() then A8 = 0 end end A8 = 1 while A8 == 1 do turtle.digDown() if turtle.down() then A8 = 0 end end end end monitor() if completed == 1 and yd == ys then print("completed!") while ycor > 1 do if Dir == "up" then turtle.digUp() if turtle.down() then ycor = ycor - 1 end elseif Dir == "down" then turtle.digDown() if turtle.up() then ycor = ycor - 1 end end end finish = 1 end if completed == 0 and xd == xs and r == 0 and zd<zs then if ys - yd > 1 then if Dir == "down" then turtle.digDown() elseif Dir == "up" then turtle.digUp() end end A4 = 1 xd = 1 r = 1 zd = zd + 1 zcor = zcor + 1 turtle.turnRight() while A4 == 1 do turtle.dig() if turtle.forward() then A4 = 0 end end turtle.turnRight() end if completed == 0 and xd == xs and r == 1 and zd < zs then if ys - yd > 1 then if Dir == "up" then turtle.digUp() elseif Dir == "down" then turtle.digDown() end end A5 = 1 xd = 1 r = 0 zd = zd + 1 zcor = zcor + 1 turtle.turnLeft() while A5 == 1 do turtle.dig() if turtle.forward() then A5 = 0 end end turtle.turnLeft() end monitor() end monitor() print("Completed!")
Для большей информации см. Turtle API