View difference between Paste ID: LfQiYjp4 and gXa8k1tJ
SHOW: | | - or go back to the newest paste.
1
-- setup is turtle facing apiary, with a (large, maybe dimensional storage) chest beneath the turtle
2
-- another chest on top is used for produce and extra drones
3
4
-- gXa8k1tJ
5
-- fKC8kx5b
6
-- H0CppXue
7
-- QTRQHPhM
8
-- RwTbaqpP
9
10
local apiary = peripheral.wrap("front")
11
local chest = peripheral.wrap("bottom")
12
local maxDrones = 6
13
local minDrones = 3
14
15
bees = {}
16
stacks = {}
17
shutdownMsg = nil
18
     
19
function addParent(parent, offspring)
20
    if not bees[parent] then
21
    bees[parent] = {
22
        --name = parent,
23
        score = 0,
24
        mutateFrom = {}
25
    }
26
    end
27
end
28
     
29
function addOffspring(offspring, parentss)
30
    if bees[offspring] then
31
    for i, parents in ipairs(parentss) do
32
        table.insert(bees[offspring].mutateFrom, parents)
33
    end
34
    else
35
    bees[offspring] = {
36
        score = 0,
37
        mutateFrom = parentss
38
    }
39
    end
40
    for i, parents in ipairs(parentss) do
41
    for i, parent in ipairs(parents) do
42
        addParent(parent, offspring)
43
    end
44
    end
45
end
46
     
47
	 
48
49
     
50
-- produce combinations from 1 or 2 lists
51
function choose(list, list2)
52
    local newList = {}
53
    if list2 then
54
    for i = 1, #list2 do
55
        for j = 1, #list do
56
        if list[j] ~= list[i] then
57
            table.insert(newList, {list[j], list2[i]})
58
        end
59
        end
60
    end
61
    else
62
    for i = 1, #list do
63
        for j = i, #list do
64
        if list[i] ~= list[j] then
65
            table.insert(newList, {list[i], list[j]})
66
        end
67
        end
68
    end
69
    end
70
    return newList
71
end
72
     
