Compare commits
1 commit
7721442731
...
325cd5c7f3
Author | SHA1 | Date | |
---|---|---|---|
Théophile Bastian | 325cd5c7f3 |
|
@ -51,15 +51,53 @@ function turn_rel(dir)
|
||||||
turn_abs((facing + dir) % 4)
|
turn_abs((facing + dir) % 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Dumps the current turtle position
|
||||||
|
function _dump_pos()
|
||||||
|
print("Current position: H "..height.." S "..side.." D "..depth)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Updates the turtle position for a move in the given direction
|
||||||
|
function _count_move_dir(dir)
|
||||||
|
dir = dir % 4
|
||||||
|
if dir == 0 then depth = depth + 1
|
||||||
|
elseif dir == 1 then side = side + 1
|
||||||
|
elseif dir == 2 then depth = depth - 1
|
||||||
|
elseif dir == 3 then side = side - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function move_forward()
|
||||||
|
rc, desc = turtle.forward()
|
||||||
|
if not rc then abort("Move: "..desc) end
|
||||||
|
_count_move_dir(facing)
|
||||||
|
_dump_pos()
|
||||||
|
end
|
||||||
|
function move_back()
|
||||||
|
rc, desc = turtle.back()
|
||||||
|
if not rc then abort("Move: "..desc) end
|
||||||
|
_count_move_dir(facing + 2)
|
||||||
|
_dump_pos()
|
||||||
|
end
|
||||||
|
function move_up()
|
||||||
|
rc, desc = turtle.up()
|
||||||
|
if not rc then abort("Move: "..desc) end
|
||||||
|
height = height + 1
|
||||||
|
_dump_pos()
|
||||||
|
end
|
||||||
|
function move_down()
|
||||||
|
rc, desc = turtle.down()
|
||||||
|
if not rc then abort("Move: "..desc) end
|
||||||
|
height = height - 1
|
||||||
|
_dump_pos()
|
||||||
|
end
|
||||||
|
|
||||||
function go_to_depth(dd)
|
function go_to_depth(dd)
|
||||||
turn_abs(0)
|
turn_abs(0)
|
||||||
while depth > dd do
|
while depth > dd do
|
||||||
turtle.back()
|
move_back()
|
||||||
depth = depth - 1
|
|
||||||
end
|
end
|
||||||
while depth < dd do
|
while depth < dd do
|
||||||
turtle.forward()
|
move_forward()
|
||||||
depth = depth + 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -70,12 +108,10 @@ function go_to(dh, dd, ds)
|
||||||
|
|
||||||
if height ~= dh then
|
if height ~= dh then
|
||||||
while height > dh do
|
while height > dh do
|
||||||
turtle.down()
|
move_down()
|
||||||
height = height - 1
|
|
||||||
end
|
end
|
||||||
while height < dh do
|
while height < dh do
|
||||||
turtle.up()
|
move_up()
|
||||||
height = height + 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -83,12 +119,10 @@ function go_to(dh, dd, ds)
|
||||||
turn_abs(1)
|
turn_abs(1)
|
||||||
|
|
||||||
while side > ds do
|
while side > ds do
|
||||||
turtle.back()
|
move_back()
|
||||||
side = side - 1
|
|
||||||
end
|
end
|
||||||
while side < ds do
|
while side < ds do
|
||||||
turtle.forward()
|
move_forward()
|
||||||
side = side + 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -138,7 +172,6 @@ function find_next_shaft()
|
||||||
go_to(0, 0, 0)
|
go_to(0, 0, 0)
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
print("Climb")
|
|
||||||
for hei=1,MAX_HEIGHT-1 do
|
for hei=1,MAX_HEIGHT-1 do
|
||||||
if (hei % 3) == 0 then
|
if (hei % 3) == 0 then
|
||||||
if turtle.detect() then
|
if turtle.detect() then
|
||||||
|
@ -149,8 +182,7 @@ function find_next_shaft()
|
||||||
if turtle.detectUp() then
|
if turtle.detectUp() then
|
||||||
turtle.digUp()
|
turtle.digUp()
|
||||||
end
|
end
|
||||||
if not turtle.up() then abort("Misshaped lobby") end
|
move_up()
|
||||||
height = height + 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
turn_abs(1)
|
turn_abs(1)
|
||||||
|
@ -158,12 +190,10 @@ function find_next_shaft()
|
||||||
if turtle.detect() then
|
if turtle.detect() then
|
||||||
turtle.dig()
|
turtle.dig()
|
||||||
end
|
end
|
||||||
if not turtle.forward() then abort("Misshaped lobby") end
|
move_forward()
|
||||||
side = side + 1
|
|
||||||
end
|
end
|
||||||
turn_abs(0)
|
turn_abs(0)
|
||||||
|
|
||||||
print("Down")
|
|
||||||
for hei=MAX_HEIGHT-1,0,-1 do
|
for hei=MAX_HEIGHT-1,0,-1 do
|
||||||
if (hei % 3) ~= 0 then
|
if (hei % 3) ~= 0 then
|
||||||
if turtle.detect() then
|
if turtle.detect() then
|
||||||
|
@ -174,8 +204,7 @@ function find_next_shaft()
|
||||||
if turtle.detectDown() then
|
if turtle.detectDown() then
|
||||||
turtle.digDown()
|
turtle.digDown()
|
||||||
end
|
end
|
||||||
if not turtle.down() then abort("Misshaped lobby") end
|
move_down()
|
||||||
height = height - 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
turn_abs(1)
|
turn_abs(1)
|
||||||
|
@ -183,8 +212,7 @@ function find_next_shaft()
|
||||||
if turtle.detect() then
|
if turtle.detect() then
|
||||||
turtle.dig()
|
turtle.dig()
|
||||||
end
|
end
|
||||||
if not turtle.forward() then abort("Misshaped lobby") end
|
move_forward()
|
||||||
side = side + 1
|
|
||||||
end
|
end
|
||||||
turn_abs(0)
|
turn_abs(0)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue