Compare commits

...

1 commit

Author SHA1 Message Date
Théophile Bastian 097c2bf812 Mine: keep next shaft position 2020-08-18 20:14:09 +02:00

View file

@ -24,6 +24,10 @@ FUEL_LOW = 1000
SHAFT_DEPTH = 100 SHAFT_DEPTH = 100
-- Start at this position to find the next shaft
next_shaft_side = 0
next_shaft_height = 0
function distance_to_drop() function distance_to_drop()
return math.abs(depth - DROP_POINT_D) return math.abs(depth - DROP_POINT_D)
+ math.abs(height - DROP_POINT_H) + math.abs(height - DROP_POINT_H)
@ -178,42 +182,37 @@ function find_next_shaft()
return is_shaft_pos() and turtle.detect() return is_shaft_pos() and turtle.detect()
end end
go_to(0, 0, 0) go_to(next_shaft_height, 0, next_shaft_side)
while true do while true do
for hei=1,MAX_HEIGHT-1 do if side % 2 == 0 then
while height < MAX_HEIGHT - 1 do
if is_shaft() then
return
end
if turtle.detectUp() then
turtle.digUp()
end
move_up()
end
if is_shaft() then if is_shaft() then
return return
end end
else
while height > 0 do
if is_shaft() then
return
end
if turtle.detectUp() then if turtle.detectDown() then
turtle.digUp() turtle.digDown()
end
move_down()
end end
move_up()
end
if is_shaft() then
return
end
turn_abs(1)
if turtle.detect() then
turtle.dig()
end
move_forward()
turn_abs(0)
for hei=MAX_HEIGHT-1,1,-1 do
if is_shaft() then if is_shaft() then
return return
end end
if turtle.detectDown() then
turtle.digDown()
end
move_down()
end
if is_shaft() then
return
end end
turn_abs(1) turn_abs(1)
@ -242,6 +241,8 @@ function main()
while true do while true do
print("Finding shaft") print("Finding shaft")
find_next_shaft() find_next_shaft()
next_shaft_height = height
next_shaft_side = side
print("Mining shaft at position:") print("Mining shaft at position:")
_dump_pos() _dump_pos()
mine_shaft() mine_shaft()