Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- BeeAnalyzer x
- -- dropping excess drones should retain a few of each needed type
- --
- invmod = peripheral.wrap("right")
- targetedSpecies = ""
- -- the bee graph ---------------------------------------------------------------
- bees = {}
- function addParent(parent, offspring)
- if not bees[parent] then
- bees[parent] = {
- --name = parent,
- score = 0,
- mutateFrom = {}
- }
- end
- end
- function addOffspring(offspring, parentss)
- if bees[offspring] then
- for i, parents in ipairs(parentss) do
- table.insert(bees[offspring].mutateFrom, parents)
- end
- else
- bees[offspring] = {
- score = 0,
- mutateFrom = parentss
- }
- end
- for i, parents in ipairs(parentss) do
- for i, parent in ipairs(parents) do
- addParent(parent, offspring)
- end
- end
- end
- -- produce combinations from 1 or 2 lists
- function choose(list, list2)
- local newList = {}
- if list2 then
- for i = 1, #list2 do
- for j = 1, #list do
- if list[j] ~= list[i] then
- table.insert(newList, {list[j], list2[i]})
- end
- end
- end
- else
- for i = 1, #list do
- for j = i, #list do
- if list[i] ~= list[j] then
- table.insert(newList, {list[i], list[j]})
- end
- end
- end
- end
- return newList
- end
- -- Forestry Bees ---------------------------------------------------------------
- -- Apis Branch
- addOffspring("Common", choose({"Forest", "Meadows", "Modest", "Marbled", "Tropical", "Wintry", "Marshy", "Water", "Rocky", "Embittered", "Unusual", "Mystical", "Sorcerous", "Attuned"}))
- addOffspring("Cultivated", choose({"Common"}, {"Forest", "Meadows", "Modest", "Marbled", "Tropical", "Wintry", "Marshy", "Water", "Rocky", "Embittered", "Unusual", "Mystical", "Sorcerous", "Attuned"}))
- -- Noble Branch
- addOffspring("Noble", {{"Cultivated", "Common"}})
- addOffspring("Majestic", {{"Noble", "Cultivated"}})
- addOffspring("Imperial", {{"Majestic", "Noble"}})
- -- Industrious Branch
- addOffspring("Diligent", {{"Cultivated", "Common"}})
- addOffspring("Unweary", {{"Diligent", "Cultivated"}})
- addOffspring("Industrious", {{"Unweary", "Diligent"}})
- -- Heroic Branch
- addOffspring("Heroic", {{"Steadfast", "Valiant"}})
- -- Infernal Branch
- addOffspring("Sinister", {{"Cultivated", "Modest"}, {"Cultivated", "Tropical"}})
- addOffspring("Fiendish", {{"Sinister", "Cultivated"}, {"Sinister", "Modest"}, {"Sinister", "Tropical"}})
- addOffspring("Demonic", {{"Fiendish", "Sinister"}})
- -- Austere Branch
- addOffspring("Frugal", {{"Sinister", "Modest"}, {"Fiendish", "Modest"}})
- addOffspring("Austere", {{"Frugal", "Modest"}})
- -- Tropical Branch
- addOffspring("Exotic", {{"Austere", "Tropical"}})
- addOffspring("Edenic", {{"Exotic", "Tropical"}})
- -- Frozen Branch
- addOffspring("Icy", {{"Industrious", "Wintry"}})
- addOffspring("Glacial", {{"Icy", "Wintry"}})
- addOffspring("Frigid", {{"Diligent", "Wintry"}})
- addOffspring("Absolute", {{"Frigid", "Ocean"}})
- -- Festive Branch
- addOffspring("Celebratory", {{"Austere", "Excited"}})
- addOffspring("Leporine", {{"Meadows", "Forest"}})
- addOffspring("Merry", {{"Wintry", "Forest"}})
- addOffspring("Tipsy", {{"Wintry", "Meadows"}})
- -- Agrarian Branch
- addOffspring("Rural", {{"Diligent", "Meadows"}})
- addOffspring("Farmed", {{"Rural", "Cultivated"}})
- -- Boggy Branch
- addOffspring("Swamp", {{"Common", "Marshy"}})
- addOffspring("Boggy", {{"Swamp", "Marshy"}})
- addOffspring("Fungal", {{"Boggy", "Swamp"}})
- -- Agricultural Branch
- addOffspring("Fermented", {{"Rural", "Fruity"}})
- addOffspring("Bovine", {{"Rural", "Water"}})
- addOffspring("Caffeine", {{"Rural", "Tropical"}})
- addOffspring("Citrus", {{"Farmed", "Modest"}})
- addOffspring("Minty", {{"Farmed", "Tropical"}})
- -- Barren Branch
- addOffspring("Arid", {{"Meadows", "Modest"}})
- addOffspring("Barren", {{"Arid", "Common"}})
- addOffspring("Desolate", {{"Barren", "Arid"}})
- -- Hostile Branch
- addOffspring("Skeletal", {{"Desolate", "Frugal"}})
- addOffspring("Decaying", {{"Desolate", "Modest"}})
- addOffspring("Creepy", {{"Desolate", "Austere"}})
- -- Rocky Branch
- addOffspring("Tolerant", {{"Diligent", "Rocky"}})
- addOffspring("Hardy", {{"Tolerant", "Rocky"}})
- addOffspring("Resilient", {{"Hardy", "Tolerant"}})
- -- Rusty Branch
- addOffspring("Rusty", {{"Resilient", "Diligent"}})
- addOffspring("Corroded", {{"Resilient", "Diligent"}})
- addOffspring("Tarnished", {{"Resilient", "Diligent"}})
- addOffspring("Leaden", {{"Resilient", "Unweary"}})
- -- Metallic Branch
- addOffspring("Lustered", {{"Resilient", "Unweary"}})
- addOffspring("Galvanized", {{"Tarnished", "Cultivated"}})
- addOffspring("Invincible", {{"Resilient", "Ender"}})
- -- Alloyed Branch
- addOffspring("Impregnable", {{"Resilient", "Noble"}})
- addOffspring("Resolute", {{"Corroded", "Tarnished"}})
- addOffspring("Brazen", {{"Corroded", "Galvanized"}})
- addOffspring("Fortified", {{"Rusty", "Fossiled"}})
- addOffspring("Lustrous", {{"Resilient", "Imperial"}})
- -- Precious Branch
- addOffspring("Shining", {{"Rusty", "Noble"}})
- addOffspring("Glittering", {{"Resolute", "Noble"}})
- addOffspring("Precious", {{"Glittering", "Shining"}})
- addOffspring("Valuable", {{"Glittering", "Ender"}})
- -- Mineral Branch
- addOffspring("Lapis", {{"Resilient", "Water"}})
- addOffspring("Sodalite", {{"Lapis", "Diligent"}})
- addOffspring("Pyrite", {{"Rusty", "Sinister"}})
- addOffspring("Bauxite", {{"Resilient", "Diligent"}})
- addOffspring("Cinnabar", {{"Resilient", "Sinister"}})
- addOffspring("Sphalerite", {{"Tarnished", "Sinister"}})
- -- Gemstone Branch
- addOffspring("Emerald", {{"Lapis", "Noble"}})
- addOffspring("Ruby", {{"Emerald", "Austere"}})
- addOffspring("Sapphire", {{"Emerald", "Ocean"}})
- addOffspring("Olivine", {{"Emerald", "Ender"}})
- addOffspring("Diamond", {{"Sapphire", "Imperial"}})
- -- Nuclear Branch
- addOffspring("Unstable", {{"Austere", "Rocky"}})
- addOffspring("Nuclear", {{"Unstable", "Rusty"}})
- addOffspring("Radioactive", {{"Nuclear", "Glittering"}})
- -- Historic Branch
- addOffspring("Ancient", {{"Noble", "Diligent"}})
- addOffspring("Primeval", {{"Ancient", "Noble"}})
- addOffspring("Prehistoric", {{"Primeval", "Majestic"}})
- addOffspring("Relic", {{"Prehistoric", "Imperial"}})
- -- Fossilized
- addOffspring("Fossiled", {{"Primeval", "Forest"}})
- addOffspring("Oily", {{"Primeval", "Modest"}})
- addOffspring("Preserved", {{"Primeval", "Boggy"}})
- addOffspring("Resinous", {{"Primeval", "Marshy"}})
- -- Refined Branch
- addOffspring("Distilled", {{"Oily", "Industrious"}})
- addOffspring("Refined", {{"Distilled", "Oily"}})
- addOffspring("Elastic", {{"Refined", "Resinous"}})
- addOffspring("Tarry", {{"Refined", "Fossiled"}})
- -- Aquatic Branch
- addOffspring("River", {{"Common", "Water"}})
- addOffspring("Ocean", {{"Common", "Water"}})
- addOffspring("Stained", {{"Ocean", "Water"}})
- -- Saccharine Branch
- addOffspring("Sweetened", {{"Diligent", "Tropical"}})
- addOffspring("Sugary", {{"Sweetened", "Diligent"}})
- addOffspring("Fruity", {{"Sugary", "Forest"}})
- -- Volcanic Branch
- addOffspring("Angry", {{"Sinister", "Embittered"}})
- addOffspring("Furious", {{"Angry", "Embittered"}})
- addOffspring("Volcanic", {{"Furious", "Angry"}})
- addOffspring("Glowering", {{"Excited", "Angry"}})
- -- Viscous Branch
- addOffspring("Viscous", {{"Exotic", "Water"}})
- addOffspring("Glutinous", {{"Viscous", "Exotic"}})
- addOffspring("Sticky", {{"Glutinous", "Viscous"}})
- -- Virulent Branch
- addOffspring("Malicious", {{"Sinister", "Tropical"}})
- addOffspring("Infectious", {{"Malicious", "Tropical"}})
- addOffspring("Virulent", {{"Infectious", "Malicious"}})
- -- Caustic Branch
- addOffspring("Corrosive", {{"Virulent", "Sticky"}})
- addOffspring("Caustic", {{"Corrosive", "Fiendish"}})
- addOffspring("Acidic", {{"Caustic", "Corrosive"}})
- -- Energetic Branch
- addOffspring("Excited", {{"Cultivated", "Valiant"}})
- addOffspring("Energetic", {{"Excited", "Valiant"}})
- addOffspring("Ecstatic", {{"Energetic", "Excited"}})
- -- Shadow Branch
- addOffspring("Shadowed", {{"Rocky", "Furious"}})
- addOffspring("Darkened", {{"Shadowed", "Embittered"}})
- addOffspring("Abyssmal", {{"Darkened", "Shadowed"}})
- -- Primary Branch
- addOffspring("Bleached", {{"Wintry", "Valiant"}})
- addOffspring("Ebony", {{"Rocky", "Valiant"}})
- addOffspring("Maroon", {{"Forest", "Valiant"}})
- addOffspring("Natural", {{"Tropical", "Valiant"}})
- addOffspring("Prussian", {{"Water", "Valiant"}})
- addOffspring("Saffron", {{"Meadows", "Valiant"}})
- addOffspring("Sepia", {{"Marshy", "Valiant"}})
- -- Secondary Branch
- addOffspring("Amber", {{"Maroon", "Saffron"}})
- addOffspring("Azure", {{"Prussian", "Bleached"}})
- addOffspring("Indigo", {{"Maroon", "Prussian"}})
- addOffspring("Lavender", {{"Maroon", "Bleached"}})
- addOffspring("Lime", {{"Natural", "Bleached"}})
- addOffspring("Slate", {{"Ebony", "Bleached"}})
- addOffspring("Turquoise", {{"Natural", "Prussian"}})
- -- Tertiary Branch
- addOffspring("Ashen", {{"Slate", "Bleached"}})
- addOffspring("Fuchsia", {{"Indigo", "Lavender"}})
- -- hungry,confused,forestry,wooden branch
- addOffspring("Hungry", {{"Arid", "Rural"}})
- addOffspring("Starved", {{"Barren", "Hungry"}})
- addOffspring("Ravenous", {{"Hungry", "Starved"}})
- addOffspring("Dazed", {{"Arid", "Edenic"}})
- addOffspring("Irrational", {{"Barren", "Dazed"}})
- addOffspring("Delirious", {{"Dazed", "Irrational"}})
- addOffspring("Pulped", {{"Unweary", "Forest"}})
- addOffspring("Spoiled", {{"Pulped", "Decaying"}})
- addOffspring("Decomposed", {{"Pulped", "Decaying"}})
- addOffspring("Wooden", {{"Diligent", "Forest"}})
- addOffspring("Lumbered", {{"Diligent", "Wooden"}})
- addOffspring("Timbered", {{"Wooden", "Lumbered"}})
- -- Beastly Branch
- addOffspring("Jaded", {{"Ender", "Relic"}})
- -- Magic Bees ------------------------------------------------------------------
- -- Arcane Branch
- addOffspring("Esoteric", {{"Imperial", "Demonic"}, {"Heroic", "Demonic"}})
- addOffspring("Mysterious", {{"Ender", "Esoteric"}})
- addOffspring("Arcane", {{"Mysterious", "Esoteric"}})
- -- Supernatural Branch
- addOffspring("Charmed", {{"Diligent", "Valiant"}})
- addOffspring("Enchanted", {{"Valiant", "Charmed"}})
- addOffspring("Supernatural", {{"Enchanted", "Charmed"}})
- -- Scholarly Branch
- addOffspring("Pupil", {{"Arcane", "Enchanted"}})
- addOffspring("Scholarly", {{"Arcane", "Pupil"}})
- addOffspring("Savant", {{"Scholarly", "Pupil"}})
- -- Thaumic Branch
- addOffspring("Stark", {{"Arcane", "Supernatural"}})
- -- Skulking Branch
- addOffspring("Skulking", {{"Mysterious", "Modest"}, {"Mysterious", "Desolate"}})
- addOffspring("Brainy", {{"Skulking", "Sinister"}})
- addOffspring("Gossamer", {{"Skulking", "Supernatural"}, {"Skulking", "Ancient"}})
- addOffspring("Wispy", {{"Gossamer", "Cultivated"}})
- addOffspring("Batty", {{"Skulking", "Frugal"}, {"Skulking", "Rocky"}})
- addOffspring("Ghastly", {{"Skulking", "Austere"}, {"Skulking", "Creepy"}})
- addOffspring("Aware", {{"Demonic", "Edenic"}})
- addOffspring("Vis", {{"Aware", "Arcane"}, {"Aware", "Stark"}})
- addOffspring("Pure", {{"Vis", "Edenic"}})
- addOffspring("Flux", {{"Vis", "Edenic"}})
- addOffspring("Node", {{"Pure", "Flux"}})
- addOffspring("Rejuvenating", {{"Vis", "Energetic"}})
- addOffspring("Timely", {{"Industrious", "Enchanted"}})
- addOffspring("Lordly", {{"Timely", "Imperial"}})
- addOffspring("Doctoral", {{"Timely", "Lordly"}})
- addOffspring("Spirit", {{"Fiendish", "Enchanted"}, {"Fiendish", "Ender"}})
- addOffspring("Soul", {{"Fiendish", "Spirit"}})
- addOffspring("Minium", {{"Sinister", "Mysterious"}, {"Frugal", "Pupil"}})
- addOffspring("Iron", {{"Industrious", "Diligent"}})
- addOffspring("Gold", {{"Minium", "Lead"}})
- addOffspring("Copper", {{"Industrious", "Meadows"}})
- addOffspring("Tin", {{"Industrious", "Forest"}})
- addOffspring("Silver", {{"Imperial", "Modest"}})
- addOffspring("Lead", {{"Industrious", "Copper"}, {"Industrious", "Tin"}, {"Industrious", "Common"}})
- addOffspring("Diamond", {{"Austere", "Gold"}})
- addOffspring("Emerald", {{"Austere", "Silver"}})
- addOffspring("Poultry", {{"Common", "Skulking"}})
- addOffspring("Beefy", {{"Common", "Skulking"}})
- addOffspring("Porcine", {{"Common", "Skulking"}})
- -- logging ---------------------------------------------------------------------
- local logFile = fs.open("bee.log", "w")
- function log(msg)
- msg = msg or ""
- logFile.write(tostring(msg))
- logFile.flush()
- io.write(msg)
- end
- function logLine(msg)
- msg = msg or ""
- logFile.write(msg.."\n")
- logFile.flush()
- io.write(msg.."\n")
- end
- -- analyzing functions ---------------------------------------------------------
- -- Fix for some versions returning bees.species.*
- function fixName(name)
- return name:gsub("bees%.species%.",""):gsub("^.", string.upper)
- end
- function clearSystem()
- -- orient turtle
- while true do
- local p = peripheral.wrap("front")
- if p and p.isBee then
- break
- end
- turtle.turnRight()
- end
- -- clear out analyzer
- turtle.turnLeft()
- while turtle.suckUp() do end
- -- clear out beealyzer
- turtle.turnRight()
- turtle.suck()
- -- clear out apiary
- turtle.turnRight()
- while turtle.suck() do end
- end
- function getBees()
- -- get bees from apiary
- log("waiting for bees.")
- turtle.select(1)
- while not turtle.suck() do
- sleep(10)
- log(".")
- end
- log("*")
- while turtle.suck() do
- log("*")
- end
- logLine()
- end
- function countBees()
- -- spread dups and fill gaps
- local count = 0
- for i = 1, 16 do
- local slotCount = turtle.getItemCount(i)
- if slotCount == 1 then
- for j = 1, i-1 do
- if turtle.getItemCount(j) == 0 then
- turtle.select(i)
- turtle.transferTo(j)
- break
- end
- end
- count = count + 1
- elseif slotCount > 1 then
- for j = 2, slotCount do
- turtle.select(i)
- for k = 1, 16 do
- if turtle.getItemCount(k) == 0 then
- turtle.transferTo(k, 1)
- end
- end
- end
- if turtle.getItemCount(i) > 1 then
- turtle.dropDown(turtle.getItemCount(i)-1)
- end
- end
- end
- return count
- end
- function breedBees(princessSlot, droneSlot)
- turtle.select(princessSlot)
- invmod.dropSneaky(1)
- turtle.select(droneSlot)
- invmod.dropSneaky(0)
- end
- function ditchProduct()
- print("ditching product...")
- turtle.turnLeft()
- m = peripheral.wrap("front")
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- turtle.drop()
- if not m.isBee() then
- turtle.suck()
- turtle.dropDown()
- else
- turtle.suck()
- end
- end
- end
- turtle.turnRight()
- end
- function scanBees()
- log("scanning bees")
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- log(".")
- turtle.select(i)
- invmod.dropSneakyUp(2)
- while not turtle.suckUp() do
- sleep(1)
- end
- end
- end
- logLine()
- turtle.turnRight()
- turtle.turnRight()
- end
- function swapBee(slot1, slot2, freeSlot)
- turtle.select(slot1)
- turtle.transferTo(freeSlot)
- turtle.select(slot2)
- turtle.transferTo(slot1)
- turtle.select(freeSlot)
- turtle.transferTo(slot2)
- end
- --if princess has no scored offspring (mutated) ... maybewe want to breed with the highest scored drone (droneScore)
- --find the highest drone bee we have, find what we need to breed with it
- --if we have that drone, breed princess with that drone
- --else find the highest we have in that tree, and repeat
- --if we dont have any then exit with needbee: bee (tree)
- --returns which drone is highest parent for species, or species if available
- function findAvailableParent(species, droneData)
- local droneIndex = 0
- local droneScore = 99999
- for i = 2, 16 do
- if droneData[i] then
- if droneData[i]["speciesPrimary"] == species or droneData[i]["speciesSecondary"] == species then
- droneIndex = i
- droneScore = bees[species].score
- return droneIndex, droneScore
- end
- end
- end
- for i, parents in ipairs(bees[species].mutateFrom) do
- index, score = findAvailableParent(parents[1], droneData)
- if score < droneScore then
- droneIndex = index
- droneScore = score
- end
- index, score = findAvailableParent(parents[2], droneData)
- if score < droneScore then
- droneIndex = index
- droneScore = score
- end
- end
- if droneScore == 99999 then
- logLine("Missing bee species: " .. species)
- end
- return droneIndex, droneScore
- end
- function analyzeBees()
- logLine("analyzing bees...")
- local freeSlot
- local princessSlot
- local princessData
- local droneData = {}
- turtle.turnLeft()
- local beealyzer = peripheral.wrap("front")
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- turtle.drop()
- local beeData = beealyzer.analyze()
- turtle.suck()
- if not beeData["speciesPrimary"] then
- print("Bee "..i.." not correctly analyzed")
- else
- beeData["speciesPrimary"] = fixName(beeData["speciesPrimary"])
- beeData["speciesSecondary"] = fixName(beeData["speciesSecondary"])
- if beeData["type"] == "princess" then
- princessData = beeData
- princessSlot = i
- else
- droneData[i] = beeData
- end
- end
- else
- freeSlot = i
- end
- end
- if princessData then
- if princessSlot ~= 1 then
- swapBee(1, princessSlot, freeSlot)
- droneData[princessSlot] = droneData[1]
- droneData[1] = nil
- princessSlot = 1
- end
- -- bubble sort drones
- print("sorting drones...")
- for i = 2, 16 do
- if turtle.getItemCount(i) > 0 and droneData[i] then
- droneData[i].score = scoreBee(princessData, droneData[i])
- for j = i - 1, 2, -1 do
- if droneData[j+1].score > droneData[j].score then
- swapBee(j+1, j, freeSlot)
- droneData[j+1], droneData[j] = droneData[j], droneData[j+1]
- end
- end
- end
- end
- if droneData[2] and droneData[2].score < 1 then
- --no breeding combos found for this princess
- i, j = findAvailableParent(targetedSpecies, droneData)
- if j == 99999 then
- droneData[2].score = 0
- else
- swapBee(2, i, freeSlot)
- droneData[2], droneData[i] = droneData[i], droneData[2]
- end
- end
- printHeader()
- princessData.slot = 1
- printBee(princessData)
- for i = 2, 16 do
- if droneData[i] then
- droneData[i].slot = i
- printBee(droneData[i])
- end
- end
- end
- logLine()
- turtle.turnRight()
- return princessData, droneData
- end
- --if drone score is 9999 return 9999 or 10k for pure
- --find offspring for this combo, return highest scoring offspring ... for each bee, if its cerated from these get its score
- function scoreBee(princessData, droneData)
- local droneSpecies = {droneData["speciesPrimary"], droneData["speciesSecondary"]}
- local princessSpecies = {princessData["speciesPrimary"], princessData["speciesSecondary"]}
- if bees[droneSpecies[1]].score == 9999 and bees[droneSpecies[2]].score == 9999 then
- return 10000
- end
- if bees[droneSpecies[1]].score == 9999 or bees[droneSpecies[2]].score == 9999 then
- return 9999
- end
- local droneScore = 0
- for name, beeData in pairs(bees) do
- if beeData.score > droneScore then
- for i, parents in ipairs(beeData.mutateFrom) do
- if princessSpecies[1] == parents[1] or princessSpecies[2] == parents[1] then
- if droneSpecies[1] == parents[2] and droneSpecies[2] == parents[2] then
- if princessSpecies[1] == princessSpecies[2] then
- droneScore = beeData.score + 2
- else
- droneScore = beeData.score + 1
- end
- break
- end
- if ((droneSpecies[1] == parents[1] and droneSpecies[2] == parents[2]) or (droneSpecies[2] == parents[1] and droneSpecies[1] == parents[2]))
- and ((princessSpecies[1] == parents[1] and princessSpecies[2] == parents[2]) or (princessSpecies[2] == parents[1] and princessSpecies[1] == parents[2])) then
- droneScore = beeData.score + 2
- break
- end
- if droneSpecies[1] == parents[2] or droneSpecies[2] == parents[2] then
- droneScore = beeData.score
- break
- end
- end
- if princessSpecies[1] == parents[2] or princessSpecies[2] == parents[2] then
- if droneSpecies[1] == parents[1] and droneSpecies[2] == parents[1] then
- if princessSpecies[1] == princessSpecies[2] then
- droneScore = beeData.score + 2
- else
- droneScore = beeData.score + 1
- end
- break
- end
- if ((droneSpecies[1] == parents[1] and droneSpecies[2] == parents[2]) or (droneSpecies[2] == parents[1] and droneSpecies[1] == parents[2]))
- and ((princessSpecies[1] == parents[1] and princessSpecies[2] == parents[2]) or (princessSpecies[2] == parents[1] and princessSpecies[1] == parents[2])) then
- droneScore = beeData.score + 2
- break
- end
- if droneSpecies[1] == parents[1] or droneSpecies[2] == parents[1] then
- droneScore = beeData.score
- break
- end
- end
- end
- end
- end
- return droneScore
- end
- function printHeader()
- logLine()
- logLine("typ species f spd d n f c tmp hmd score")
- logLine("-|-|-------|-|---|-|-|-|-|---|---|-----")
- end
- toleranceString = {
- ["NONE"] = " ",
- ["UP_1"] = " +1 ",
- ["UP_2"] = " +2 ",
- ["UP_3"] = " +3 ",
- ["DOWN_1"] = " -1 ",
- ["DOWN_2"] = " -2 ",
- ["DOWN_3"] = " -3 ",
- ["BOTH_1"] = "+-1 ",
- ["BOTH_2"] = "+-2 ",
- ["BOTH_3"] = "+-3 "
- }
- function printBee(beeData)
- log(beeData["slot"] < 10 and beeData["slot"].." " or beeData["slot"])
- if (beeData["type"] == "princess") then
- log("P ")
- else
- log("d ")
- end
- log(beeData["speciesPrimary"]:gsub("bees%.species%.",""):sub(1,3)..":"..beeData["speciesSecondary"]:gsub("bees%.species%.",""):sub(1,3).." ")
- log(tostring(beeData["fertility"]).." ")
- log(beeData["speed"] == 1 and "1.0 " or tostring(beeData["speed"]).." ")
- if beeData["diurnal"] then
- log("d ")
- else
- log(" ")
- end
- if beeData["nocturnal"] then
- log("n ")
- else
- log(" ")
- end
- if beeData["tolerantFlyer"] then
- log("f ")
- else
- log(" ")
- end
- if beeData["caveDwelling"] then
- log("c ")
- else
- log(" ")
- end
- log(toleranceString[beeData["toleranceTemperature"]])
- log(toleranceString[beeData["toleranceHumidity"]])
- if beeData.score then
- logLine(string.format("%5.1d", beeData.score).." ")
- else
- logLine()
- end
- end
- function dropExcess(droneData)
- print("dropping excess...")
- local count = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- count = count + 1
- -- drop drones over 9 to clear space for newly bred bees and product
- if count > 9 then
- turtle.select(i)
- turtle.dropDown()
- count = count - 1
- end
- end
- end
- end
- function isPurebred(princessData, droneData)
- -- check if princess and drone are exactly the same and no chance for mutation
- if princessData["speciesPrimary"] ~= princessData["speciesSecondary"] then
- return false
- end
- for key, value in pairs(princessData) do
- if value ~= droneData[key] and key ~= "territory" and key ~= "type" and key ~= "slot" then
- return false
- end
- end
- return true
- end
- function getUnknown(princessData, droneData)
- -- lists species that are not in the bee graph
- local unknownSpecies = {}
- if not bees[princessData["speciesPrimary"]] then
- table.insert(unknownSpecies, princessData["speciesPrimary"])
- end
- if not bees[princessData["speciesSecondary"]] then
- table.insert(unknownSpecies, princessData["speciesSecondary"])
- end
- for _, beeData in pairs(droneData) do
- if not bees[beeData["speciesPrimary"]] then
- table.insert(unknownSpecies, beeData["speciesPrimary"])
- end
- if not bees[beeData["speciesSecondary"]] then
- table.insert(unknownSpecies, beeData["speciesSecondary"])
- end
- end
- return unknownSpecies
- end
- function scoreBeesIterate(name)
- for i, parents in ipairs(bees[name].mutateFrom) do
- if bees[parents[1]].score < bees[name].score - 4 then
- bees[parents[1]].score = bees[name].score - 4
- scoreBeesIterate(parents[1])
- end
- if bees[parents[2]].score < bees[name].score - 4 then
- bees[parents[2]].score = bees[name].score - 4
- scoreBeesIterate(parents[2])
- end
- end
- end
- -- program begins, read input---------------------------------------------------
- tArgs = { ... }
- if #tArgs > 0 then
- logLine("targeting bee species:")
- for i, target in ipairs(tArgs) do
- targetedSpecies = target
- bees[target].score = 9999
- for name, data in pairs(bees) do
- if data.score > 1 then
- logLine(name .. string.rep(" ", 20-#name), data.score)
- end
- end
- end
- for name, beeData in pairs(bees) do
- if beeData.score == 9999 then
- scoreBeesIterate(name)
- end
- end
- else
- logLine("Usage Bee [species]")
- logFile.close()
- return false
- end
- -- breeding loop ---------------------------------------------------------------
- logLine("Clearing system...")
- clearSystem()
- while true do
- ditchProduct()
- countBees()
- scanBees()
- princessData, droneData = analyzeBees()
- if droneData[2].score == 0 then --analyze failed to find a breeding pair
- break
- end
- if princessData then
- if isPurebred(princessData, droneData[2]) then
- logLine("Bees are purebred")
- turtle.turnRight()
- break
- end
- local unknownSpecies = getUnknown(princessData, droneData)
- if #unknownSpecies > 0 then
- logLine("Please add new species to bee graph:")
- for _, species in ipairs(unknownSpecies) do
- logLine(" "..species)
- end
- turtle.turnRight()
- break
- end
- breedBees(1, 2)
- dropExcess(droneData)
- end
- getBees()
- if redstone.getInput("right") then logLine("Execution ended by user.") break end
- end
- logFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement