Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- in early development
- local tun_number=1
- local num_black_list=4;
- local num_white_list=4;
- local reportArray={}
- local depth=0;
- local inventory_cur={};
- local inventory_prv={};
- local reserve_slot=0;
- local max_nesting =5
- local function nothing()
- end
- local function turnAround()
- turtle.turnLeft();turtle.turnLeft()
- end
- local maskOff=1;
- local mfFunc=2;
- local digFunc=3;
- local mrFunc=4;
- local tfFunc=5;
- local trFunc=6;
- local detFunc=7;
- local rmaskVal=8;
- function bullyForward()
- while not turtle.forward() do turtle.dig() end
- return true
- end
- function bullyUp()
- while not turtle.up() do turtle.digUp() end
- return true
- end
- local dirnames={"forward","up","down","left","right","back"}
- local funcar=
- {-- 1 mask 2 move 3dig 4 reverse 5 turn 6 revturn 7 detect
- {1 , bullyForward, turtle.dig, turtle.back, nothing, nothing, turtle.detect, 31},
- {2 , bullyUp, turtle.digUp, turtle.down, nothing, nothing, turtle.detectUp, 31-4},
- {4 , turtle.down, turtle.digDown, turtle.up, nothing, nothing, turtle.detectDown, 31-2},
- {8 , turtle.forward, turtle.dig, turtle.back, turtle.turnLeft, turtle.turnRight, turtle.detect, 31},
- {16,turtle.forward, turtle.dig, turtle.back, turtle.turnRight, turtle.turnLeft, turtle.detect, 31},
- {32,turtle.forward, turtle.dig, turtle.back, turnAround , turnAround, turtle.detect, 31}
- }
- function checkInventory(dump)
- local cnt;
- local lim=0;
- dump = dump or false
- if(dump or turtle.getItemCount(16)==0) then return end
- if(turtle.detectDown()) then turtle.digDown() end
- for i=reserve_slot+1,num_black_list do
- cnt=turtle.getItemCount(i)
- if(cnt>30) then turtle.select(i);turtle.drop(cnt-1) end
- end
- if(reserve_slot==1) then
- turtle.select(reserve_slot)
- turtle.placeDown()
- for i=num_black_list+1 ,num_black_list+num_white_list do
- --for i=num_black_list+1 ,16 do
- cnt=turtle.getItemCount(i)
- if(cnt>0) then turtle.select(i);turtle.dropDown(cnt-1) end
- end
- end
- for i=(num_black_list+num_white_list+1),16 do
- turtle.select(i);turtle.dropDown();
- end
- turtle.select(1)
- if(reserve_slot==1) then turtle.digDown() end
- end
- local function scanInventory(inventory)
- local i;
- for i=1,16 do
- inventory[i]=turtle.getItemCount(i);
- if(inventory[i]==nil) then inventory[i]=0 end;
- end
- end
- local function compareInventory(cur,prv)
- for i=1,16 do
- if cur[i]>prv[i] then
- return i;
- end
- end
- return 0;
- end
- local function copyBackInventory()
- for j=1,16 do inventory_prv[j]=inventory_cur[j] end;
- end
- function reportFind(item)
- print(item," ",tun_number,",",depth)
- end
- function handleBlackList(change)
- if change==0 then return end
- if change==reserve_slot then return end
- if(inventory_cur[change]>32) then
- turtle.select(change)
- turtle.drop(inventory_cur[change]-1);
- inventory_cur[change]=1
- turtle.select(1)
- end
- end
- --[[
- local maskOff=1;
- local digFunc=2;
- local mfFunc=3;
- local mrFunc=4;
- local tfFunc=5;
- local trFunc=6;
- local detFunc=7;
- local funcar=
- --]]
- function dumpFuncAr()
- for i=1,6 do
- write(i.." ")
- for j=1,7 do
- if funcar[i][j]~=nil then write("OK ")else write("Nil ") end
- end
- print("")
- end
- end
- function boreHoleScan2(nesting,mask,lastCh)
- local nest=nesting
- local rmask;
- if mask== nil then
- end
- if(nest >max_nesting) then return end
- checkInventory();
- write(nest,"> ")
- for i=1,6 do
- if bit.band(mask,funcar[i][maskOff])~=0 then
- --print("mask= ",mask ,"turn=", funcar[i][maskOff])
- copyBackInventory()
- funcar[i][tfFunc]()
- while(funcar[i][detFunc]()) do
- dag=funcar[i][digFunc]();
- -- print("detecting ", mask,funcar[i][detFunc]())
- end
- if(dag) then
- --print("scanning inventory")
- scanInventory(inventory_cur)
- --print("finding change in inventory")
- change=compareInventory(inventory_cur,inventory_prv)
- if(change>num_black_list and (nest)< max_nesting) then
- funcar[i][mfFunc]() ;
- --print("recursing in")
- rmask=funcar[i][rmaskVal]
- boreHoleScan2(nest+1,rmask,change);
- funcar[i][mrFunc]();
- else
- --print("black list item maintance")
- handleBlackList(change);
- end
- end
- --print("turning back")
- funcar[i][trFunc]()
- end
- end
- write(nest,"< ")
- end
- function boreHoleMine(length,direction,digdir)
- local change;
- local dag;
- local moved;
- local ms=1;
- if digdir==nil then digdir=1; end
- while ms< 6 and bit.band(digdir,funcar[ms][1])==0 do ms=ms+1 end
- print( "bhm len=",length ,"dir =", direction , "ms= ",ms);
- for i=1,length do
- copyBackInventory()
- while(turtle.detect()) do dag=turtle.dig() ; sleep(0.5) end
- if(dag) then
- scanInventory(inventory_cur)
- change=compareInventory(inventory_cur,inventory_prv)
- end
- moved=false;
- bullyForward()
- depth=depth+ direction;
- --if(change>num_black_list) then reportFind( depth) end
- --boreHoleScan(0)
- boreHoleScan2(0,30,change)
- print("tunnel = ",i)
- end
- end
- local num=0
- local len=0
- local lwl=0;
- local moveMask;
- local ar_dir={1,2,4,8,16,32}
- dumpFuncAr()
- print("number of tunnels?")
- num=tonumber(read())
- print("length of tunnels?")
- len=tonumber(read())
- print("last black list(BL) item(1-16) ?")
- num_black_list=tonumber(read())
- num_white_list=0
- print("recursion depth - should be minimal like 2-3")
- max_nesting=tonumber(read())
- print("is there an ender chest in slot 1 (0=no,1=yes)?")
- reserve_slot=tonumber(read())
- turtle.select(1)
- if(reserve_slot~=0 and reserve_slot~=1) then reserve_slot=1 end
- --print("number of white list items(after BL) ?")
- --num_white_list=tonumber(read())
- write("mining direction ")
- for i=1,6 do write(i.." "..dirnames[i].." ") end
- print(" ?")
- moveMask=tonumber(read())
- if moveMask<1 or moveMask>6 then moveMask=1;print("bad input picked "..dirnames[moveMask]); end
- moveMask=ar_dir[moveMask];
- scanInventory(inventory_cur);
- scanInventory(inventory_prv);
- for i=num_black_list+1,16 do
- if(turtle.getItemCount(i)==0) then break else num_white_list=num_white_list+1; end
- end
- turtle.select(1)
- local dir=1
- num=num+num%2
- for i=1,num do
- boreHoleMine(len,dir,moveMask)
- checkInventory( true )
- if(dir>0) then turtle.turnLeft() else turtle.turnRight(); end
- boreHoleMine(4,dir)
- if(dir>0) then turtle.turnLeft() else turtle.turnRight(); end
- tun_number=tun_number+1
- if(dir>0) then bullyUp() else turtle.digDown();turtle.down(); end
- dir=dir*-1
- end
- --for i=1,reportArray.getn() do print (reportArray[i][0]," ", reportArray[i][1],",",reportArray[i][0]) end
Advertisement
Add Comment
Please, Sign In to add comment