73
74
--bee list from Master Apiarist Database v3.1
75
--Forestry v2.3.0.7 (683)
76
--Extra Bees v1.8-dev2
77
--Magic Bees v2.1.7 (build 78)
78
79
addOffspring("Common", choose({"Forest", "Meadows", "Modest", "Wintry", "Tropical", "Marshy", "Water", "Rocky", "Mystical", "Sorcerous", "Unusual", "Attuned"}))
80
addOffspring("Cultivated", choose({"Common"}, {"Forest", "Meadows", "Modest", "Wintry", "Tropical", "Marshy", "Water", "Rocky", "Mystical", "Sorcerous", "Unusual", "Attuned"}))
81
82
addOffspring("Noble", {{"Common", "Cultivated"}})
83
addOffspring("Majestic", {{"Noble", "Cultivated"}})
84
addOffspring("Imperial", {{"Noble", "Majestic"}})
85
addOffspring("Diligent", {{"Common", "Cultivated"}})
86
addOffspring("Unweary", {{"Diligent", "Cultivated"}})
87
addOffspring("Industrious", {{"Diligent", "Unweary"}})
88
addOffspring("Heroic", {{"Steadfast", "Valiant"}})
89
addOffspring("Sinister", choose({"Cultivated"}, {"Modest", "Tropical"}))
90
addOffspring("Fiendish", choose({"Sinister"}, {"Cultivated", "Modest", "Tropical"}))
91
addOffspring("Frugal", choose({"Modest"}, {"Sinister", "Fiendish"}))
92
addOffspring("Demonic", {{"Sinister", "Fiendish"}})
93
addOffspring("Austere", {{"Modest", "Frugal"}})
94
addOffspring("Exotic", {{"Austere", "Tropical"}})
95
addOffspring("Edenic", {{"Exotic", "Tropical"}})
96
addOffspring("Spectral", {{"Hermitic", "Ender"}})
97
addOffspring("Phantasmal", {{"Spectral", "Ender"}})
98
addOffspring("Icy", {{"Industrious", "Wintry"}})
99
addOffspring("Glacial", {{"Icy", "Wintry"}})
100
addOffspring("Vindictive", {{"Monastic", "Demonic"}})
101
addOffspring("Vengeful", choose({"Vindictive"}, {"Demonic", "Monastic"}))
102
addOffspring("Avenging", {{"Vengeful", "Vindictive"}})
103
addOffspring("Leporine", {{"Meadows", "Forest"}})
104
addOffspring("Merry", {{"Wintry", "Forest"}})
105
addOffspring("Tipsy", {{"Wintry", "Meadows"}})
106
addOffspring("Tricky", {{"Sinister", "Common"}})
107
addOffspring("Rural", {{"Meadows", "Diligent"}})
108
addOffspring("Secluded", {{"Monastic", "Austere"}})
109
addOffspring("Hermitic", {{"Monastic", "Secluded"}})
110
addOffspring("Arid", {{"Meadows", "Modest"}})
111
addOffspring("Barren", {{"Arid", "Common"}})
112
addOffspring("Desolate", {{"Arid", "Barren"}})
113
addOffspring("Decaying", {{"Desolate", "Modest"}})
114
addOffspring("Skeletal", {{"Desolate", "Frugal"}})
115
addOffspring("Creepy", {{"Desolate", "Austere"}})
116
addOffspring("Decomposing", {{"Gnawing", "Common"}})
117
addOffspring("Tolerant", {{"Rocky", "Diligent"}})
118
addOffspring("Robust", {{"Rocky", "Tolerant"}})
119
addOffspring("Resilient", {{"Imperial", "Robust"}})
120
addOffspring("Corroded", {{"Resilient", "Forest"}})
121
addOffspring("Tarnished", {{"Resilient", "Marshy"}})
122
addOffspring("Rusty", {{"Resilient", "Meadows"}})
123
addOffspring("Leaden", {{"Resilient", "Unweary"}})
124
addOffspring("Galvanized", {{"Tarnished", "Cultivated"}})
125
addOffspring("Impregnable", {{"Resilient", "Noble"}})
126
addOffspring("Invincible", {{"Resilient", "Ender"}})
127
addOffspring("Glittering", {{"Corroded", "Imperial"}})
128
addOffspring("Shining", {{"Rusty", "Imperial"}})
129
addOffspring("Valuable", {{"Glittering", "Shining"}})
130
addOffspring("Lapis", {{"Resilient", "Water"}})
131
addOffspring("Emerald", {{"Lapis", "Noble"}})
132
addOffspring("Ruby", {{"Emerald", "Austere"}})
133
addOffspring("Sapphire", {{"Emerald", "Ocean"}})
134
addOffspring("Diamond", {{"Lapis", "Imperial"}})
135
addOffspring("Unstable", {{"Austere", "Rocky"}})
136
addOffspring("Nuclear", {{"Unstable", "Rusty"}})
137
addOffspring("Radioactive", {{"Nuclear", "Glittering"}})
138
addOffspring("Ancient", {{"Noble", "Diligent"}})
139
addOffspring("Primeval", {{"Ancient", "Noble"}})
140
addOffspring("Prehistoric", {{"Primeval", "Majestic"}})
141
addOffspring("Relic", {{"Prehistoric", "Imperial"}})
142
addOffspring("Fossilised", {{"Primeval", "Growing"}})
143
addOffspring("Resinous", {{"Primeval", "Fungal"}})
144
addOffspring("Oily", {{"Primeval", "Ocean"}})
145
addOffspring("Distilled", {{"Oily", "Industrious"}})
146
addOffspring("Refined", {{"Oily", "Distilled"}})
147
addOffspring("Elastic", {{"Refined", "Resinous"}})
148
addOffspring("River", {{"Water", "Common"}})
149
addOffspring("Ocean", {{"Water", "Diligent"}})
150
addOffspring("Stained", {{"Ebony", "Ocean"}})
151
addOffspring("Growing", {{"Diligent", "Forest"}})
152
addOffspring("Thriving", {{"Growing", "Rural"}})
153
addOffspring("Blooming", {{"Thriving", "Growing"}})
154
addOffspring("Sweetened", {{"Valiant", "Diligent"}})
155
addOffspring("Sugary", {{"Sweetened", "Diligent"}})
156
addOffspring("Ripening", {{"Sugary", "Forest"}})
157
addOffspring("Fruity", {{"Ripening", "Rural"}})
158
addOffspring("Farmed", {{"Cultivated", "Rural"}})
159
addOffspring("Bovine", {{"Rural", "Water"}})
160
addOffspring("Caffeinated", {{"Tropical", "Rural"}})
161
addOffspring("Minty", {{"Tropical", "Farmed"}})
162
addOffspring("Damp", {{"Common", "Marshy"}})
163
addOffspring("Boggy", {{"Damp", "Marshy"}})
164
addOffspring("Fungal", {{"Boggy", "Damp"}})
165
addOffspring("Furious", {{"Embittered", "Sinister"}})
166
addOffspring("Volcanic", {{"Embittered", "Furious"}})
167
addOffspring("Malicious", {{"Sinister", "Tropical"}})
168
addOffspring("Infectious", {{"Malicious", "Tropical"}})
169
addOffspring("Virulent", {{"Malicious", "Infectious"}})
170
addOffspring("Viscous", {{"Water", "Exotic"}})
171
addOffspring("Glutinous", {{"Viscous", "Exotic"}})
172
addOffspring("Sticky", {{"Viscous", "Glutinous"}})
173
addOffspring("Corrosive", {{"Virulent", "Sticky"}})
174
addOffspring("Caustic", {{"Corrosive", "Fiendish"}})
175
addOffspring("Acidic", {{"Corrosive", "Caustic"}})
176
addOffspring("Excited", {{"Cultivated", "Valiant"}})
177
addOffspring("Energetic", {{"Excited", "Valiant"}})
178
addOffspring("Frigid", {{"Wintry", "Diligent"}})
179
addOffspring("Absolute", {{"Ocean", "Frigid"}})
180
addOffspring("Shadowed", {{"Tolerant", "Sinister"}})
181
addOffspring("Darkened", {{"Shadowed", "Embittered"}})
182
addOffspring("Abyssal", {{"Shadowed", "Darkened"}})
183
addOffspring("Maroon", {{"Forest", "Valiant"}})
184
addOffspring("Saffron", {{"Meadows", "Valiant"}})
185
addOffspring("Prussian", {{"Water", "Valiant"}})
186
addOffspring("Natural", {{"Tropical", "Valiant"}})
187
addOffspring("Ebony", {{"Rocky", "Valiant"}})
188
addOffspring("Bleached", {{"Wintry", "Valiant"}})
189
addOffspring("Sepia", {{"Marshy", "Valiant"}})
190
addOffspring("Amber", {{"Maroon", "Saffron"}})
191
addOffspring("Turquoise", {{"Natural", "Prussian"}})
192
addOffspring("Indigo", {{"Maroon", "Prussian"}})
193
addOffspring("Slate", {{"Ebony", "Bleached"}})
194
addOffspring("Azure", {{"Prussian", "Bleached"}})
195
addOffspring("Lavender", {{"Maroon", "Bleached"}})
196
addOffspring("Lime", {{"Natural", "Bleached"}})
197
addOffspring("Fuchsia", {{"Indigo", "Lavender"}})
198
addOffspring("Ashen", {{"Slate", "Bleached"}})
199
addOffspring("Celebratory", {{"Austere", "Excited"}})
200
addOffspring("Jaded", {{"Ender", "Relic"}})
201
addOffspring("Glowering", {{"Furious", "Excited"}})
202
addOffspring("Hazardous", {{"Austere", "Desolate"}})
203
addOffspring("Lustered", {{"Resilient", "Unweary"}})
204
addOffspring("Abnormal", {{"Secluded", "Ender"}})
205
addOffspring("Spatial", {{"Abnormal", "Hermitic"}})
206
addOffspring("Quantum", {{"Spatial", "Spectral"}})
207
addOffspring("Eldritch", choose({"Cultivated"}, {"Mystical", "Sorcerous", "Unusual", "Attuned"}))
208
addOffspring("Esoteric", {{"Cultivated", "Eldritch"}})
209
addOffspring("Mysterious", {{"Eldritch", "Esoteric"}})
210
addOffspring("Arcane", {{"Esoteric", "Mysterious"}})
211
addOffspring("Charmed", {{"Cultivated", "Eldritch"}})
212
addOffspring("Enchanted", {{"Eldritch", "Charmed"}})
213
addOffspring("Supernatural", {{"Charmed", "Enchanted"}})
214
addOffspring("Ethereal", {{"Arcane", "Supernatural"}})
215
addOffspring("Watery", {{"Supernatural", "Ethereal"}})
216
addOffspring("Earthen", {{"Supernatural", "Ethereal"}})
217
addOffspring("Firey", {{"Supernatural", "Ethereal"}})
218
addOffspring("Windy", {{"Supernatural", "Ethereal"}})
219
addOffspring("Pupil", {{"Monastic", "Arcane"}})
220
addOffspring("Scholarly", {{"Arcane", "Pupil"}})
221
addOffspring("Savant", {{"Pupil", "Scholarly"}})
222
addOffspring("Aware", {{"Ethereal", "Attuned"}})
223
addOffspring("Spirit", choose({"Aware"}, {"MystEtherealical", "Attuned"}))
224
addOffspring("Soul", {{"Aware", "Spirit"}})
225
addOffspring("Skulking", {{"Modest", "Eldritch"}})
226
addOffspring("Ghastly", {{"Skulking", "Ethereal"}})
227
addOffspring("Spidery", {{"Tropical", "Skulking"}})
228
addOffspring("Smouldering", {{"Skulking", "Hateful"}})
229
addOffspring("Timely", {{"Imperial", "Ethereal"}})
230
addOffspring("Lordly", {{"Imperial", "Timely"}})
231
addOffspring("Doctoral", {{"Timely", "Lordly"}})
232
addOffspring("Infernal", {{"Infernal", "ves"}})
233
addOffspring("Hateful", {{"Infernal", "Eldritch"}})
234
addOffspring("Spiteful", {{"Infernal", "Hateful"}})
235
addOffspring("Withering", {{"Demonic", "Spiteful"}})
236
addOffspring("Oblivion", {{"Oblivion", "ves"}})
237
addOffspring("Nameless", {{"Ethereal", "Oblivion"}})
238
addOffspring("Abandoned", {{"Oblivion", "Nameless"}})
239
addOffspring("Forlorn", {{"Nameless", "Abandoned"}})
240
addOffspring("Draconic", {{"Imperial", "Abandoned"}})
241
addOffspring("Ferrous", {{"Common", "Industrious"}})
242
addOffspring("Auric", {{"Minium", "Plumbum"}})
243
addOffspring("Cuprum", {{"Industrious", "Meadows"}})
244
addOffspring("Stannum", {{"Industrious", "Forest"}})
245
addOffspring("Argentum", {{"Imperial", "Modest"}})
246
addOffspring("Plumbum", {{"Stannum", "Common"}})
247
addOffspring("Aluminum", {{"Industrious", "Cultivated"}})
248
addOffspring("Ardite", {{"Industrious", "Infernal"}})
249
addOffspring("Cobalt", {{"Imperial", "Infernal"}})
250
addOffspring("Manyullyn", {{"Ardite", "Cobalt"}})
251
addOffspring("Diamandi", {{"Austere", "Auric"}})
252
addOffspring("Esmeraldi", {{"Austere", "Argentum"}})
253
addOffspring("Apatine", {{"Rural", "Cuprum"}})
254
addOffspring("Mutable", {{"Unusual", "Eldritch"}})
255
addOffspring("Transmuting", {{"Unusual", "Mutable"}})
256
addOffspring("Crumbling", {{"Unusual", "Mutable"}})
257
addOffspring("Invisible", {{"Mystical", "Mutable"}})
258
addOffspring("Aer", {{"Windy", "Windy"}})
259
addOffspring("Ignis", {{"Firey", "Firey"}})
260
addOffspring("Aqua", {{"Watery", "Watery"}})
261
addOffspring("Solum", {{"Earthen", "Earthen"}})
262
addOffspring("Ordered", {{"Ethereal", "Arcane"}})
263
addOffspring("Chaotic", {{"Ethereal", "Supernatural"}})
264
addOffspring("Brainy", {{"Skulking", "Pupil"}})
265
addOffspring("Batty", {{"Skulking", "Windy"}})
266
addOffspring("Poultry", {{"Common", "Skulking"}})
267
addOffspring("Beefy", {{"Common", "Skulking"}})
268
addOffspring("Porcine", {{"Common", "Skulking"}})
269
addOffspring("Minium", {{"Frugal", "Eldritch"}})
270
271
272
	
