在线游戏中模拟体育比赛

发布于 2024-08-03 07:54:53 字数 898 浏览 5 评论 0原文

在在线经理游戏(例如 Hattrick)中,我想模拟两支球队之间的比赛。

一支球队由 11 名球员组成。每个球员的力量值在 1 到 100 之间。我取每支球队防守球员的这些力量值并计算平均值。这就是一支球队的防守质量。然后我会利用进攻球员的优势并获得进攻质量。

对于每次攻击,我都会执行以下操作:

$offFactor = ($attackerTeam_offensive-$defenderTeam_defensive)/max($attackerTeam_offensive, $defenderTeam_defensive);
$defFactor = ($defenderTeam_defensive-$attackerTeam_offensive)/max($defenderTeam_defensive, $attackerTeam_offensive);

目前,我不知道为什么要将其除以两个值中较高的一个。但这个公式应该给你一个稍后需要的进攻和防守质量的因素。

然后我为每个可能发生的事件嵌套了条件语句。例如:进攻队有得分机会吗?

if ((mt_rand((-10+$offAdditionalFactor-$defAdditionalFactor), 10)/10)+$offFactor >= 0) 
{ ... // the attack succeeds

例如,这些附加因素可能是战术价值。

您认为这是计算游戏的好方法吗?我的用户说他们对模拟的质量不满意。我该如何改进它们?您是否有可以带来更好结果的不同方法?或者你认为我的方法很好,我只需要调整条件语句中的值并进行一些实验?

我希望你能帮助我。提前致谢!

In an online manager game (like Hattrick), I want to simulate matches between two teams.

A team consists of 11 players. Every player has a strength value between 1 and 100. I take these strength values of the defensive players for each team and calculate the average. That's the defensive quality of a team. Then I take the strengths of the offensive players and I get the offensive quality.

For each attack, I do the following:

$offFactor = ($attackerTeam_offensive-$defenderTeam_defensive)/max($attackerTeam_offensive, $defenderTeam_defensive);
$defFactor = ($defenderTeam_defensive-$attackerTeam_offensive)/max($defenderTeam_defensive, $attackerTeam_offensive);

At the moment, I don't know why I divide it by the higher one of both values. But this formula should give you a factor for the quality of offense and defense which is needed later.

Then I have nested conditional statements for each event which could happen. E.g.: Does the attacking team get a scoring chance?

if ((mt_rand((-10+$offAdditionalFactor-$defAdditionalFactor), 10)/10)+$offFactor >= 0) 
{ ... // the attack succeeds

These additional factors could be tactical values for example.

Do you think this is a good way of calculating a game? My users say that they aren't satisfied with the quality of the simulations. How can I improve them? Do you have different approaches which could give better results? Or do you think that my approach is good and I only need to adjust the values in the conditional statements and experiment a bit?

I hope you can help me. Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

欢烬 2024-08-10 07:54:53

这是我会做的一种方法。

进攻/防守质量

首先让我们计算出整个球队的平均实力:

Team.Strength = SUM(Players.Strength) / 11

现在我们想将球队分成两部分,并计算出我们防守球员和进攻球员的平均实力。]

Defense.Strength = SUM(Defensive_Players.Strength)/Defensive_Players.Count
Offense.Strength = SUM(Offense_Players.Strength)/Offense_Players.Count

现在,我们有三个值。第一个,即团队平均水平,将用于计算我们获胜的几率。另外两个将计算我们防守的几率和得分的几率。

进攻平均数高的球队将有更多机会,防守高的球队将有更多扑救机会。

现在如果我们有球队,我们称他们为A和B。A

队,平均得分为80,进攻得分为85,防守得分为60。B

队,平均得分为70,进攻得分为50,并且防守得分为 80。

现在,基于平均值。 A队应该更有机会获胜。但增加多少呢?

得分和节省

让我们计算出 A 队应该得分多少次:

A.Goals = (A.Offensive / B.Defensive) + RAND()
        = (85/80) + 0.8;
        = 1.666

我假设随机值会增加 -1 到 +1 之间的任何值,尽管您可以调整它。

我们可以看到,公式表明 A 队应该进 1.6 个球。我们可以向上/向下舍入。或者给 A 队 1,然后计算另一队是否允许(随机机会)。

现在对于 B 队来说

B.Goals = (B.Offensive / A.Defensive) + RAND()
        = (50/60) + 0.2;
        = 1.03

,我们 A 得分 1,B 得分 1。但请记住,我们希望以 A 有利的方式权衡这一点,因为总体而言,他们是更好的球队。

那么A获胜的机会有多大呢?

Chance A Will Win = (A.Average / B.Average)
                  = 80 / 70
                  = 1.14

因此我们可以看到 A 赢得比赛的赔率是 14% (0.14)。我们可以使用这个值来查看最终得分是否有任何变化:

if Rand() <= 0.14 then Final Score  = A 2 - 1 B Otherwise A 1 - 1 B

如果我们的随机数是 0.8,那么比赛是平局。

总结和进一步的想法

您肯定会想尝试一下这些值。请记住,游戏机制很难正确。与你的球员交谈,询问他们为什么不满意。有球队总是输球吗?模拟总是停滞不前吗?等等。

上述概要深受选择的随机性影响。您需要将其标准化,这样一支球队额外进 5 个球的机会就非常非常少了。但一点随机性是为游戏增添多样性的好方法。

也有一些方法可以编辑此方法。例如,您可以使用“进球数”作为得分机会数,而不是进球数,然后使用另一个函数根据其他因素计算出进球数(即选择随机前锋,并使用该球员个人)统计数据和守门员,以确定是否有进球)

