fix: keep track of current miner targetY

This commit is contained in:
Guillaume ARM 2024-05-08 22:57:37 +02:00
parent 7fa1fb7cea
commit 09fc50d55e

View File

@ -4,16 +4,16 @@ local turtleUtils = require('turtle-utils')
local config = { local config = {
startY = 122, startY = 122,
targetY = 109, targetY = 109,
height = 1, height = 3,
size = 4 size = 4
} }
local TARGET_Y = config.targetY - config.startY local INITIAL_TARGET_Y = config.targetY - config.startY
local TARGET_Z = config.size - 1 local TARGET_Z = config.size - 1
local TARGET_X = config.size - 1 local TARGET_X = config.size - 1
local MAX_X = TARGET_X local MAX_X = TARGET_X
local MAX_Y = TARGET_Y + (config.height - 1) local MAX_Y = INITIAL_TARGET_Y + (config.height - 1)
local MAX_Z = TARGET_Z local MAX_Z = TARGET_Z
local LOWER_LIMIT = 2; local LOWER_LIMIT = 2;
@ -23,13 +23,14 @@ local robot = robotApi.create()
local MAX_INVENTORY_BLOCKS = 16 * 64 local MAX_INVENTORY_BLOCKS = 16 * 64
local ADDITIONAL_FUEL_NEEDED = 128 local ADDITIONAL_FUEL_NEEDED = 128
local MIN_FUEL_NEEDED = (config.size * 2) + TARGET_Y + MAX_INVENTORY_BLOCKS + ADDITIONAL_FUEL_NEEDED local MIN_FUEL_NEEDED = (config.size * 2) + INITIAL_TARGET_Y + MAX_INVENTORY_BLOCKS + ADDITIONAL_FUEL_NEEDED
local miner = { local miner = {
robot = robot, robot = robot,
mission = 'unload', -- "unload" | "refuel" | "mine" | "return-home" | "return-mine" | nil mission = 'unload', -- "unload" | "refuel" | "mine" | "return-home" | "return-mine" | nil
finished = false, finished = false,
lastPositionState = nil -- { x, y, z, dir } lastPositionState = nil, -- { x, y, z, dir }
targetY = INITIAL_TARGET_Y
} }
local function isOdd(x) local function isOdd(x)
@ -140,7 +141,7 @@ end
local function mineProcedure() local function mineProcedure()
local robotState = miner.robot.getState() local robotState = miner.robot.getState()
local targetY = TARGET_Y local targetY = miner.targetY
local targetZ = TARGET_Z local targetZ = TARGET_Z
-- 1. Move -- 1. Move
@ -181,6 +182,7 @@ local function mineProcedure()
miner.robot.turnRight() miner.robot.turnRight()
miner.robot.up() miner.robot.up()
miner.targetY = miner.targetY - 1
end end
if turtleUtils.countFreeSlots() < 1 then if turtleUtils.countFreeSlots() < 1 then