35 lines
859 B
Lua
35 lines
859 B
Lua
up = vector.new(0,1,0)
|
|
function greedystep(target)
|
|
--rednet.broadcast(position)
|
|
vec = target-position
|
|
if target == position then
|
|
return false
|
|
end
|
|
if vec.y > 0 then
|
|
if turtle.up() then
|
|
_G.position = position + up
|
|
return true
|
|
end
|
|
elseif vec.y < 0 then
|
|
if turtle.down() then
|
|
_G.position = position - up
|
|
return true
|
|
end
|
|
end
|
|
if vec:dot(facing) > 0 then
|
|
if turtle.forward() then
|
|
_G.position = position + facing
|
|
return true
|
|
end
|
|
end
|
|
if vec:dot(facing:cross(up)) > 0 then
|
|
turtle.turnRight()
|
|
_G.facing = facing:cross(up)
|
|
return true
|
|
else
|
|
turtle.turnLeft()
|
|
_G.facing = - facing:cross(up)
|
|
return true
|
|
end
|
|
end
|
|
return {greedystep = greedystep}
|