From fef74033d50cbdd3b8c3cc690ce9d6d814cd1cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Thu, 20 Aug 2020 00:05:59 +0200 Subject: [PATCH] Mine: tryhard forward --- turtles/mine.lua | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/turtles/mine.lua b/turtles/mine.lua index a49a936..35c4d91 100644 --- a/turtles/mine.lua +++ b/turtles/mine.lua @@ -70,10 +70,17 @@ function _count_move_dir(dir) end end -function move_forward() +function move_forward(will_retry) 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) + return true end function move_back() rc, desc = turtle.back() @@ -91,6 +98,20 @@ function move_down() height = height - 1 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) turn_abs(0) while depth > dd do @@ -285,9 +306,11 @@ function mine_shaft() turtle.dig() end - move_forward() + tryhard_forward() - mine_around() + if depth > 1 then -- if not we confuse find_next_shaft + mine_around() + end end turn_abs(2) while depth > 0 do