mine.lua: rewrite checkpoint 2
This commit is contained in:
parent
d0ab016dcf
commit
f4444cd120
1 changed files with 20 additions and 19 deletions
39
mine.lua
39
mine.lua
|
|
@ -21,7 +21,7 @@ function copy_v(v)
|
||||||
return vector.new(
|
return vector.new(
|
||||||
v.x,
|
v.x,
|
||||||
v.y,
|
v.y,
|
||||||
v.z,
|
v.z
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -33,8 +33,8 @@ local Block = {
|
||||||
-- orient our corner and offset to a vector
|
-- orient our corner and offset to a vector
|
||||||
orient = function (self, pos)
|
orient = function (self, pos)
|
||||||
local dims = {
|
local dims = {
|
||||||
x = { self.v1.x, self.v1.x + self.v2.x }
|
x = { self.v1.x, self.v1.x + self.v2.x },
|
||||||
y = { self.v1.y, self.v1.y + self.v2.y }
|
y = { self.v1.y, self.v1.y + self.v2.y },
|
||||||
z = { self.v1.z, self.v1.z + self.v2.z }
|
z = { self.v1.z, self.v1.z + self.v2.z }
|
||||||
}
|
}
|
||||||
for dim, points in pairs(dims) do
|
for dim, points in pairs(dims) do
|
||||||
|
|
@ -67,7 +67,7 @@ local Block = {
|
||||||
copy = function (self)
|
copy = function (self)
|
||||||
return Block.new(
|
return Block.new(
|
||||||
vector.new(self.v1.x, self.v1.y, self.v1.z),
|
vector.new(self.v1.x, self.v1.y, self.v1.z),
|
||||||
vector.new(self.v2.x, self.v2.y, self.v2.z),
|
vector.new(self.v2.x, self.v2.y, self.v2.z)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
@ -193,10 +193,11 @@ function refuelUntil (amt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function dropOffItems (starting_point, go_back)
|
function dropOffItems (starting_point, go_back)
|
||||||
|
print("Time to drop off what I got")
|
||||||
-- Turn off mining
|
-- Turn off mining
|
||||||
mode.mine = { forward = true }
|
mode.mine = { forward = true }
|
||||||
-- Note current position (assuming facing FORWARD)
|
-- Note current position (assuming facing FORWARD)
|
||||||
local pos_state = vector.new(mode.v.x, mode.v.y, mode.v.z)
|
local pos_state = getCurrentPos()
|
||||||
-- Return to origin, facing BACK
|
-- Return to origin, facing BACK
|
||||||
moveAbs(starting_point)
|
moveAbs(starting_point)
|
||||||
moveAbs(V_ZERO)
|
moveAbs(V_ZERO)
|
||||||
|
|
@ -232,7 +233,7 @@ function mine (block)
|
||||||
-- a. don't move vertically if you don't have to
|
-- a. don't move vertically if you don't have to
|
||||||
-- b. set mining mode beforehand
|
-- b. set mining mode beforehand
|
||||||
-- 2. move to the ending point
|
-- 2. move to the ending point
|
||||||
local height = block.v2.y
|
local height = block.v2.y + 1
|
||||||
if height % 3 == 0 then
|
if height % 3 == 0 then
|
||||||
mode.mine = { up = true, forward = true, down = true }
|
mode.mine = { up = true, forward = true, down = true }
|
||||||
elseif height == 2 then
|
elseif height == 2 then
|
||||||
|
|
@ -249,14 +250,14 @@ function mine (block)
|
||||||
start_v = start_v - UNIT_Y
|
start_v = start_v - UNIT_Y
|
||||||
end_v = end_v - UNIT_Y
|
end_v = end_v - UNIT_Y
|
||||||
end
|
end
|
||||||
move(start_v)
|
moveAbs(start_v)
|
||||||
move(end_v)
|
moveAbs(end_v)
|
||||||
end
|
end
|
||||||
|
|
||||||
function canMine (block)
|
function canMine (block)
|
||||||
local tooHigh = block.v2.y > 3
|
local tooHigh = block.v2.y > 2
|
||||||
-- we can only mine in a 1-wide strip at a time
|
-- we can only mine in a 1-wide strip at a time
|
||||||
local tooWide = block.v2.x > 1 and block.v2.z > 1
|
local tooWide = block.v2.x > 0 and block.v2.z > 0
|
||||||
return not (tooHigh or tooWide)
|
return not (tooHigh or tooWide)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -272,7 +273,7 @@ end
|
||||||
|
|
||||||
function split (block)
|
function split (block)
|
||||||
local tooHigh = function (block)
|
local tooHigh = function (block)
|
||||||
return block.v2.y > 3
|
return block.v2.y > 2
|
||||||
end
|
end
|
||||||
block = block:orient(getCurrentPos())
|
block = block:orient(getCurrentPos())
|
||||||
if tooHigh(block) then
|
if tooHigh(block) then
|
||||||
|
|
@ -283,12 +284,10 @@ function split (block)
|
||||||
end
|
end
|
||||||
|
|
||||||
function process (stack, starting_point)
|
function process (stack, starting_point)
|
||||||
-- START code taken from `mine`
|
|
||||||
-- fuel and go to starting point
|
-- fuel and go to starting point
|
||||||
refuelUntil(FUEL_RESERVE)
|
refuelUntil(FUEL_RESERVE)
|
||||||
mode.mine = { forward = true }
|
mode.mine = { forward = true }
|
||||||
moveAbs(starting_point)
|
moveAbs(starting_point)
|
||||||
-- END
|
|
||||||
-- TODO
|
-- TODO
|
||||||
if #stack == 0 then return nil end
|
if #stack == 0 then return nil end
|
||||||
local working = table.remove(stack):orient(getCurrentPos())
|
local working = table.remove(stack):orient(getCurrentPos())
|
||||||
|
|
@ -323,7 +322,7 @@ function calculateBlock (v1, v2)
|
||||||
normalize("y", v1.y, v2.y)
|
normalize("y", v1.y, v2.y)
|
||||||
normalize("z", v1.z, v2.z)
|
normalize("z", v1.z, v2.z)
|
||||||
return new_block(
|
return new_block(
|
||||||
vector.new(block.x, block.y, block.z)
|
vector.new(block.x, block.y, block.z),
|
||||||
vector.new(block.xoff, block.yoff, block.zoff)
|
vector.new(block.xoff, block.yoff, block.zoff)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
@ -332,14 +331,16 @@ function run (v1, v2)
|
||||||
-- TODO calculate starting_point, the place turtle will move to before
|
-- TODO calculate starting_point, the place turtle will move to before
|
||||||
-- moving to the first corner of block
|
-- moving to the first corner of block
|
||||||
local block = new_block(v1, v2 - v1)
|
local block = new_block(v1, v2 - v1)
|
||||||
process({ block })
|
local starting_point = V_ZERO
|
||||||
|
|
||||||
|
process({ block }, starting_point)
|
||||||
-- return to base
|
-- return to base
|
||||||
dropOffItems(starting_point)
|
dropOffItems(starting_point)
|
||||||
turnToFace(FORWARD)
|
turnToFace(FORWARD)
|
||||||
end
|
end
|
||||||
|
|
||||||
function usage ()
|
function usage ()
|
||||||
print("Usage: mine x1 y1 z1 x2 y2 z2 OR mine x1 y1 z1 OR mine x1 y1 z1
|
print("Usage: mine x1 y1 z1 x2 y2 z2 OR mine x1 y1 z1 OR mine x1 y1 z1 \
|
||||||
x2 y2 z2 x_turtle y_turtle z_turtle.")
|
x2 y2 z2 x_turtle y_turtle z_turtle.")
|
||||||
print("Mine from the first set of coordinates to the second in a \
|
print("Mine from the first set of coordinates to the second in a \
|
||||||
rectangular prism.")
|
rectangular prism.")
|
||||||
|
|
@ -347,9 +348,9 @@ function usage ()
|
||||||
start of the program.")
|
start of the program.")
|
||||||
print("If invoked with only three arguments, act as if they are the last \
|
print("If invoked with only three arguments, act as if they are the last \
|
||||||
three arguments and substitute 0 0 0 for the first three.")
|
three arguments and substitute 0 0 0 for the first three.")
|
||||||
print("If invoked with nine arguments, interpret the first two sets as
|
print("If invoked with nine arguments, interpret the first two sets as \
|
||||||
world coordinates of the rectangular prism and the third set as
|
world coordinates of the rectangular prism and the third set as \
|
||||||
the coordinates of the turtle's starting position,
|
the coordinates of the turtle's starting position, \
|
||||||
ASSUMING FACING NORTH.")
|
ASSUMING FACING NORTH.")
|
||||||
print("Fuel goes in the top-left slot of the turtle's inventory.")
|
print("Fuel goes in the top-left slot of the turtle's inventory.")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue