Advertisement
Guest User

Untitled

a guest
May 3rd, 2023
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. local robot = require("robot")
  2.  
  3. local robomove = {}
  4.  
  5. function robomove.forward(x)
  6. if x ~= 0 then
  7. if x > 0 then
  8. for i = 1, x do
  9. robot.forward()
  10. end
  11. else
  12. for i = 1, -x do
  13. robot.back()
  14. end
  15. end
  16. end
  17. end
  18.  
  19. function robomove.back(x)
  20. if x ~= 0 then
  21. if x > 0 then
  22. robot.turnRight()
  23. robot.turnRight()
  24. for i = 1, x do
  25. robot.forward()
  26. end
  27. else
  28. robot.turnLeft()
  29. robot.turnLeft()
  30. for i = 1, -x do
  31. robot.back()
  32. end
  33. end
  34. end
  35. end
  36.  
  37. function robomove.up(x)
  38. if x ~= 0 then
  39. if x > 0 then
  40. for i = 1, x do
  41. robot.up()
  42. end
  43. else
  44. for i = 1, -x do
  45. robot.down()
  46. end
  47. end
  48. end
  49. end
  50.  
  51. function robomove.down(x)
  52. if x ~= 0 then
  53. if x > 0 then
  54. for i = 1, x do
  55. robot.down()
  56. end
  57. else
  58. for i = 1, -x do
  59. robot.up()
  60. end
  61. end
  62. end
  63. end
  64.  
  65. function robomove.right(x)
  66. if x >= 0 then
  67. robot.turnRight()
  68. if x > 0 then
  69. for i = 1, x do
  70. robot.forward()
  71. end
  72. end
  73. else
  74. for i = 1, -x do
  75. robot.back()
  76. end
  77. robo.turnLeft()
  78. end
  79. end
  80.  
  81. function robomove.left(x)
  82. if x >= 0 then
  83. robot.turnLeft()
  84. if x > 0 then
  85. for i = 1, x do
  86. robot.forward()
  87. end
  88. end
  89. else
  90. for i = 1, -x do
  91. robot.back()
  92. end
  93. robo.turnRight()
  94. end
  95. end
  96.  
  97. function robomove.path(m,x)
  98. local movment = {}
  99. movment["f"] = robomove.forward
  100. movment["b"] = robomove.back
  101. movment["u"] = robomove.up
  102. movment["d"] = robomove.down
  103. movment["r"] = robomove.right
  104. movment["l"] = robomove.left
  105.  
  106. movment[m](x)
  107. end
  108.  
  109. return robomove
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement