Advertisement
Guest User

navigation_short

a guest
Mar 17th, 2017
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.75 KB | None | 0 0
  1. local rbt=component.proxy(component.list("robot")())
  2. local ns,nx,ny,nz,rm,rt,ma=0,0,0,0,rbt.move,rbt.turn,math.abs
  3. function id(a,b) return math.floor(a/b) end
  4. function n_u() if rm(1) then nz=nz+1 end end
  5. function n_d() if rm(0) then nz=nz-1 end end
  6. function n_f() if rm(3) then nx,ny=nx+(1-ns%2)*(1-2*id(ns,2)),ny+(ns%2)*(1-2*id(ns,2)) end end
  7. function n_r() rt(true); ns=(ns+1)%4 end
  8. function n_l() rt(false); ns=(ns+3)%4 end
  9. function t_t(is) local tf=n_l; if ((is-ns)+4)%4<2 then tf=n_r end while(ns~=is) do n_l() end end
  10. function n_t(x,y,z)
  11. local fz,dz,sx,dx,sy,dy=n_d,ma(z-nz),2,ma(x-nx),3,ma(y-ny)
  12. if z>nz then fz=n_u end
  13. for i=1,dz,1 do fz() end
  14. if x>nx then sx=0 end
  15. t_t(sx)
  16. for i=1,dx,1 do n_f() end
  17. if y>ny then sy=1 end
  18. t_t(sy)
  19. for i=1,dy,1 do n_f() end
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement