我为采矿龟创建了以下脚本:
--Strip mining turtle program test
--Based on stripmining program by Gabriel *******(Spirr0u)
function excarvateRectangle(size,looptimes)
print("Excavating "..size .. " with looptimes "..looptimes)
if size > 0 then
for i=1, looptimes, 1 do
for z=1, size, 1 do
turtle.dig()
sleep(1)
turtle.forward()
end
turtle.turnRight()
end
onesmaller = size-1
excarvateRectangle(onesmaller,2)
end
end
function goBackToStart(size2)
print("Going back to "..size2)
-- go back like a stair with size as the number of turns
if size2 % 2 == 0 then
turnAround()
end
dir=0
for z=1, size2, 1 do
turtle.forward()
if dir == 0 then
turtle.turnLeft()
dir = 1
else
turtle.turnRight()
dir = 0
end
end
-- turn in the right direction
if size2 % 2 > 0 then
turtle.turnRight()
end
turtle.turnRight()
end
function digHole(origsize, depth)
for g=1, depth, 1 do
size = origsize
excarvateRectangle(size,3)
sleep(3)
goBackToStart(origsize)
turtle.digDown()
turtle.down()
end
for g=1, depth, 1 do
turtle.up()
end
end
function checkFuel()
while turtle.getFuelLevel() <= 50 do
turtle.select(15)
turtle.refuel(1)
turtle.select(1)
end
end
function turnAround()
turtle.turnRight()
turtle.turnRight()
end
-- MAIN
print("Fuel in slot 15")
print("Input rectangle size:")
origsize = io.read()
origsize = origsize +0
print("Input depth:")
depth = io.read()
depth = depth +0
checkFuel()
digHole(origsize, depth)
print("Finish")
对于测试,放入5表示大小,2表示深度。 它应该挖掘5个5块5块深。
会发生什么: 乌龟像螺旋一样挖出一个长方形区域。然后它从螺旋中心返回到起始位置。 现在它下降了一个又重新开始“深度”#39;次。
但是当它第二次回到起始位置时,它会显示出一种奇怪的行为。它不是左前方左转,而是左前后左转,然后以某种方式转身并结束。
我已经假设它可能是范围并重命名了变量。我为变量添加了调试输出。一切似乎都是正确的。我无法发现那里正在发生的事情。我想这可能是一场竞争。
任何帮助都将不胜感激。
谢谢,鲍里斯