Mines N rows of given length and always comes back the exact amount it
mined so if there is a problem it doesn't mess it up
master
D4VID 1 year ago
parent 11a902dcd7
commit 58e14bdf35

@ -1,15 +1,59 @@
local robot = require("robot") local robot = require("robot")
local arg = ... local function mine_single()
robot.swing()
local function mine(count) local result, error = robot.forward()
for i = 1, count do if not result then
robot.swing() print("Cannot mine: " .. error)
robot.up() return false
robot.swing() end
robot.down()
robot.forward() robot.swingUp()
return true
end
local function mine_n(count)
local mined = 0
for _ = 1, count do
if mine_single() then
mined = mined + 1
else
break
end
end
return mined
end
local function mine_row(length)
local mined = mine_n(length)
robot.turnAround()
for _ = 1, mined do
while not robot.forward() do end
end end
end end
mine(arg) local function mine(mine_rows, mine_row_length)
for i = 1, mine_rows do
print("Mining row " .. i .. " of " .. mine_rows)
mine_row(mine_row_length)
robot.turnLeft()
if mine_n(3) ~= 3 then
print("Unable to continue mining rows")
return
end
robot.turnLeft()
end
end
local rows, row_length = ...
print("Will mine " .. rows .. "x" .. row_length .. " rows")
mine(rows, row_length)

Loading…
Cancel
Save