mine.lua: rewrite checkpoint 5
This commit is contained in:
parent
91a27e292e
commit
91a0242ad0
1 changed files with 16 additions and 11 deletions
27
mine.lua
27
mine.lua
|
|
@ -29,13 +29,14 @@ function copy_v(v)
|
|||
)
|
||||
end
|
||||
|
||||
local bmetatable
|
||||
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)
|
||||
self.v1 = self.v1 - pos
|
||||
local dims = {
|
||||
x = { self.v1.x, self.v1.x + self.v2.x },
|
||||
y = { self.v1.y, self.v1.y + self.v2.y },
|
||||
|
|
@ -61,15 +62,21 @@ local Block = {
|
|||
-- TODO
|
||||
if dir ~= "x" and dir ~= "y" and dir ~= "z" then return nil end
|
||||
|
||||
local block_offset = -1
|
||||
if self.v2[dir] < 0 then
|
||||
amt = amt * -1
|
||||
block_offset = block_offset * -1
|
||||
end
|
||||
|
||||
local new, remainder = self:copy(), self
|
||||
new.v1[dir] = amt
|
||||
new.v2[dir] = amt + block_offset
|
||||
remainder.v1[dir] = remainder.v1[dir] + amt
|
||||
remainder.v2[dir] = remainder.v2[dir] - amt
|
||||
|
||||
return new, remainder
|
||||
end,
|
||||
copy = function (self)
|
||||
return Block.new(
|
||||
return new_block(
|
||||
vector.new(self.v1.x, self.v1.y, self.v1.z),
|
||||
vector.new(self.v2.x, self.v2.y, self.v2.z)
|
||||
)
|
||||
|
|
@ -85,7 +92,7 @@ bmetatable = {
|
|||
__index = Block,
|
||||
}
|
||||
|
||||
local new_block = function (v1, v2)
|
||||
new_block = function (v1, v2)
|
||||
return setmetatable(
|
||||
{ v1 = v1, v2 = v2 },
|
||||
bmetatable
|
||||
|
|
@ -265,7 +272,7 @@ end
|
|||
function canMine (block)
|
||||
local tooHigh = block.v2.y > 2
|
||||
-- we can only mine in a 1-wide strip at a time
|
||||
local tooWide = block.v2.x > 0 and block.v2.z > 0
|
||||
local tooWide = (math.abs(block.v2.x) > 0) and (math.abs(block.v2.z) > 0)
|
||||
return not (tooHigh or tooWide)
|
||||
end
|
||||
|
||||
|
|
@ -286,14 +293,14 @@ function splitHorizontal (block)
|
|||
return bigBlock(block) and inMiddleOfBlock(block)
|
||||
end
|
||||
if inMiddleOfBigBlock(block) then
|
||||
-- TODO
|
||||
-- TODO split the big block at where the turtle is near
|
||||
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
|
||||
if block.v2.z <= block.v2.x then
|
||||
return block:take(1, "z")
|
||||
else
|
||||
return block:take(1, "x")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -301,7 +308,6 @@ function split (block)
|
|||
local tooHigh = function (block)
|
||||
return block.v2.y > 2
|
||||
end
|
||||
block = block:orient(getCurrentPos())
|
||||
if tooHigh(block) then
|
||||
return block:take(3, "y")
|
||||
else
|
||||
|
|
@ -313,7 +319,6 @@ function process (stack, starting_point)
|
|||
-- fuel and go to starting point
|
||||
refuelUntil(FUEL_RESERVE)
|
||||
mode.mine = { forward = true }
|
||||
-- TODO
|
||||
if #stack == 0 then return nil end
|
||||
local working = table.remove(stack):orient(getCurrentPos())
|
||||
print("Working:", working:tostring())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue