c# - 战斗的数学方程式

标签 c# algorithm equation

我有以下战斗代码,但用户将在大约 99.9% 的时间内获胜(经过 5000 次随机循环测试)

我有以下影响战斗的变量

强度 |防御 |灵巧 |损坏 |门户难度(总是+ 1停止* 0)|关键

这是我目前的情况

//player variable 
//(int) player.itemDamage = 20
//(int) player.itemStr = 2
//(int) player.itemDex = 4

            int defense = (int)Math.Round((((portal + 1) * ((rand.NextDouble() + 0.5))) + 5) / 2, 0);
            int damage = (int)Math.Round((((portal + 1) * ((rand.NextDouble() + 0.5))) + player.itemDamage), 0);
            int str = (int)Math.Round((((portal + 1) * ((rand.NextDouble() + 0.5))) + player.itemStr), 0);
            int dex = (int)Math.Round((((portal + 1) * ((rand.NextDouble() + 0.5))) + player.itemDex), 0);
while(true)
{
for (int i = 0; i < 10; i++)
                {
                    critical += rand.NextDouble();
                }
                eHP -= (int)Math.Round((((player.itemDamage + player.itemStr) - defense) * critical) / 2, 0);
                critical = 1;

                for (int i = 0; i < 10; i++)
                {
                    critical += rand.NextDouble();
                }
                HP -= (int)Math.Round((((damage + str) - 5) * critical) / 2, 0);

                if (eHP <= 0)
                {
                    return;
                }
else if (HP <= 0)
                {
                    return;
                }
                }

我可以在以下代码中更改什么以使用户 (HP) 赢得 70% 的时间,我可以得到一些建议吗?我对算法很糟糕 编辑:虽然我希望用户在 70% 的时间里获胜,但我仍然希望它是基于伤害的回合,而不是使用简单的 if(0 > 70) win else 松散的声明,因为那不会是一场非常有趣的战斗。

最佳答案

if (rand.next(10) > 7) {
    //user wins
} else {
    //user loses
}

关于c# - 战斗的数学方程式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13551172/

相关文章:

c# - 单击用户控件更新面板内动态按钮上的事件

C# Entity Framework 连接 - 访问数据所需的 dbcreator 角色

algorithm - 有网页可以测试我的3-SAT程序吗?

python - TRIE数据结构中Search操作的时间复杂度

haskell - 求解方程 a * b = c,其中 a、b 和 c 是自然数

c++ - OpenCV 解决任意系统的返回常量值?

c# - 对 HttpContext.Current.Session 的静态引用是否为所有用户返回相同的 session ?

c# - 如何防止 Jquery 可排序连接列表中的重复条目?

c - 如何避免首字母相同的两个句子在随机播放中彼此相邻?