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 upmaster
parent
11a902dcd7
commit
58e14bdf35
@ -1,15 +1,59 @@
|
||||
local robot = require("robot")
|
||||
|
||||
local arg = ...
|
||||
local function mine_single()
|
||||
robot.swing()
|
||||
|
||||
local function mine(count)
|
||||
for i = 1, count do
|
||||
robot.swing()
|
||||
robot.up()
|
||||
robot.swing()
|
||||
robot.down()
|
||||
robot.forward()
|
||||
local result, error = robot.forward()
|
||||
if not result then
|
||||
print("Cannot mine: " .. error)
|
||||
return false
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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…
Reference in new issue