G2A Many GEOs
SHARE
TWEET

lib_neko_0.1.1

kssr3951 Sep 28th, 2014 172 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. dofile("lib_turtle_0.2.3");
  2.  
  3. local function digBack()
  4.   local rslt;
  5.   turtle.turnLeft();
  6.   turtle.turnLeft();
  7.   rslt = myDig();
  8.   turtle.turnRight();
  9.   turtle.turnRight();
  10.   return rslt;
  11. end
  12.  
  13. local function dir(name_, fromDir_, compareFunc_, detectFunc_,
  14.                    forwardFunc_, digFunc_, backFunc_, backDigFunc_)
  15.   return
  16.     {
  17.       name        = name_,
  18.       fromDir     = fromDir_,
  19.       compareFunc = compareFunc_,
  20.       detectFunc  = detectFunc_,
  21.       forwardFunc = forwardFunc_,
  22.       digFunc     = digFunc_,
  23.       backFunc    = backFunc_,
  24.       backDigFunc = backDigFunc_,
  25.     };
  26. end
  27.  
  28. local dirInfo = { };
  29. dirInfo[0] = dir("top",    2, turtle.compareUp,   turtle.detectUp,   myUp,      myDigUp,   myDown, myDigDown);
  30. dirInfo[1] = dir("front",  4, turtle.compare,     turtle.detect,     myForward, myDig,     myBack, digBack);
  31. dirInfo[2] = dir("bottom", 0, turtle.compareDown, turtle.detectDown, myDown,    myDigDown, myUp,   myDigUp);
  32. dirInfo[3] = dir("left",   4, turtle.compare,     turtle.detect,     myForward, myDig,     myBack, digBack);
  33. dirInfo[4] = dir("back",   4, turtle.compare,     turtle.detect,     myForward, myDig,     myBack, digBack);
  34. dirInfo[5] = dir("right",  4, turtle.compare,     turtle.detect,     myForward, myDig,     myBack, digBack);
  35.  
  36. local stack = { };
  37.  
  38. local function doCompare(posiFlg, compareFunc, detectFunc, slotAry)
  39.   for i, slot in ipairs(slotAry) do
  40.     turtle.select(slot);
  41.     if compareFunc() then
  42.       return posiFlg;
  43.     end
  44.   end
  45.   if posiFlg then
  46.     return false;
  47.   else
  48.     return detectFunc();
  49.   end
  50. end
  51.  
  52. local function doNekosogi(posiFlg, dirCode, slotAry)
  53.  
  54.   local dcDI = dirInfo[dirCode];
  55.   if not doCompare(posiFlg, dcDI.compareFunc, dcDI.detectFunc, slotAry) then
  56.     return;
  57.   end
  58.   if false == dcDI.digFunc() then
  59.     return;
  60.   end
  61.   dcDI.forwardFunc();
  62.  
  63.   table.insert(stack, { toDir = dirCode, progress = 0 });
  64.   local current = stack[table.maxn(stack)];
  65.    
  66.   while true do
  67.     if 6 <= current.progress then
  68.       turtle.turnLeft();
  69.       if not dirInfo[current.toDir].backDigFunc() then
  70.         error("Since the return path was shut by unbreakable block, turtle cannot move.");
  71.       end
  72.       dirInfo[current.toDir].backFunc();
  73.       table.remove(stack);
  74.  
  75.       current = stack[table.maxn(stack)];
  76.       if nil == current then
  77.         break;
  78.       end
  79.     else
  80.       if 3 <= current.progress then
  81.         turtle.turnLeft();
  82.       end
  83.       local curStaIdx = table.maxn(stack);
  84.       if current.progress ~= dirInfo[current.toDir].fromDir then
  85.         local cpDI = dirInfo[current.progress];
  86.         if doCompare(posiFlg, cpDI.compareFunc, cpDI.detectFunc, slotAry) then
  87.           if cpDI.digFunc() then
  88.             cpDI.forwardFunc();
  89.             table.insert(stack, { toDir = current.progress, progress = 0 });
  90.             current = stack[table.maxn(stack)];
  91.           end
  92.         end
  93.       end
  94.       stack[curStaIdx].progress = stack[curStaIdx].progress + 1;
  95.     end
  96.   end
  97. end
  98.  
  99. -- dirCode : 0(top), 1(front), 2(bottom)
  100. function nekoPosi(dirCode, slotAry)
  101.   doNekosogi(true, dirCode, slotAry);
  102. end
  103.  
  104. -- dirCode : 0(top), 1(front), 2(bottom)
  105. function nekoNega(dirCode, slotAry)
  106.   doNekosogi(false, dirCode, slotAry);
  107. end
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top