我希望这会有所帮助。

Here is a way I would do it.

Offensive/Defensive Quality

First lets work out the average strength of the entire team:

Team.Strength = SUM(Players.Strength) / 11

Now we want to split out side in two, and work out the average for our defensive players, and our offensive players.]

Defense.Strength = SUM(Defensive_Players.Strength)/Defensive_Players.Count
Offense.Strength = SUM(Offense_Players.Strength)/Offense_Players.Count

Now, we have three values. The first, out Team average, is going to be used to calculate our odds of winning. The other two, are going to calculate our odds of defending and our odds of scoring.

A team with a high offensive average is going to have more chances, a team with a high defense is going to have more chance at saving.

Now if we have to teams, lets call them A and B.

Team A, have an average of 80, An offensive score of 85 and a defensive score of 60.

Team B, have an average of 70, An offensive score of 50 and a defensive score of 80.

Now, based on the average. Team A, should have a better chance at winning. But by how much?

Scoring and Saving

Lets work out how many times goals Team A should score:

A.Goals = (A.Offensive / B.Defensive) + RAND()
        = (85/80) + 0.8;
        = 1.666

I have assumed the random value adds anything between -1 and +1, although you can adjust this.

As we can see, the formula indicates team A should score 1.6 goals. we can either round this up/down. Or give team A 1, and calculate if the other one is allowed (random chance).

Now for Team B

B.Goals = (B.Offensive / A.Defensive) + RAND()
        = (50/60) + 0.2;
        = 1.03

So we have A scoring 1 and B scoring 1. But remember, we want to weight this in A's favour, because, overall, they are the better team.

So what is the chance A will win?

Chance A Will Win = (A.Average / B.Average)
                  = 80 / 70
                  = 1.14

So we can see the odds are 14% (.14) in favor of A winning the match. We can use this value to see if there is any change in the final score:

if Rand() <= 0.14 then Final Score  = A 2 - 1 B Otherwise A 1 - 1 B

If our random number was 0.8, then the match is a draw.

Rounding Up and Further Thoughts

You will definitely want to play around with the values. Remember, game mechanics are very hard to get right. Talk to your players, ask them why they are dissatisfied. Are there teams always losing? Are the simulations always stagnant? etc.

The above outline is deeply affected by the randomness of the selection. You will want to normalise it so the chances of a team scoring an extra 5 goals is very very rare. But a little randomness is a great way to add some variety to the game.

There are ways to edit this method as well. For example instead of the number of goals, you could use the Goal figure as the number of scoring chances, and then have another function that worked out the number of goals based on other factors (i.e. choose a random striker, and use that players individual stats, and the goalies, to work out if there is a goal)

I hope this helps.

贩梦商人 2024-08-10 07:54:53

足球中最基本的战术决策是选择阵型,这是一组三个数字,分别将 10 名外场球员分配到防守、中场和进攻,例如 4/4/2。

如果你使用平均水平的球员力量,你不仅会失去这种战术,而且还会倒退:最强的防守是只有一名非常优秀的球员的防守,给他任何帮助都会让对方更有可能得分。如果您有一名评分为 10 的玩家,则平均值为 10。添加另一名评分为 8 的玩家,平均值就会下降(降至 9)。但分配更多的人来防守应该会让它变得更强,而不是更弱。

所以首先,你想让一切都基于总数,而不是平均值。总数之间的比率是一种很好的与规模无关的方法,用于确定哪些球队更强以及强多少。比率往往比差异更好,因为它们以可预测的方式与任何实力范围的团队一起工作。您可以设置一个战斗结果表,显示进球数(每场比赛、每场比赛)一半,每次移动,或其他)。

下一个战术选择是拥有一名出色的球员更好,还是拥有几名优秀的球员更好。您可以通过设置代表游戏中发生的事情的场景(例如一对一、角球或长传)来使这一点变得重要。首先随机选择场景中涉及的玩家,然后滚动该场景的结果。一个结果可能是另一种情况开始(中场传球导致传中导致头球机会)。

最后一步是为玩家提供不止一种类型的力量评级,例如头球、传球、射门等,这将使您几乎达到实际足球经理游戏的水平。然后,您使用适合他们所处场景的强度等级。

The most basic tactical decision in football is picking formation, which is a set of three numbers which assigns the 10 outfield players to defence, midfield and attack, respectively, e.g. 4/4/2.

