Compare commits

...
Sign in to create a new pull request.

4 commits

Author SHA1 Message Date
Emerson Rosen-Jones
af05e2dd21 chore: remove completed TODOs 2025-12-21 14:05:39 -05:00
Emerson Rosen-Jones
6ced67f883 feat: implement medium-chunk splitting 2025-12-21 14:05:29 -05:00
Emerson Rosen-Jones
56c511324e fix: remove unnecessary variable in function call 2025-12-21 13:56:27 -05:00
Emerson Rosen-Jones
ef808abb94 fix: correct movement logic 2025-12-21 13:56:04 -05:00

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 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
-- pieces
local BIG_DIM = 7
local BIG_DIM = MED_DIM * 3
local V_ZERO = vector.new(0, 0, 0)
local UNIT_X = vector.new(1, 0, 0)
@ -32,7 +36,6 @@ end
local bmetatable, new_block
-- what is this? a type that holds a starting position and a dimention as
-- two vectors
-- TODO learn about metatables
local Block = {
-- orient our corner and offset to a vector
orient = function (self, pos)
@ -60,7 +63,6 @@ local Block = {
return self
end,
take = function (self, amt, dir)
-- TODO
if dir ~= "x" and dir ~= "y" and dir ~= "z" then return nil end
local block_offset = -1
@ -212,8 +214,6 @@ function dropOffItems (starting_point, go_back)
print("Time to drop off what I got")
-- Turn off mining
mode.mine = { forward = true }
-- Note current position (assuming facing FORWARD)
local pos_state = getCurrentPos()
-- Return to origin, facing BACK
moveAbs(starting_point)
moveAbs(V_ZERO)
@ -224,10 +224,9 @@ function dropOffItems (starting_point, go_back)
turtle.drop()
end
turtle.select(1)
-- Return to current position, facing forward
-- Return to the mining zone, facing forward
if go_back then
moveAbs(starting_point)
moveAbs(pos_state)
end
end
@ -282,33 +281,19 @@ function canMine (block)
end
function splitHorizontal (block)
-- TODO make this less naive?
-- 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)
local differentSigns = function (a, b)
return math.abs(a + b) < math.abs(a) + math.abs(b)
end
local take_amt = 1
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
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 split the big block at where the turtle is near
if bigBlock(block) then
take_amt = MED_DIM
end
-- decide whether to take a slice off of the x or z direction
-- (criteria: take the dimension that is not too big)
if math.abs(block.v2.z) < BIG_DIM then
return block:take(1, "z")
-- (criteria: bite a piece off the bigger dimension)
if math.abs(block.v2.z) >= math.abs(block.v2.x) then
return block:take(take_amt, "z")
else
return block:take(1, "x")
return block:take(take_amt, "x")
end
end
@ -324,17 +309,16 @@ function split (block)
end
function process (stack, starting_point)
-- fuel and go to starting point
refuelUntil(FUEL_RESERVE)
mode.mine = { forward = true }
if #stack == 0 then return nil end
checkAndDropOff(starting_point)
local working = table.remove(stack):orient(getCurrentPos())
print("Working:", working:tostring())
if canMine(working) then
checkAndDropOff(starting_point)
mine(working)
else
local new, remainder = split(working, mode.v)
local new, remainder = split(working)
table.insert(stack, remainder)
table.insert(stack, new)
end
@ -349,7 +333,7 @@ function run (v1, v2)
process({ block }, starting_point)
-- return to base
dropOffItems(starting_point)
dropOffItems(starting_point, false)
turnToFace(FORWARD)
end