diff --git a/mine.lua b/mine.lua index 18b2598..09a6224 100644 --- a/mine.lua +++ b/mine.lua @@ -6,6 +6,10 @@ local FUEL_RESERVE = 800 local FUEL_REFUEL_UNIT = 8 -- how many items to refuel with at a time local FULL_CHECK_SLOT = 14 -- slot to check for "fullness" +-- what size of a dimension is considered big enough to split into medium-size +-- pieces +local BIG_DIM = 7 + local V_ZERO = vector.new(0, 0, 0) local UNIT_X = vector.new(1, 0, 0) local UNIT_Y = vector.new(0, 1, 0) @@ -69,6 +73,10 @@ local Block = { vector.new(self.v1.x, self.v1.y, self.v1.z), vector.new(self.v2.x, self.v2.y, self.v2.z) ) + end, + tostring = function (self) + -- TODO revisit? + return string.format('%s %s', self.v1:tostring(), self.v2:tostring()) end } @@ -266,9 +274,27 @@ function splitHorizontal (block) -- Future work: potentially split a large block into smaller blocks -- based on currentPos (think splitting down the middle instead of -- splitting off of one end) - -- Future work: decide whether to take a slice off of the x or z direction - -- (criteria?) - return block:take(1, "x") + local bigBlock = function (block) + return (block.v2.x >= BIG_DIM) and (block.v2.z >= BIG_DIM) + end + local inMiddleOfBlock = function (block) + local middle_of_x = differentSigns(block.v1.x, block.v2.x) + local middle_of_z = differentSigns(block.v1.z, block.v2.z) + return middle_of_x or middle_of_z + end + local inMiddleOfBigBlock = function (block) + return bigBlock(block) and inMiddleOfBlock(block) + end + if inMiddleOfBigBlock(block) then + -- TODO + end + -- decide whether to take a slice off of the x or z direction + -- (criteria: take the dimension with the smaller length) + if block.v2.x <= block.v2.z then + return block:take(1, "x") + else + return block:take(1, "z") + end end function split (block) @@ -287,10 +313,10 @@ function process (stack, starting_point) -- fuel and go to starting point refuelUntil(FUEL_RESERVE) mode.mine = { forward = true } - moveAbs(starting_point) -- TODO if #stack == 0 then return nil end local working = table.remove(stack):orient(getCurrentPos()) + print("Working:", working:tostring()) if canMine(working) then checkAndDropOff(starting_point) mine(working) @@ -299,7 +325,7 @@ function process (stack, starting_point) table.insert(stack, remainder) table.insert(stack, new) end - return process (stack) + return process (stack, starting_point) end function run (v1, v2)