If you use average player strength, you don't merely lose that tactic, you have it going backwards: the strongest defence is one with a single very good player, giving him any help will make it more likely the other team score. If you have one player with a rating of 10, the average is 10. Add another with rating 8, and the average drops (to 9). But assigning more people to defence should make it stronger, not weaker.

So first thing, you want to make everything be based on the total, not the average. The ratio between the totals is a good scale-independent way of determining which teams is stronger and by how much. Ratios tend to be better than differences, because they work in a predictable way with teams of any range of strengths. You can set up a combat results table that says how many goals are scored (per game, per half, per move, or whatever).

The next tactical choice is whether it is better to have one exceptional player, or several good ones. You can make that matter that by setting up scenarios that represent things that happen in game, e.g. a 1 on 1, a corner, or a long ball. The players involved in a scenario are first randomly chosen, then the result of the scenario is rolled for. One result can be that another scenario starts (midfield pass leads to cross leads to header chance).

The final step, which would bring you pretty much up to the level of actual football manager games, is to give players more than one type of strength rating, e.g., heading, passing, shooting, and so on. Then you use the strength rating appropriate to the scenario they are in.

绅刃 2024-08-10 07:54:53

您的示例中的除法可能是一个坏主意,因为它会根据哪一侧更好而改变输出变量的比例。通常,在比较两个数量时,您要么需要区间数据(从另一个数量中减去一个数量),要么需要比率数据(一个数量除以另一个数量),但不能同时使用两者。

在这种情况下,更好的方法是简单地将进攻得分除以防守得分。如果两者相等,则结果为1。如果进攻方比防守方强,则结果大于1,如果防守方更强,则结果小于1。这些都是很容易使用的数字。

此外,不是对整个团队进行平均,而是根据所使用的阵型或战术对团队的各个部分进行平均。这将允许球队选择进攻或防守,并了解其利弊。

并为自己编写一些更好的随机数生成函数。对于初学者来说,一种返回 -1 到 1 之间的浮点值,另一种返回 0 到 1 之间的浮点值。在计算中使用这些,您就可以避免到处都是令人困惑的 10!

The division in your example is probably a bad idea, because it changes the scale of the output variable depending on which side is better. Generally when comparing two quantities you either want interval data (subtract one from the other) or ratio data (divide one by the other) but not both.

A better approach in this case would be to simply divide the offensive score by the defensive score. If both are equal, the result will be 1. If the attacker is better than the defender, it will be greater than 1, and if the defender is stronger, it will be less than one. These are easy numbers to work with.

Also, instead of averaging the whole team, average parts of the team depending on the formations or tactics used. This will allow teams to choose to play offensively or defensively and see the pros and cons of this.

And write yourself some better random number generation functions. One that returns floating point values between -1 and 1 and one that works from 0 to 1, for starters. Use these in your calculations and you can avoid all those confusing 10s everywhere!

始于初秋 2024-08-10 07:54:53

您可能还想询问用户他们不喜欢模拟的哪些。他们可能不想看到比赛的最终结果,而是想知道有多少次他们的球队有机会进攻,但防守重新获得了控制权。因此,

"Your team wins 2-1"

他们不想看到比赛亮点:

"Your team wins 2-1:
 - scored at minute 15,
 - other team took control and went for tried for a goal at minute 30, 
   but the shoot was intercepted,
 - we took control again and $PLAYER1 scored a beautiful goal!
... etc

您可以使用杰米建议的起点,随机选择时间,也许还可以根据进攻球员的加权样本(即具有得分越高,获得得分的机会就越大)。您可以享受乐趣并添加随机的低概率事件,例如球员吃到红牌、有人自伤、球场上裸奔……

You might also want to ask the users what about the simulation they don't like. It's possible that, rather than seeing the final outcome of the game, they want to know how many times their team had an opportunity to attack but the defense regained control. So instead of

"Your team wins 2-1"

They want to see match highlights:

"Your team wins 2-1:
 - scored at minute 15,
 - other team took control and went for tried for a goal at minute 30, 
   but the shoot was intercepted,
 - we took control again and $PLAYER1 scored a beautiful goal!
... etc

You can use something like what Jamie suggests for a starting point, choose the times at random, and maybe pick who scored the goal based on a weighted sampling of the offensive players (i.e. a player with a higher score gets a higher chance of being the one who scored). You can have fun and add random low-probability events like a red card on a player, someone injuring themselves, streakers across the field...

深海不蓝 2024-08-10 07:54:53

平均值应该是玩家数量...如果您有 3 个玩家团队,则使用最大平均值:

[4 4 4]

[7 4 1]

第二个将被认为较弱。这就是你想要的吗?我认为你宁愿做这样的事情:(

总得分/总玩家)+(最大得分/总玩家),所以在上面的例子中,它会让第二支球队稍微好一些。

我想这取决于你认为团队应该如何平衡。

The average should be the number of players... using the max means if you have 3 player teams:

[4 4 4]

[7 4 1]

The second one would be considered weaker. Is that what you want? I think you would rather do something like:

(Total Scores / Total Players) + (Max Score / Total Players), so in the above example it would make the second team slightly better.

I guess it depends on how you feel the teams should be balanced.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文