Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- _____
- -- | ___| _ _ __ ___
- -- | |_ | | | | '_ \ / __|
- -- | _|| |_| | | | | (__
- -- |_| \__,_|_| |_|\___|
- --
- left = function()
- return turtle.turnLeft()
- end
- right = function()
- return turtle.turnRight()
- end
- up = function()
- return turtle.up()
- end
- down = function()
- return turtle.down()
- end
- back = function()
- return turtle.back()
- end
- go = function()
- return turtle.forward()
- end
- fuel = function()
- return turtle.getFuelLevel()
- end
- select = function(id)
- return turtle.select(id)
- end
- count = function(id)
- return turtle.getItemCount(id)
- end
- move = function(id, nb)
- return turtle.transferTo(id, nb)
- end
- function testFuel()
- if(fuel() < 16)then
- print('Plus de coco, test de refuel')
- if(count(15) == 0)then
- return false
- end
- select(15)
- turtle.refuel(1)
- end
- if(count(15) == 0)then
- return false
- end
- return true
- end
- function videInv(move)
- if(count(1)>1)then
- turtle.select(1)
- if(turtle.dropDown(count(1)-1)==false)then
- return false
- end
- end
- for m = 2,14 do
- if(count(m)>0)then
- turtle.select(m)
- if(turtle.dropDown()==false)then
- return false
- end
- end
- end
- select(1)
- return true
- end
- function init()
- if(count(1) == 0)then
- print("Pas de seed en slot 1 ? ^^' exit.")
- return false
- end
- if(count(15) == 0)then
- print("Pas de fuel en reserve en slot 15 ? :/ ok..")
- end
- if(count(16) == 0)then
- print("Besoin du bloc sur l'eau en slot 16(lilipad ? autre ?) exit.")
- return false
- end
- if(turtle.detectDown()==false)then
- print("Besoin d'un coffre en dessou. exit.")
- return false
- end
- return true
- end
- function CheckMyTable(x, y)
- if(Cpt == 0)then
- return false
- end
- l=0
- local checkstop = false
- while(checkstop == false)do
- if(""..MyTable0[l] == ""..x and ""..MyTable1[l] == ""..y)then
- --print('return true')
- return true
- end
- if(l > Cpt-2)then
- checkstop = true
- else
- l=l+1
- end
- end
- --print('return false')
- return false
- end
- function test()
- if(turtle.detectDown()==true)then
- select(16)
- if(turtle.compareDown()==false)then
- select(1)
- turtle.digDown()
- if(count(1)==0)then
- print("J'ai pas u de graine, je peux pas replenté , je rentre.")
- goHome()
- return false
- end
- turtle.placeDown()
- end
- return true
- else
- return false
- end
- end
- function whaitGo(k)
- if(k> 60)then
- return false
- end
- if(go()==false)then
- sleep(2)
- return whaitGo(k+1)
- end
- return true
- end
- function whaitBack(j)
- if(j> 60)then
- return false
- end
- if(back()==false)then
- sleep(2)
- return whaitBack(j+1)
- end
- return true
- end
- function testLeft(testLeftFlag)
- if(testLeftFlag ~= 1)then -- Si = 1 ne pas prendre en compte si la case est visitée
- testLeftFlag = 0
- end
- if(testLeftFlag == 0)then
- if(Dir == "+y")then
- FlagLeft = CheckMyTable(NowPos[0]-1, NowPos[1])
- elseif(Dir == "+x")then
- FlagLeft = CheckMyTable(NowPos[0], NowPos[1]+1)
- elseif(Dir == "-y")then
- FlagLeft = CheckMyTable(NowPos[0]+1, NowPos[1])
- elseif(Dir == "-x")then
- FlagLeft = CheckMyTable(NowPos[0], NowPos[1]-1)
- end
- else
- FlagLeft = false
- end
- if(FlagLeft==true)then -- si elle est visite
- return false
- else
- left()
- if(whaitGo(0)==false)then
- print('Pas pus avance , exit')
- stop=true
- return false
- end
- if(turtle.detectDown()==true)then
- if(Dir == "+y")then
- newDir = "-x"
- NowPos[0] = NowPos[0]-1
- elseif(Dir == "+x")then
- newDir = "+y"
- NowPos[1] = NowPos[1]+1
- elseif(Dir == "-y")then
- newDir = "+x"
- NowPos[0] = NowPos[0]+1
- elseif(Dir == "-x")then
- newDir = "-y"
- NowPos[1] = NowPos[1]-1
- end
- Dir = newDir
- print("end left x"..NowPos[0].." y"..NowPos[1].." dir:"..Dir)
- return true
- else
- print("end left (false) x"..NowPos[0].." y"..NowPos[1].." dir:"..Dir)
- if(whaitBack(0)==false)then
- print('Pas pus recule , exit')
- stop=true
- return false
- end
- right()
- return false
- end
- end
- end
- function testRight(testRightFlag)
- if(testRightFlag ~= 1)then -- Si = 1 ne pas prendre en compte si la case est visitée
- testRightFlag = 0
- end
- if(testRightFlag == 0)then
- if(Dir == "+y")then
- FlagRight = CheckMyTable(NowPos[0]+1, NowPos[1])
- elseif(Dir == "+x")then
- FlagRight = CheckMyTable(NowPos[0], NowPos[1]-1)
- elseif(Dir == "-y")then
- FlagRight = CheckMyTable(NowPos[0]-1, NowPos[1])
- elseif(Dir == "-x")then
- FlagRight = CheckMyTable(NowPos[0], NowPos[1]+1)
- end
- else
- FlagRight = false
- end
- if(FlagRight==true)then -- si elle est visite
- return false
- else
- right()
- if(whaitGo(0)==false)then
- print('Pas pus avance , exit')
- stop=true
- return false
- end
- if(turtle.detectDown()==true)then
- if(Dir == "+y")then
- newDir = "+x"
- NowPos[0] = NowPos[0]+1
- elseif(Dir == "+x")then
- newDir = "-y"
- NowPos[1] = NowPos[1]-1
- elseif(Dir == "-y")then
- newDir = "-x"
- NowPos[0] = NowPos[0]-1
- elseif(Dir == "-x")then
- newDir = "+y"
- NowPos[1] = NowPos[1]+1
- end
- Dir = newDir
- print("end right x"..NowPos[0].." y"..NowPos[1].." dir:"..Dir)
- return true
- else
- print("end right (false) x"..NowPos[0].." y"..NowPos[1].." dir:"..Dir)
- if(whaitBack(0)==false)then
- print('Pas pus recule , exit')
- stop=true
- return false
- end
- left()
- return false
- end
- end
- end
- function testGo(testGoFlag)
- if(testGoFlag ~= 1)then -- Si = 1 ne pas prendre en compte si la case est visitée
- testGoFlag = 0
- end
- if(testGoFlag == 0)then
- if(Dir == "+y")then
- FlagGo = CheckMyTable(NowPos[0], NowPos[1]+1)
- elseif(Dir == "+x")then
- FlagGo = CheckMyTable(NowPos[0]+1, NowPos[1])
- elseif(Dir == "-y")then
- FlagGo = CheckMyTable(NowPos[0], NowPos[1]-1)
- elseif(Dir == "-x")then
- FlagGo = CheckMyTable(NowPos[0]-1, NowPos[1])
- end
- else
- FlagGo = false
- end
- if(FlagGo==true)then -- si elle est visite
- return false
- else
- if(whaitGo(0)==false)then
- print('Pas pus avance , exit')
- stop=true
- return false
- end
- if(turtle.detectDown()==true)then
- if(Dir == "+y")then
- NowPos[1] = NowPos[1]+1
- elseif(Dir == "+x")then
- NowPos[0] = NowPos[0]+1
- elseif(Dir == "-y")then
- NowPos[1] = NowPos[1]-1
- elseif(Dir == "-x")then
- NowPos[0] = NowPos[0]-1
- end
- print("end go x"..NowPos[0].." y"..NowPos[1].." dir:"..Dir)
- return true
- else
- print("end go (back) x"..NowPos[0].." y"..NowPos[1].." dir:"..Dir)
- if(whaitBack(0)==false)then
- print('Pas pus recule , exit')
- stop=true
- return false
- end
- return false
- end
- end
- end
- function demisTour()
- left()
- left()
- if(whaitGo(0)==false)then
- return false
- else
- if(Dir == "+y")then
- newDir = "-y"
- NowPos[1] = NowPos[1]-1
- elseif(Dir == "+x")then
- newDir = "-x"
- NowPos[0] = NowPos[0]-1
- elseif(Dir == "-y")then
- newDir = "+y"
- NowPos[1] = NowPos[1]+1
- elseif(Dir == "-x")then
- newDir = "+x"
- NowPos[0] = NowPos[0]+1
- end
- Dir = newDir
- print("end demi tour x"..NowPos[0].." y"..NowPos[1].." dir:"..Dir)
- end
- end
- -- __ __ _ ____
- -- | \/ | __ _(_)_ __ / /\ \
- -- | |\/| |/ _` | | '_ \| | | |
- -- | | | | (_| | | | | | | | |
- -- |_| |_|\__,_|_|_| |_| | | |
- -- \_\/_/
- args = { ... }
- if( args[1]==null)then
- args[1] = 16
- --print("Début de 'tree', par defaut, "..args[1].." blocks")
- else
- --print("Début de 'tree', "..args[1].." blocks")
- end
- stop=false
- if(init()==false) then
- stop=true
- else
- if(whaitGo(0)==false)then
- stop=true
- end
- if(whaitGo(0)==false)then
- stop=true
- end
- if(turtle.detectDown()==false)then
- print('Il est ou ton champ ? x)')
- back()
- back()
- stop=true
- end
- end
- NowPos = {}
- NowPos[0] = 0
- NowPos[1] = 0
- NewPos0 = NowPos[0]
- NewPos1 = NowPos[1]
- MyTable0 = {}
- MyTable1 = {}
- Cpt = 0
- Dir = "+y"
- FlagVisited = false
- LastVisited = false
- while(stop==false)do
- for i=0, Cpt-1 do
- --print("["..i.."][0]="..MyTable0[i].." [1]="..MyTable1[i])
- end
- if(CheckMyTable(NowPos[0], NowPos[1])==true)then
- --si on a deja visiter cette case
- ------Flagtruk : dé que tu trouve une possition nouvelle tu fait les tests (gauche , tout droit,droite)
- -- si ya le flag truk, et qu'on sort du chant en allant tout droit => go home()
- FlagVisited = true
- print("Je connais cette case : x"..NowPos[0].." y"..NowPos[1])
- else
- FlagVisited = false
- end
- if(FlagVisited == false)then -- si on connais pas la case
- if(LastVisited==false)then -- si on vien d'une case qui etais nouvelle
- if(test()==true)then -- si on est bien a la suite
- print("test()==true 1")
- NewPos0 = NowPos[0]
- NewPos1 = NowPos[1]
- MyTable0[Cpt] = NewPos0
- MyTable1[Cpt] = NewPos1
- Cpt = Cpt+1
- if(testLeft()==false)then
- print("testLeft()==false 1")
- if(testGo()==false)then
- print("testGo()==false1")
- if(testRight()==false)then
- print("testRight()==false1")
- if(testLeft(1)==false)then
- if(testGo(1)==false)then
- if(testRight(1)==false)then
- demisTour()
- end
- end
- end
- end
- end
- end
- else -- Si on est sortis du champs
- print("wtf?")
- if(whaitBack(0)==false)then
- print('Pas pus recule , exit')
- stop=true
- else
- if(testLeft()==false)then
- if(testRight()==false)then
- demisTour()
- end
- end
- end
- end
- else -- si on vien d'une case déja visité
- if(test()==true)then -- si on est bien a la suite
- print("test()==true 2")
- NewPos0 = NowPos[0]
- NewPos1 = NowPos[1]
- MyTable0[Cpt] = NewPos0
- MyTable1[Cpt] = NewPos1
- Cpt = Cpt+1
- if(testLeft()==false)then
- print("testLeft()==false 2")
- if(testGo()==false)then
- print("testGo()==false 2")
- if(testRight()==false)then
- print("testRight()==false 2 (go home)")
- if(testGo(1)==false)then
- if(testLeft(1)==false)then
- if(testRight(1)==false)then
- demisTour()
- end
- end
- end
- end
- end
- end
- else -- Si on est sortis du champs
- goHome()
- end
- end
- else -- si la case est visitée
- if(testLeft()==false)then
- if(testGo()==false)then
- if(testRight()==false)then
- if(testGo(1)==false)then
- if(LastVisited==false)then
- goHome()
- else
- if(testLeft(1)==false)then
- if(testRight(1)==false)then
- demisTour()
- end
- end
- end
- end
- end
- end
- end
- end
- LastVisited = FlagVisited
- end
- print('End')
- if(fuel() == 0) then
- print('Ya plus de coco mon coco !')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement