commit 796c982890bdc2eabed3d0245a1aca455e3d6332 Author: D4VID Date: Mon Oct 14 20:57:17 2024 +0200 Lumberjack diff --git a/lumberjack.lua b/lumberjack.lua new file mode 100644 index 0000000..33d2203 --- /dev/null +++ b/lumberjack.lua @@ -0,0 +1,47 @@ +local robot = require("robot") +local os = require("os") + +local length = ... + +if not length then + print('Usage: lumberjack ') + return +end + +local function mine_tree() + local n = 0 + robot.swing() + robot.forward() + robot.swingDown() + while robot.detectUp() do + robot.swingUp() + robot.up() + n = n + 1 + end + for _ = 1, n do + while not robot.down() do end + end + robot.placeDown() +end + +while true do + for _ = 1, length do + if robot.detect() then + mine_tree() + else + while not robot.forward() do end + end + robot.suckDown() + end + robot.turnAround() + for _ = 1, length do + if robot.detect() then + mine_tree() + else + while not robot.forward() do end + end + robot.suckDown() + end + robot.turnAround() + os.execute("sleep 5") +end