Advertisement
taoshi

Harvest

Jan 21st, 2022 (edited)
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. --утилита сбора урожая
  2. --поле 11х11
  3. --автор Taoshi
  4. --padtebin for dl dq5NNtEb
  5.  
  6. robot=require('robot')
  7. --попытка движения вперёд
  8. forward=function()
  9.   while robot.forward()~=true do print('ъпЪ!') os.sleep(1) end
  10. end
  11.  
  12. --выгрузка инвентаря
  13. drop=function()
  14.   local inv=robot.inventorySize()
  15.   for f=1, inv do robot.select(f) robot.drop() end
  16. end
  17.  
  18. --основное тело
  19. function doit(s,t)
  20.   if s==nil then s=11 else
  21.     if s%2==0 then s=s-1 end end
  22.   if s==1 then s=3 end
  23.   s=s-1
  24.   if t==nil then t=19 end
  25.   local z,x=s-1,s-1
  26.   local turn,turn1='turnRight','turnLeft'
  27.   forward()
  28.   forward() robot.use()
  29.  
  30.   --обход левой верхней части поля
  31.   for f=1,x do
  32.     for g=1,z do
  33.       forward() robot.use(0)
  34.     end
  35.     robot[turn]() forward() robot[turn]() robot.use()
  36.     turn,turn1=turn1,turn
  37.   end
  38.  
  39.   robot[turn]()
  40.   --обход правого края в 2 клетки шириной
  41.   turn,turn2='turnRight','turnLeft'
  42.   for f=1,s do
  43.     forward() robot.use(0) robot[turn]()
  44.     forward() robot.use(0) robot[turn]()
  45.     turn,turn2=turn2,turn    
  46.   end      
  47.  
  48.   --обход возвратом нижнего ряда поля
  49.   forward() robot.use(0) robot[turn]() robot[turn]()
  50.   for f=1,s do
  51.     forward() robot.use()
  52.   end
  53.  
  54.   robot.turnLeft() forward() drop()
  55.   robot.turnAround() os.sleep(t)
  56. end
  57.  
  58. --самозацикливание. отключить для внешнего вызова
  59. while true do
  60.   doit(11,19)
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement