init
This commit is contained in:
commit
12ffbdc45d
76 changed files with 79368 additions and 0 deletions
113
disk/0/pf
Normal file
113
disk/0/pf
Normal file
|
@ -0,0 +1,113 @@
|
|||
home = vector.new(-250, 96, 108)
|
||||
up = vector.new(0,1,0)
|
||||
south = vector.new(0,0,1)
|
||||
east = vector.new(1,0,0)
|
||||
function greedystep(target)
|
||||
if (target-position):dot(facing) > 0 then
|
||||
if turtle.forward() then
|
||||
position = position + facing
|
||||
elseif position + facing ==target then
|
||||
return false, "the target is occupied"
|
||||
else
|
||||
|
||||
|
||||
temp = (target-position):dot(facing:cross(up))
|
||||
if temp>0 then
|
||||
turtle.turnRight()
|
||||
facing = facing:cross(up)
|
||||
elseif temp<0 then
|
||||
turtle.turnLeft()
|
||||
facing = - facing:cross(up)
|
||||
else
|
||||
temp = (target-position):dot(up)
|
||||
if temp>0 then
|
||||
if turtle.up() then
|
||||
position = position+up
|
||||
end
|
||||
elseif temp<0 then
|
||||
if turtle.down() then
|
||||
position = position-up
|
||||
end
|
||||
else
|
||||
error("help me im stuck")
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
--we did not need to move in that direction
|
||||
temp = (target-position):dot(facing:cross(up))
|
||||
if temp > 0 then
|
||||
turtle.turnRight()
|
||||
facing=facing:cross(up)
|
||||
elseif temp < 0 then
|
||||
turtle.turnLeft()
|
||||
facing=facing:cross(-up)
|
||||
else
|
||||
if (target-position):dot(facing) == 0 then
|
||||
temp = (target-position):dot(up)
|
||||
if temp == 0 then
|
||||
return false,"the target has been reached"
|
||||
else
|
||||
if temp > 0 then
|
||||
if turtle.up() then
|
||||
position:add(up)
|
||||
else
|
||||
position.sub(up)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
-- print(position,facing)
|
||||
_G.position = position
|
||||
_G.facing = facing
|
||||
return true
|
||||
end
|
||||
greedystep = require("pathfinding2").greedystep
|
||||
function to(target)
|
||||
print(tostring(target))
|
||||
while greedystep(target) do
|
||||
end
|
||||
end
|
||||
function returnhome()
|
||||
to(home)
|
||||
if facing == south then
|
||||
turtle.turnRight()
|
||||
facing=facing:cross(up)
|
||||
end
|
||||
if facing == east then
|
||||
turtle.turnLeft()
|
||||
facing=facing:cross(-up)
|
||||
end
|
||||
if facing == -south then
|
||||
turtle.turnLeft()
|
||||
facing=facing:cross(-up)
|
||||
end
|
||||
_G.facing = facing
|
||||
_G.position = position
|
||||
end
|
||||
function lookat(target)
|
||||
print("lookat")
|
||||
while (position+facing).x ~= target.x
|
||||
or (position+facing).z ~= target.z do
|
||||
greedystep(target)
|
||||
end
|
||||
print("temp")
|
||||
temp = target.y-position.y
|
||||
while target.y > position.y do
|
||||
turtle.up()
|
||||
position = position+up
|
||||
end
|
||||
while target.y < position.y do
|
||||
turtle.down()
|
||||
position = position-up
|
||||
end
|
||||
_G.position = position
|
||||
end
|
||||
return {to = to,
|
||||
returnHome=returnhome,
|
||||
lookat = lookat,
|
||||
home = home}
|
Loading…
Add table
Add a link
Reference in a new issue