HappySunChild

SequenceMining

Sep 11th, 2021 (edited)
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.71 KB | None | 0 0
  1. local Sequence = ""
  2. local i = 1
  3.  
  4. local function resetTerm()
  5.     term.clear()
  6.     term.setCursorPos(1,1)
  7. end
  8.  
  9. local function Split(inputstr,sep)
  10.     if sep == nil then
  11.         sep = "%s"
  12.     end
  13.    
  14.     local t={}
  15.     for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  16.         table.insert(t, str)
  17.     end
  18.     return t
  19. end
  20.  
  21. resetTerm()
  22.  
  23. local function CheckType(str) -- basic interpreter
  24.     local funcStr = ""
  25.     local f = Split(str)[1]
  26.     local n = Split(str)[2]
  27.     local g = Split(str)[3]
  28.     local o = Split(str)[4]
  29.  
  30.     if f == "mf" or f == "f" then
  31.         funcStr = "while turtle.detect() do turtle.dig() end turtle.forward()\n"
  32.     elseif f == "mb" or f == "b" then
  33.         funcStr = "turtle.back()"
  34.     elseif f == "mu" or f == "u" then
  35.         funcStr = "if turtle.detectUp() then turtle.digUp() end turtle.up()\n"
  36.     elseif f == "md" or f == "d" then
  37.         funcStr = "if turtle.detectDown() then turtle.digDown() end turtle.down()\n"
  38.     end
  39.  
  40.     if f == "dig" or f == "ds" then
  41.         funcStr = "turtle.dig()\n"
  42.     elseif f == "digup" or f == "du" then
  43.         funcStr = "turtle.digUp()\n"
  44.     elseif f == "digdown" or f == "dd" then
  45.         funcStr = "turtle.digDown()\n"
  46.     end
  47.  
  48.     if f == "180" then
  49.         funcStr = "turtle.turnRight() turtle.turnRight()\n"
  50.     end
  51.  
  52.     if f == "l" or f == "left" then
  53.         funcStr = "turtle.turnLeft()\n"
  54.     elseif f == "r" or f == "right" then
  55.         funcStr = "turtle.turnRight()\n"
  56.     end
  57.  
  58.     if f == "select" or f == "s" then
  59.         funcStr = "turtle.select("..n..")\n"
  60.     end
  61.  
  62.     if f == "place" or f == "p" then
  63.         funcStr = "turtle.place()\n"
  64.     elseif f == "placeup" or f == "pu" then
  65.         funcStr = "turtle.placeUp()\n"
  66.     elseif f == "placedown" or f == "pd" then
  67.         funcStr = "turtle.placeDown()\n"
  68.     end
  69.  
  70.     if f == "loop" or f == "for" then
  71.         funcStr = "for i = 1,"..n.." do\n"
  72.     end
  73.     if f == "end" or f == "endloop" or f == "endfor" then
  74.         funcStr = "end\n"
  75.     end
  76.  
  77.     if f == "refuel" then
  78.         funcStr = "turtle.refuel()\n"
  79.     end
  80.  
  81.     if f == "print" then
  82.         funcStr = "print(" .. n .. ")"
  83.     end
  84.  
  85.     if f == "break" then
  86.         funcStr = "break\n"
  87.     end
  88.  
  89.     if f == "if" then
  90.         if n == "detect" then
  91.             funcStr = "if turtle.detect() then\n"
  92.         elseif n == "detectUp" then
  93.             funcStr = "if turtle.detectUp() then\n"
  94.         elseif n == "detectDown" then
  95.             funcStr = "if turtle.detectDown() then\n"
  96.         elseif n == "inspect" then
  97.             local line = "has_block, data = turtle.inspect()\n"
  98.             local ifline = "if data.name == " .. g .. " then\n"
  99.             funcStr = line .. ifline
  100.         elseif n == "inspectUp" then
  101.             local line = "has_block, data = turtle.inspectUp()\n"
  102.             local ifline = "if data.name == " .. g .. " then\n"
  103.             funcStr = line .. ifline
  104.         elseif n == "inspectDown" then
  105.             local line = "has_block, data = turtle.inspectUp()\n"
  106.             local ifline = "if data.name == " .. g .. " then\n"
  107.             funcStr = line .. ifline
  108.         end
  109.     end
  110.  
  111.     return funcStr
  112. end
  113.  
  114. while true do
  115.     term.write("Instruction " .. i .. ": ")
  116.    
  117.     local r = read()
  118.    
  119.     if r == "go" then -- set off
  120.         break
  121.     elseif r == "restart" then
  122.         Sequence = ""
  123.         i = 1
  124.         resetTerm()
  125.     end
  126.    
  127.     local func = CheckType(r)
  128.  
  129.     if func then
  130.         Sequence = Sequence .. func
  131.         i = i + 1
  132.     end
  133. end
  134.  
  135. term.setCursorPos(1,1)
  136. term.clear()
  137.  
  138. print("Running Sequence")
  139.  
  140. local file = fs.open("smResult",'w')
  141. file.write(Sequence)
  142. file.close()
  143.  
  144. loadstring(Sequence)()
Add Comment
Please, Sign In to add comment