273
--find the highest level bee i own that is a parent to species (of type "Princess" or "Drone" if type ~= nil)
274
--returns parent, offspring, score
275
--offspring is the next step after parent
276
--score is the depth of the search
277
278
function findAvailableParent(species, score, type)
279
280
	for i, stack in pairs(stacks) do
281
		if stack.beeInfo.displayName == species then
282
			if type then
283
				if string.find(stack.name, type) then
284
					return species, nil, score
285
				end					
286
			else
287
				return species, nil, score
288
			end
289
		end
290
	end
291
292
	local aScore, aParent, aOffspring
293
	local beeScore = 99999
294
	local beeParent = nil
295
	local beeOffspring = nil
296
	
297
	for i, parents in ipairs(bees[species].mutateFrom) do
298
		aParent, aOffspring, aScore = findAvailableParent(parents[1], score + 1, type)
299
		if aScore < beeScore then
300
			beeScore = aScore
301
			beeParent = aParent
302
			beeOffspring = aOffspring
303
		end
304
		aParent, aOffspring, aScore = findAvailableParent(parents[2], score + 1, type)
305
		if aScore < beeScore then
306
			beeScore = aScore
307
			beeParent = aParent
308
			beeOffspring = aOffspring
309
		end
310
	end
311
	if beeOffspring == nil then
312
		beeOffspring = species
313
	end
314
	return beeParent, beeOffspring, beeScore
315
end
316
317
--finds a princess and drone of the given species if they exist
318
local function findSpecies(species)
319
	local princessIndex = nil
320
	local droneIndex = nil
321
322
	for i, stack in pairs(stacks) do
323
		if stack.beeInfo.displayName == species then
324
			if string.find(stack.name, "Princess") then
325
				princessIndex = i
326
			end
327
			if string.find(stack.name, "Drone") then
328
				droneIndex = i
329
			end
330
		end
331
	end
332
	return princessIndex, droneIndex
333
end
334
335
--breed these two species, they must exists and have a breeding pair
336
local function breedSpecies(parent1, parent2)
337
	local princess1 = nil
338
	local princess2 = nil
339
	local drone1 = nil
340
	local drone2 = nil
341
	
342
	princess1, drone1 = findSpecies(parent1)
343
	princess2, drone2 = findSpecies(parent2)
344
	
345
	if not (princess1 and drone2) then
346
		princess1 = princess2
347
		drone2 = drone1
348
	end
349
	
350-
		chest.pushItem("up", princess1, 1) --todo check against description
350+
351
352-
		chest.pushItem("up", drone2, 1) --todo check against description
352+
353
		chest.pushItem("up", princess1, 1)
