feat: implement medium-chunk splitting

This commit is contained in:
Emerson Rosen-Jones 2025-12-21 14:05:29 -05:00
parent 56c511324e
commit 6ced67f883

View file

@ -6,9 +6,13 @@ local FUEL_RESERVE = 800
local FUEL_REFUEL_UNIT = 8 -- how many items to refuel with at a time local FUEL_REFUEL_UNIT = 8 -- how many items to refuel with at a time
local FULL_CHECK_SLOT = 14 -- slot to check for "fullness" local FULL_CHECK_SLOT = 14 -- slot to check for "fullness"
-- what size is good for a medium-size piece
local MED_DIM = 11
-- what size of a dimension is considered big enough to split into medium-size -- what size of a dimension is considered big enough to split into medium-size
-- pieces -- pieces
local BIG_DIM = 7 local BIG_DIM = MED_DIM * 3
local V_ZERO = vector.new(0, 0, 0) local V_ZERO = vector.new(0, 0, 0)
local UNIT_X = vector.new(1, 0, 0) local UNIT_X = vector.new(1, 0, 0)
@ -280,32 +284,19 @@ end
function splitHorizontal (block) function splitHorizontal (block)
-- TODO make this less naive? -- TODO make this less naive?
-- Future work: potentially split a large block into smaller blocks local take_amt = 1
-- based on currentPos (think splitting down the middle instead of
-- splitting off of one end)
local differentSigns = function (a, b)
return math.abs(a + b) < math.abs(a) + math.abs(b)
end
local bigBlock = function (block) local bigBlock = function (block)
return (block.v2.x >= BIG_DIM) and (block.v2.z >= BIG_DIM) return (block.v2.x >= BIG_DIM) or (block.v2.z >= BIG_DIM)
end end
local inMiddleOfBlock = function (block) if bigBlock(block) then
local middle_of_x = differentSigns(block.v1.x, block.v2.x) take_amt = MED_DIM
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 split the big block at where the turtle is near
end end
-- decide whether to take a slice off of the x or z direction -- decide whether to take a slice off of the x or z direction
-- (criteria: take the dimension that is not too big) -- (criteria: bite a piece off the bigger dimension)
if math.abs(block.v2.z) < BIG_DIM then if math.abs(block.v2.z) >= math.abs(block.v2.x) then
return block:take(1, "z") return block:take(take_amt, "z")
else else
return block:take(1, "x") return block:take(take_amt, "x")
end end
end end