gpt4 book ai didi

java - 需要用 Java 来决定一支球队得分多少(足球模拟器)

转载 作者:行者123 更新时间:2023-12-01 18:34:17 26 4
gpt4 key购买 nike

我正在尝试制作一个基于文本的足球模拟。我发现很难编写决定球队进球数的方法。每个队伍都有攻击和防御等级(目前为 20 级)。我的程序功能性的,但我正在寻找使其更加现实的方法,包括惊喜的机会(最近这种情况在联赛中经常发生)。这是我写的方法:

public static int determineGoals(Team t1, Team t2)
// Determines how many goals a team scores by comparing attack and defense levels
{
double percent = randDouble(1, 100);
int goals = 0;

if (t1.attack - t2.defence >= 15)
{
if (percent <= 5)
{
goals = 0;
}
else if (percent <= 25)
{
goals = rand(1, 2);
}
else if (percent <= 90)
{
goals = rand(3, 4);
}
else
{
goals = rand(5, 6);
}
}

else if (t1.attack - t2.defence >= 7)
{
if (percent <= 10)
{
goals = 0;
}
else if (percent <= 30)
{
goals = rand(1, 2);
}
else if (percent <= 92)
{
goals = rand(3, 4);
}
else
{
goals = rand(5, 6);
}
}

else if (t1.attack - t2.defence >= 3)
{
if (percent <= 20)
{
goals = 0;
}
else if (percent <= 55)
{
goals = rand(1, 2);
}
else if (percent <= 94)
{
goals = rand(3, 4);
}
else
{
goals = rand(5, 6);
}
}

else if (t1.attack - t2.defence >= 0)
{
if (percent <= 25)
{
goals = 0;
}
else if (percent <= 70)
{
goals = rand(1, 2);
}
else if (percent <= 96)
{
goals = rand(3, 4);
}
else
{
goals = rand(5, 6);
}
}

else if (t1.attack - t2.defence >= -3)
{
if (percent <= 30)
{
goals = 0;
}
else if (percent <= 75)
{
goals = rand(1, 2);
}
else if (percent <= 98)
{
goals = rand(3, 4);
}
else
{
goals = rand(5, 6);
}
}

else if (t1.attack - t2.defence >= -7)
{
if (percent <= 35)
{
goals = 0;
}
else if (percent <= 85)
{
goals = rand(1, 2);
}
else
{
goals = rand(3, 4);
}
}

else if (t1.attack - t2.defence >= -15)
{
if (percent <= 65)
{
goals = 0;
}
else if (percent <= 95)
{
goals = rand(1, 2);
}
else
{
goals = rand(3, 4);
}
}

else
{
if (percent <= 75)
{
goals = 0;
}
else
{
goals = rand(1, 2);
}
}

return goals;
}

如果您有任何想法,我想听听,包括全新的算法想法。

编辑:此外,我意识到我使用了随机 double 值,但将其视为 int (1-100),我会更改它。

最佳答案

我会使用随机双生成器函数来随机化攻击和防御分数。通过这样做,您不会得到“直接结果”,但它们可能会以令人惊讶的方式稍微扭曲结果。您可以为此研究高斯分布,以稍微“引导”它。

关于java - 需要用 Java 来决定一支球队得分多少(足球模拟器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60090125/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com