Advertisement
SergOmarov

Эффективный робот-кровельщик

Aug 17th, 2015
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.08 KB | None | 0 0
  1. --Эффективный робот кровельщик
  2. --(c) SergOmarov, 2015
  3. local robotc=require("component").robot
  4. local robot=require("robot")
  5. local robot_back=robot.back
  6. local robot_forward=robot.forward
  7. local curslot=robot.select(1)
  8. local function getSize()--функция измерения размером
  9. local h=0
  10. local w=0
  11. local forward=true
  12. local back=true
  13. local function a(functionA)
  14. repeat
  15. back=robot_back()
  16. until back==nil
  17. repeat
  18. forward=robot_forward()
  19. functionA()
  20. until forward==nil
  21. end
  22. a(function()w=w+1 end)
  23. robot.turnRight()
  24. a(function()h=h+1 end)
  25. return w,h
  26.  
  27. end
  28. local W,H=getSize()
  29. H=H-1
  30. local function build()
  31. local turn=true
  32. for i=1,W do
  33. for j=1,H do
  34. robot_back()
  35. robot.place()
  36.  
  37. end
  38. if robot.count(curslot) == 0 then curslot = curslot + 1 end
  39. if robot.count(curslot) == 0 then print("Кончились блоки, Хозяин, закинь") end
  40. robot.select(curslot)
  41. if(i%2==1)then
  42. turn=false
  43. else
  44. turn=true
  45. end
  46. robotc.turn(turn)
  47. robot_back()
  48. robot.place()
  49. robotc.turn(turn)
  50.  
  51. end
  52.  
  53. end
  54. build()
  55. robot.up()
  56. robot.place(0)
  57. ::r::
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement