Guest User

analyze

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