Advertisement
markman4897

#OC traveler

Oct 26th, 2015
111
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None
  1. local r = require("robot")
  2.  
  3. -- functions part
  4. function move(dir, times)
  5.   if dir == "f" then
  6.     for i=1,times do
  7.       r.forward()
  8.     end
  9.   elseif dir == "b" then
  10.     for i=1,times do
  11.       r.back()
  12.     end
  13.   elseif dir == "u" then
  14.     for i=1,times do
  15.       r.up()
  16.     end
  17.   elseif dir == "d" then
  18.     for i=1,times do
  19.       r.down()
  20.     end
  21.   elseif dir == "l" then
  22.     r.turnLeft()
  23.   elseif dir == "r" then
  24.     r.turnRight()
  25.   elseif dir == nil then
  26.     print("You added ',' after the final move.")
  27.   else
  28.     print("Error in input!")
  29.     os.exit()
  30.   end
  31. end
  32.  
  33. function convert(inp)
  34.   t = {}
  35.   c = 1
  36.   for s, e in (inp..","):gmatch("(.)(.?.?),") do
  37.     t[c] = {}
  38.     t[c][1] = s
  39.     t[c][2] = e
  40.     c = c + 1
  41.   end
  42.   return t
  43. end
  44.  
  45. function parse(inp)
  46.   for i=1,#inp do
  47.     move(inp[i][1], inp[i][2])
  48.   end
  49. end
  50.  
  51. -- work part
  52. path = "f1,d2,f1,r,f10,l,f3,d3,l,f3,d3,r,f5,r"
  53. parse(convert(path))
Advertisement
RAW Paste Data Copied
Advertisement