Advertisement
Phishphan420

analyze

Aug 21st, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 regTable()
  12.    beeTable["bees.species.industrious"] = 31
  13.    beeTable["bees.species.imperial"] = 30
  14.    beeTable["bees.species.unweary"] = 21
  15.    beeTable["bees.species.majestic"] = 20
  16.    beeTable["bees.species.diligent"] = 12
  17.    beeTable["bees.species.ancient"] = 11
  18.    beeTable["bees.species.noble"] = 10
  19.    beeTable["bees.species.cultivated"] = 6
  20.    beeTable["bees.species.common"] = 5
  21.    beeTable["bees.species.marbled"] = 1
  22.    beeTable["bees.species.forest"] = 1
  23.    beeTable["bees.species.meadows"] = 1
  24. end  
  25.  
  26. function getBees()
  27.    turtle.select(1)
  28.    for i = 1,6 do
  29.      if turtle.suck() then countBees = countBees + 1 end
  30.    end
  31. end
  32.  
  33. function returnBees()
  34.    turtle.turnRight()
  35.    turtle.turnRight()
  36.    turtle.select(princess)
  37.    s.dropSneaky(1,1)
  38.    turtle.select(bestDrone)
  39.    s.dropSneaky(0,1)
  40. end
  41.  
  42. function ditchCombs()  
  43.    turtle.turnLeft()
  44.    m = peripheral.wrap("front")
  45.    for i = 1,8 do
  46.      turtle.suck()
  47.      while (not m.isBee()) and (turtle.getItemCount(i) > 0) do
  48.      turtle.select(i)
  49.      turtle.drop()
  50.      if not m.isBee() then
  51.         print("Gotta ditch the combs!")
  52.         turtle.suck()
  53.         turtle.dropDown()
  54.         turtle.select(countBees)
  55.         turtle.transferTo(i, 1)
  56.         countBees = countBees - 1
  57.      end
  58.    end
  59.    end
  60. end
  61.  
  62. function scanBees()
  63.    turtle.turnLeft()
  64.    for i = 1, countBees do
  65.      turtle.select(i)
  66.      turtle.drop()
  67.    end
  68.    print("Sleeping for a minute while the bee scans")
  69.    sleep(26)
  70. end
  71.  
  72. function determineBest(slot)
  73.    local primScore = (beeTable[data["speciesPrimary"]] ~= nil and beeTable[data["speciesPrimary"]] or 0)
  74.    local secScore = (beeTable[data["speciesSecondary"]] ~= nil and beeTable[data["speciesSecondary"]] or 0)
  75.    score = primScore + secScore
  76.    print("Current: "..currScore)
  77.    if primScore == 0 and secScore == 0 then print("Warning bee species not in registry table! Evalutaing as 0!") end
  78.    print("NewScore: "..score)
  79.    if(bestDrone == 0) then
  80.      bestDrone = slot
  81.      currScore = score
  82.    else
  83.      if (score > currScore) then
  84.        bestDrone = slot
  85.        currScore = score
  86.      end
  87.    end  
  88. end
  89.  
  90. function analyzeBees()
  91.   for i = 1, countBees do
  92.     turtle.select(i)
  93.     s.suckSneaky(0,1)
  94.     turtle.turnRight()
  95.     turtle.drop()
  96.     m = peripheral.wrap("front")
  97.     data = m.analyze()
  98.     if (data["type"] == "princess") then
  99.       princess = i
  100.       print("Princess = "..i)
  101.     else
  102.       determineBest(i)
  103.     end
  104.     print(data["speciesPrimary"]..":"..data["speciesSecondary"])
  105.     print("BestDrone = "..bestDrone)
  106.     turtle.suck()
  107.     turtle.turnLeft()
  108.     if i ~= countBees then sleep(26) end
  109.    end
  110. end
  111.  
  112.  
  113. function dropExcess()
  114.   for i = 1, 16 do
  115.     turtle.select(i)
  116.     turtle.dropDown()
  117.    end  
  118. end
  119.  
  120. function dropDupe()
  121.   for i = 1, countBees do
  122.     turtle.select(i)
  123.     local count = turtle.getItemCount(i)
  124.     if count > 1 then
  125.       print("Dropping excess drones.")
  126.       turtle.dropDown(count - 1)
  127.     end
  128.   end
  129.   turtle.select(1)
  130. end
  131. ------=============================
  132.  
  133. currslot = 1
  134. princess = 0
  135. bestDrone = 0
  136. data=""
  137. countBees = 0
  138. beeTable = {}
  139. currScore = 0
  140.  
  141. regTable()
  142. dropExcess()
  143. getBees()
  144. if (turtle.getItemCount(2) > 0) then
  145.    ditchCombs()
  146.    dropDupe()
  147.    scanBees()
  148.    analyzeBees()
  149.    returnBees()
  150.    dropExcess()
  151. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement