Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function copy(tbl)
- local output = {}
- for k, v in pairs(tbl) do
- if type(v) == "table" then
- if v == tbl then
- output[k] = output
- else
- output[k] = copy(v)
- end
- else
- output[k] = v
- end
- end
- return output
- end
- local f = fs.open("bee.dat", "r")
- local d = f.readAll()
- f.close()
- local raw = textutils.unserialize(d)
- local allSpecies = {}
- for k, v in pairs(raw) do
- allSpecies[v.allele1] = true
- allSpecies[v.allele2] = true
- allSpecies[v.result] = true
- end
- local iallSpecies = {}
- for k, v in pairs(allSpecies) do
- table.insert(iallSpecies, k)
- end
- print("Total species: " .. #iallSpecies)
- local unbreedable = copy(allSpecies)
- for k, v in pairs(raw) do
- unbreedable[v.result] = nil
- end
- local iunbreedable = {}
- for k, v in pairs(unbreedable) do
- table.insert(iunbreedable, k)
- end
- print("Unbreedable: " .. #iunbreedable)
- print("Building tree...")
- local tree = {}
- -- initial pass
- for k, v in pairs(raw) do
- local data = {v.allele1, v.allele2, v.chance}
- local res = v.result
- if not tree[res] then tree[res] = {} end
- table.insert(tree[res], data)
- end
- local f = fs.open("out.dat", "w")
- f.write(textutils.serialize(tree))
- f.close()
- local available = {
- Meadows=true,
- Forest=true,
- }
- local function breedable(available)
- local out = copy(available)
- for species, combos in pairs(tree) do
- for i, combo in ipairs(combos) do
- if available[combo[1]] and available[combo[2]] then
- if out[species] then
- if out[species][3] < combo[3] then
- out[species] = combo
- end
- else
- out[species] = combo
- end
- end
- end
- end
- local recurse = false
- for k, v in pairs(out) do
- if not available[k] then recurse = true break end
- end
- if recurse then out = breedable(out) end
- return out
- end
- --print(textutils.serialize(breedable(available)))
- return breedable
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement