Advertisement
Guest User

analyze

a guest
Apr 6th, 2013
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.60 KB | None | 0 0
  1. local currslot = 1
  2. local princess = 0
  3. local bestDrone = 0
  4. local data=""
  5. local countBees = 0
  6. local beeTable = {}
  7. local currScore = 0
  8.  
  9. s = peripheral.wrap("right")
  10.  
  11. function clearVars()
  12.    currslot = 1
  13.    princess = 0
  14.    bestDrone = 0
  15.    data = ""
  16.    countBees = 0
  17.    currScore = 0
  18. end
  19.  
  20. function regTable()
  21. --   beeTable["Heroic"] = 32
  22. --   beeTable["Industrious"] = 31
  23. --   beeTable["Imperial"] = 30
  24. --   beeTable["Valiant"] = 21
  25. --   beeTable["Unweary"] = 21
  26. --   beeTable["Majestic"] = 20
  27. --   beeTable["Steadfast"] = 11
  28. --   beeTable["Ancient"] = 35
  29. --   beeTable["Prehistoric"] = 30
  30. --   beeTable["Primeval"] = 25
  31.    beeTable["Ancient"] = 20
  32.    beeTable["Diligent"] = 11
  33.    beeTable["Noble"] = 10
  34.    beeTable["Cultivated"] = 6
  35.    beeTable["Common"] = 5
  36.    beeTable["Forest"] = 1
  37.    beeTable["Meadows"] = 1
  38. end  
  39.  
  40. function getBees()
  41.    turtle.select(1)
  42.    for i = 1,6 do
  43.      if turtle.suck() then countBees = countBees + 1 end
  44.    end
  45. end
  46.  
  47. function returnBees()
  48.    turtle.turnRight()
  49.    turtle.turnRight()
  50.    turtle.select(princess)
  51.    s.dropSneaky(1,1)
  52.    turtle.select(bestDrone)
  53.    s.dropSneaky(0,1)
  54. end
  55.  
  56. function ditchCombs()  
  57.    turtle.turnLeft()
  58.    m = peripheral.wrap("front")
  59.    for i = 1,8 do
  60.      turtle.suck()
  61.      while (not m.isBee()) and (turtle.getItemCount(i) > 0) do
  62.         turtle.select(i)
  63.         turtle.drop()
  64.         if not m.isBee() then
  65.            print("Gotta ditch the combs!")
  66.            turtle.suck()
  67.            turtle.dropDown()
  68.            turtle.select(countBees)
  69.            turtle.transferTo(i, 1)
  70.            countBees = countBees - 1
  71.         else
  72.            turtle.suck()
  73.            while turtle.getItemCount(i) > 1 do
  74.               countBees = countBees + 1
  75.               turtle.transferTo(countBees, 1)
  76.            end
  77.            turtle.drop()
  78.         end
  79.       end
  80.    end
  81.    turtle.turnRight()
  82. end
  83.  
  84. function scanBees()
  85.    turtle.turnLeft()
  86.    turtle.turnLeft()
  87.    for i = 1, countBees do
  88.      turtle.select(i)
  89.      turtle.drop()
  90.    end
  91.    print("Waiting on Analyzer for bees...")
  92.    sleep(26)
  93. end
  94.  
  95. function determineBest(slot)
  96.    if beeTable[data["speciesPrimary"]] == nil then
  97.      score = 0
  98.    else
  99.      score = beeTable[data["speciesPrimary"]]
  100.    end
  101.    if beeTable[data["speciesSecondary"]] == nil then
  102.      score = score + 0
  103.    else
  104.      score = score + beeTable[data["speciesSecondary"]]
  105.    end
  106.    print("Current: "..currScore)
  107.    print("NewScore: "..score)
  108.    if(bestDrone == 0) then
  109.      bestDrone = slot
  110.      currScore = score
  111.    else
  112.      if (score > currScore) then
  113.        bestDrone = slot
  114.        currScore = score
  115.      end
  116.    end  
  117. end
  118.  
  119. function analyzeBees()
  120.   for i = 1, countBees do
  121.     turtle.select(i)
  122.     s.suckSneaky(0,1)
  123.     turtle.turnRight()
  124.     turtle.drop()
  125.     m = peripheral.wrap("front")
  126.     data = m.analyze()
  127.     if (data["type"] == "princess") then
  128.       princess = i
  129.       print("Princess = "..i)
  130.     else
  131.       determineBest(i)
  132.     end
  133.     print(data["speciesPrimary"]..":"..data["speciesSecondary"])
  134.     print("BestDrone = "..bestDrone)
  135.     turtle.suck()
  136.     turtle.turnLeft()
  137.     if i ~= countBees then sleep(26) end
  138.    end
  139. end
  140.  
  141.  
  142. function dropExcess()
  143.   for i = 1, 6 do
  144.     turtle.select(i)
  145.     turtle.dropDown()
  146.    end  
  147. end
  148. ------=============================
  149.  
  150. beeTable = {}
  151.  
  152. clearVars()
  153. regTable()
  154.  
  155. while true do
  156.    getBees()
  157.    ditchCombs()
  158.    if (turtle.getItemCount(1) > 0) then
  159.       scanBees()
  160.       analyzeBees()
  161.       returnBees()
  162.       dropExcess()
  163.       clearVars()
  164.    end
  165.    print("Waiting on bees...")
  166.    sleep(60)
  167. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement