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/miner.lua

62 lines
1.2 KiB

local robot = require("robot")
local nav = require("navigator")
local function mine_single()
robot.swing()
local result, error = robot.forward()
if not result then
print("Cannot move: " .. 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()
nav.forward(mined)
end
-- starts facing right, mines rows to the right
-- ends facing "left"
local function mine(mine_rows, mine_row_length)
local moved_rows = nav.forward_until_solid()
for i = 1, mine_rows do
print("Mining row " .. i .. " of " .. mine_rows)
if mine_n(1) ~= 1 then
print("Unable to continue mining rows")
break
end
robot.turnLeft()
mine_row(mine_row_length)
moved_rows = moved_rows + 1
robot.turnLeft()
end
-- go back to start
robot.turnAround()
nav.forward(moved_rows)
end
return {
mine = mine
}