commit
796c982890
@ -0,0 +1,47 @@
|
|||||||
|
local robot = require("robot")
|
||||||
|
local os = require("os")
|
||||||
|
|
||||||
|
local length = ...
|
||||||
|
|
||||||
|
if not length then
|
||||||
|
print('Usage: lumberjack <length>')
|
||||||
|
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
|
Loading…
Reference in new issue