You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
miner/mine.lua

60 lines
988 B

local robot = require("robot")
local function mine_single()
robot.swing()
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
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)