Mine: tryhard forward

This commit is contained in:
Théophile Bastian 2020-08-20 00:05:59 +02:00
parent 99d6aeb35e
commit fef74033d5

View file

@ -70,10 +70,17 @@ function _count_move_dir(dir)
end end
end end
function move_forward() function move_forward(will_retry)
rc, desc = turtle.forward() rc, desc = turtle.forward()
if not rc then abort("Move: "..desc) end if not rc then
if will_retry then
return false
else
abort("Move: "..desc)
end
end
_count_move_dir(facing) _count_move_dir(facing)
return true
end end
function move_back() function move_back()
rc, desc = turtle.back() rc, desc = turtle.back()
@ -91,6 +98,20 @@ function move_down()
height = height - 1 height = height - 1
end end
function tryhard_forward()
for i=1,5 do
while turtle.detect() do
turtle.dig()
end
if move_forward(true) then
return true
else
sleep(1)
end
end
abort('Giving up trying to move forward.')
end
function go_to_depth(dd) function go_to_depth(dd)
turn_abs(0) turn_abs(0)
while depth > dd do while depth > dd do
@ -285,9 +306,11 @@ function mine_shaft()
turtle.dig() turtle.dig()
end end
move_forward() tryhard_forward()
mine_around() if depth > 1 then -- if not we confuse find_next_shaft
mine_around()
end
end end
turn_abs(2) turn_abs(2)
while depth > 0 do while depth > 0 do