init
This commit is contained in:
commit
12ffbdc45d
76 changed files with 79368 additions and 0 deletions
40
computer/3/pathfinding2.lua
Normal file
40
computer/3/pathfinding2.lua
Normal file
|
@ -0,0 +1,40 @@
|
|||
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
|
||||
elseif vec:dot(facing) < 0 then
|
||||
if turtle.back() 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}
|
Loading…
Add table
Add a link
Reference in a new issue