Compare commits

..

1 commit

Author SHA1 Message Date
Théophile Bastian 325cd5c7f3 Mine: write movement functions 2020-08-18 19:44:23 +02:00

View file

@ -51,6 +51,11 @@ function turn_rel(dir)
turn_abs((facing + dir) % 4)
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
@ -65,21 +70,25 @@ 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)
@ -163,7 +172,6 @@ function find_next_shaft()
go_to(0, 0, 0)
while true do
print("Climb")
for hei=1,MAX_HEIGHT-1 do
if (hei % 3) == 0 then
if turtle.detect() then
@ -186,7 +194,6 @@ function find_next_shaft()
end
turn_abs(0)
print("Down")
for hei=MAX_HEIGHT-1,0,-1 do
if (hei % 3) ~= 0 then
if turtle.detect() then