计算RPG中命中几率的算法

时间:2013-07-23 10:56:09

标签: c# algorithm

我正在尝试计算一个算法并在C#中实现它,它将计算角色扮演游戏中敌人的命中几率。

基本上,如果我的角色的灵巧等于我的对手,我的命中率是90%。如果我的灵巧度是我对手的500%,我的命中率是100%,如果我的对手是我的500%,那么我的命中几率为0%。

我一直在寻找曲线拟合公式一小时,我的大脑被摧毁。

也许这太复杂了一种确定命中几率的方法?也许某人有更好的解决方案可以提供?

1 个答案:

答案 0 :(得分:3)

我没有测试过这个,但它似乎是你想要的:

double higherd = Math.Max(mydexterity, oppdexterity);
double lowerd  = Math.Min(mydexterity, oppdexterity);

//(500%-100%)/100% * 25% = 400%/100% * 25% = 4* 25% = 100%
double d_hitchance = (higherd - lowerd) / (lowerd) * 0.25D;

double higher_hitchance = d_hitchance * 0.1D + 0.9D;

double lower_hitchance = 0.9D - d_hitchance * 0.9D;

double myhitchance = (mydexterity==higherd)? higher_hitchance : lower_hitchance;
double opphitchance = (oppdexterity==higherd)? higher_hitchance : lower_hitchance;

当差异超过500%

时,您可能必须将机会夹在0和1.0之间