为了好玩,我制作了Lua脚本,以模拟虚构物种的生长速度' krogan'从游戏质量效应。他们可以活1000年,一个krogan女性一年可以生产1000克罗根。基本规则是:
可以找到代码(和输出)HERE。否则...
local NumYears = 1000 --How many years to estimate
local MinFertile = 100 --Age krogan start reproducing
local MaxFertile = 300 --Age krogan stop reproducing
local KroganAge = 1000 --How old a krogan can get
local Start_Population = 100000 --Number of initial krogans
local TimeSkips = 10 --Population updates displayed every # years
local Fertility = 1000 --Number of average children born by one mother each year
local PercentPregnant = 0.04 --percent of population pregnant during the year
math.randomseed(os.time())
local Krogans = {}
do --randomizes current krogan population
local sum = 0
for i = 1, KroganAge do
local x = i-KroganAge/2
x = x*5/KroganAge
Krogans[i] = math.exp(-((x)^2)/2)/math.sqrt(2*math.pi) --bell curve
sum = sum + Krogans[i]
end
--So that the ratio remains the same, and the total sum is around Start_Population
local left = 0
for i = 1, KroganAge do
local a = Krogans[i]/sum*Start_Population
left = left + (a-math.floor(a))
local extra = math.floor(left)
Krogans[i] = math.floor(a)+extra
left = left - extra
end
end
function NextYear()
local Fertile = 0
local Population = 0
for i = MinFertile, MaxFertile do
if Krogans[i] then
Fertile = Fertile + Krogans[i]*0.5 --mult by 0.5 for fertile females (50% of population)
end
end
for i = KroganAge, 2, -1 do
if Krogans[i-1] then
Krogans[i] = Krogans[i-1] --advance krogan by one year
Population = Population + Krogans[i] --get population count
end
end
Krogans[1] = Fertile*Fertility*PercentPregnant --Krogan born this year
Population = Population + Krogans[1]
return Fertile, Population
end
local words = {} --Table used for output formatting
words[9] = "Billion"
words[12] = "Trillion"
words[15] = "Quadrillion"
words[18] = "Quintillion"
words[21] = "Sextillion"
words[24] = "Septillion"
words[27] = "Octillion"
words[30] = "Nonillion"
words[33] = "Decillion"
words[36] = "Undecillion"
words[39] = "Duodecillion"
words[42] = "Tredecillion"
words[45] = "Quattuordecillion"
words[48] = "Quindecillion"
function convert(n) --Converts/formats numbers into easy-to-read output
if n <= 999999999 then -- credit http://r...content-available-to-author-only...n.it
local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right
else
n = string.format("%18.0f",n):gsub("%s","")
local digits = #n-1
local choice = math.floor(digits/3)*3
local num = (digits-choice)+1
local str = string.sub(n,1,num).."."..string.sub(n,num+1,num+1).." "..words[choice]
return str
end
end
for i = 1, NumYears do
local Fertile, Population = NextYear()
if i%TimeSkips == 0 then
print("Year: "..i)
print("Total Population:\t"..convert(math.floor(Population)))
print("Fertile Females: \t"..convert(math.floor(Fertile)))
print("----")
end
end
这可以预见,几百年后人口相当多。我的问题是,这是否反映了准确的克罗根人群,假设所有死亡都是从老年开始的?我尝试为人类输入一系列数字(年龄在15到44岁之间,最大年龄70岁,每个孩子出生1个孩子),但这只会导致下降的人口,而我&#39 ;我不确定为什么。
我猜测它与如何计算每年出生的孩子数量有关。这是非常简单的乘法:
Krogans[1] = Fertile*Fertility*PercentPregant
--[[
Fertile: Number of Fertile Women
Fertility: Number of children born in a pregnancy
PercentPregnant: How many fertile women are pregnant this year (4% = 0.04)
]]
但这有什么不对吗?为什么会导致人口下降?