354
		turtle.drop()
355
		chest.pushItem("up", drone2, 1)
356
		turtle.drop()
357
		return true
358
	end
359-
--finds the most common species of type
359+
360
end
361
362
--finds the most common species of type Drone or Princess
363
local function findExtraBee(type, msg)
364
	local counts = {}
365
	local bestcount = 0
366
	local bestspecies = nil
367
368
	for i, stack in pairs(stacks) do
369
		if string.find(stack.name, type) then
370
			if counts[stack.beeInfo.displayName] then
371
				counts[stack.beeInfo.displayName] = counts[stack.beeInfo.displayName] + stack.qty
372
			else
373
				counts[stack.beeInfo.displayName] = stack.qty
374
			end
375
			if counts[stack.beeInfo.displayName] > bestcount then
376
				bestcount = counts[stack.beeInfo.displayName]
377
				bestspecies = stack.beeInfo.displayName
378
			end
379
		end
380
	end
381
	if bestcount < 2 then
382
		shutdownMsg = "Need more " .. type .. "s!";
383
	else
384
		if msg == "Used" then
385
			print("Used Extra " .. bestspecies .. " " .. type)
386
		end
387
	end
388
	return bestspecies, bestcount
389
end
390
391
--attempt to create a princess and minDrones of species, which i own one of
392
--returns true if already purebred, else begins a breeding cycle
393
394
local function purebreed(species)
395
	local princessCount = 0
396
	local droneCount = 0
397
398
	--count how many i have
399
400
	for i, stack in pairs(stacks) do
401
		if stack.beeInfo.displayName == species then
402
			if string.find(stack.name, "Princess") then
403
				princessCount = princessCount + stack.qty
404
			end
405
			if string.find(stack.name, "Drone") then
406
				droneCount = droneCount + stack.qty
407
			end
408
		end
409
	end
410
	
411
	if princessCount >= 1 and droneCount >= minDrones then
412
		return true
413
	end
414
415
	print("Attempting to purebreed " .. species)
416
417
	if princessCount >= 1 and droneCount >= 1 then
418
		breedSpecies(species, species)
419
		return false
420
	end
421
422
	--find something to breed it with, an available parent, or an extra bee
423
424
	local parent1, offspring, score
425
	if(princessCount >= 1) then
426
		parent1, offspring, score = findAvailableParent(species, 0, "Drone") 
427
		if score == 99999 then
428
			parent1, score = findExtraBee("Drone", "Used")
429
		else	
430
			--the purebreeding code sometimes gets stuck on low fertility bees		
431
			--local princess1, drone1 = findSpecies(parent1)
432
			--if princess1 and drone2 and not purebreed(parent1) then
433
			--	return false
434
			--end
435
		end
436
	else
437
		parent1, offspring, score = findAvailableParent(species, 0, "Princess")
438
		if score == 99999 then
439
			parent1, score = findExtraBee("Princess", "Used")
440
		else		
441
			--local princess1, drone1 = findSpecies(parent1)
442
			--if princess1 and drone2 and not purebreed(parent1) then
443
			--	return false
444
			--end
445
		end
446
	end
447
	if shutdownMsg then
448
		return false
449
	end
450
451
	breedSpecies(species, parent1)
452
	return false
453
end
454
455
--the main breeding function
456
--uses findavailableparent, then tries to create the designated offspring
457
458
local function targetSpecies(species)
459
	local parent1
460
	local parent2 = nil
461
462
	--find the highest level bee i have that is a parent to species
463
	--offspring is the next step after parent on the way to species
464
465
	local parent1, offspring, score = findAvailableParent(species, 0, nil)
466
	if score == 0 then
467
		--found species		
468
		return true
469
	end
470
	if score == 99999 then
471
		shutdownMsg = "No available parents for " .. species
472
		return false
473
	end
474
475
	print("Targeting Species " .. offspring)
476
	
477
	local princess1, drone1 = findSpecies(parent1)
478
	local princess2, drone2
479
480
	--find which bee i need to breed parent1 with to get offspring, showing preference for bees that i own
481
482
	for i, parents in ipairs(bees[offspring].mutateFrom) do
