我试图制作一个程序来计算你的k/d比(杀死/死亡,这是在FPS游戏中用来让人们相信它是一种技能),你需要多少杀死而不死一次才能到达goalKD。它也有一个部分,计算你需要多少战斗,如果你给程序,你的平均战斗死亡和战斗死亡。
有一个有效的方法来编程吗?目前,我的方式是让我进入程序员-效率地狱。
For i = 1 to 100000 {
While GoalKD>KDratio {
Kills = BattleKills + Kill
Deaths = BattleDeaths + Death
KDratio = Kills / Deaths
i++
}
}我正在用SmallBasic编程,因为我对它非常熟悉,而且我认为它很容易读懂。此外,如果可能的话,不要马上给出答案,给我一些提示,让我练习我的思想。将答案添加到一个扰流板框中。
发布于 2013-12-19 22:58:51
对于所需的杀人部分,您正在试图解决以下问题:
k{current} + n
-------------- = r
d{current}其中,r是目标速率,n是您要寻找的数字。一些基本代数:
n = rd - k对于战斗部分,你需要解决
k{current} + b * k{battle} // current kills + additional kills
-------------------------- = r
d{current} + b * d{battle} // current deaths + additional deaths
k{current} + b * k{battle} = r * (d{current} + b * d{battle}) // multiply both sides by d{current} + b * d{battle}
k{current} + b * k{battle} = r * d{current} + r * b * d{battle}) // just showing multiplication of r
b * (k{battle} - r * d{battle}) = r * d{current} - k{current} // subtracting terms from each side
r * d{current} - k{current}
b = --------------------------- // dividing by k{battle} - r * d{battle}
k{battle} - r * d{battle}在上面的代码中,这将变成
need = Math.ceiling( GoalKD * Deaths - Kills )
battles = Math.ceiling( ( GoalKD * Deaths - Kills ) / (BattleKills - GoalKD * BattleDeaths) )我不是SmallBasic的人,所以请原谅上面的语法错误.
(编辑以修复所需的数学错误,重新战斗,并向数学添加注释。)
https://codereview.stackexchange.com/questions/37806
复制相似问题