-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdevice.lua
More file actions
76 lines (69 loc) · 2.82 KB
/
Copy pathdevice.lua
File metadata and controls
76 lines (69 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
local M = {}
local apiary = require("apiary")
--local alveary = require("alveary")
--local industrialApiary = require("industrialApiary")
local bot = require("bot")
local mutations = require("mutations")
local function checkMutation(princessSlot, droneSlot)
local speciesGeneList = { bot.inventory[princessSlot].species[1], bot.inventory[princessSlot].species[2], bot.inventory[droneSlot].species[1], bot.inventory[droneSlot].species[2] }
for i=4,2,-1 do
for j=1,i-1 do
if speciesGeneList[i] == speciesGeneList[j] then
table.remove(speciesGeneList, i)
break
end
end
end
local function check(allele1, allele2)
for _,mutation in pairs(mutations) do
if mutation[1] then
for i=1,#mutation do
if not mutation[i].foundation and (mutation[i].parents[1] == allele1 and mutation[i].parents[2] == allele2 or mutation[i].parents[1] == allele2 and mutation[i].parents[2] == allele1) then
return true
end
end
else
if not mutation.foundation and (mutation.parents[1] == allele1 and mutation.parents[2] == allele2 or mutation.parents[1] == allele2 and mutation.parents[2] == allele1) then
return true
end
end
end
return false
end
for i=1,#speciesGeneList-1 do
for j=i,#speciesGeneList do
if check(speciesGeneList[i], speciesGeneList[j]) then
return true
end
end
end
return false
end
local function chooseMethod(strategy)
--暂时只写了单方块蜂箱
return apiary
end
function M.nextGeneration(princessSlot, droneSlot, mutation)
if not bot.inventory[princessSlot] or bot.inventory[princessSlot].type ~= "beePrincess" or not bot.inventory[droneSlot] or bot.inventory[droneSlot].type ~= "beeDrone" then
error(string.format("错误的调用nextGeneration(%d, %d)",princessSlot, droneSlot))
end
local strategy = mutation or checkMutation(princessSlot, droneSlot)
--[[策略为false,忽略突变率,使寿命尽可能短
策略为true,在突变率为0的前提下使寿命尽可能短
策略type为table,尽可能将突变率提高到100]]
if not apiary.checkNextGeneration(princessSlot, strategy) then
error("没有满足条件的蜂箱可供培育下一代")
end
return chooseMethod(strategy).nextGeneration(princessSlot, droneSlot, strategy)
end
function M.checkMutationEnvironment(mutation)
return apiary.checkMutationEnvironment(mutation)
end
function M.destruct()
apiary.destruct()
bot.moveYTo(2)
bot.moveXZTo(0,0)
bot.moveYTo(1)
bot.turnTo(0,-1)
end
return M