483
		if parents[1] == parent1 then
484
			princess2, drone2 = findSpecies(parents[2])
485
			if (princess1 and drone2) or (princess2 and drone1) then
486
				parent2 = parents[2]
487
				break
488
			end
489
			if not parent2 then
490
				parent2 = parents[2]
491
			end
492
			if princess2 or drone2 then
493
				parent2 = parents[2]
494
			end
495
		end
496
		if parents[2] == parent1 then
497
			princess2, drone2 = findSpecies(parents[1])
498
			if (princess1 and drone2) or (princess2 and drone1) then
499
				parent2 = parents[1]
500
				break
501
			end
502
			if not parent2 then
503
				parent2 = parents[1]
504
			end
505
			if princess2 or drone2 then
506
				parent2 = parents[1]
507
			end
508
		end
509
510
	end
511
	
512
	princess2, drone2 = findSpecies(parent2)
513
514
	if (princess1 and drone2) or (princess2 and drone1) then	
515
		--i have both bees i need so breed it now
516
		--the purebreeding code sometimes gets stuck on low fertility bees	
517
		--if princess1 and drone1 and not purebreed(parent1) then
518
		--	return false
519
		--end
520
		--if princess2 and drone2 and not purebreed(parent2) then
521
		--	return false
522
		--end
523
		breedSpecies(parent1, parent2)
524
		return false
525
	end
526
527
	--i have the species but not princess or drone, so purebreed it
528
	if princess2 or drone2 then
529
		purebreed(parent2)
530
		return false
531
	end
532
533
	--i dont have the species i need to breed with parent, so target it
534
	targetSpecies(parent2)
535
	return false
536
end
537
538
local function dropExtraDrones()
539
540
	local species, count = findExtraBee("Drone", "Dropping")
541
	shutdownMsg = nil
542
543
	if count <= maxDrones then
544
		return
545
	end
546
	
547
	for i, stack in pairs(stacks) do
548
		if stack.beeInfo.displayName == species and string.find(stack.name, "Drone") then
549
			chest.pushItem("up", i, 1)
550
			turtle.dropUp()
551
			count = count - 1
552
			if count <= maxDrones then
553
				return
554
			end
555
		end
556
	end
557
558
end
559
560
local dropExtraItems()
561
562
	for i, stack in pairs(stacks) do
563
		if (not string.find(stack.name, "Drone")) and (not string.find(stack.name, "Princess")) then
564
			chest.pushItem("up", i, stack.qty)
565
			turtle.dropUp()
566
		end
567
	end
568
569
end
570
571
local function main(species)
572
573
	for slot = 1, 16 do
574
		if turtle.getItemCount(slot) > 0 then
575
			turtle.select(slot)
576
			turtle.dropDown()
577
		end
578
	end
579
	turtle.select(1)
580
	
581
	local apiarystacks
582
583
	while(1) do
584
	
585
		--test for breeding in progress
586
		apiarystacks = apiary.getAllStacks()
587
		while apiarystacks[1] do
588
			sleep(1)
589
			while(turtle.suck()) do
590
				turtle.dropDown()
591
			end
592
593
			apiarystacks = apiary.getAllStacks()
594
		end
595
596
		--clear apiary
597
		while(turtle.suck()) do
598
			turtle.dropDown()
599
		end
600
601
		--get the list of all items in the chest
602
		stacks = chest.getAllStacks()
603
		
604
		if targetSpecies(species) then
605
			if purebreed(species) then
606
				shutdownMsg = "Breeding complete: " .. species
607
			end
608
		end
609
610
		if(shutdownMsg) then
611
			print(shutdownMsg)
612
			break
613
		end
614
615
		dropExtraDrones()
616
		dropExtraItems()
617
618
		sleep(1)
619
	end
620
end
621
622
local species = ...
623
if species == nil then
624
	print("Usage")
625
	print("   programname species")
626
	return
627
end
628
if bees[species] == nil then
629
	print("Species does not exist in database")
630
end
631
632
main(species)