Design an algorithm to calculate probability of team winning depending on variables

huangapple go评论96阅读模式
英文:

Design an algorithm to calculate probability of team winning depending on variables

问题

I am designing a football-based game in Java where two teams will face off. Then I want to design an algorithm to calculate the probability of team A or team B winning depending on some factors.

  1. The strength of the team (which doesn't change after being set)

  2. The form the team is in (how many of their last 5 games they won or lost)

  3. Some randomness so it can go either way even if team A is much stronger and in better form than team B.

I don't really know where to start though, any tips would be appreciated!

英文:

so I am designing a football based game in Java where two teams will face off. Then I want to design an algorithm to calculate the probability of team A or team B winning depending on some factors.

  1. The strength of the team (which doesn't change after being set)

  2. The form the team is in (how many of their last 5 games they won or lost)

  3. Some randomness so it can go either way even if team A is much stronger and in better form than team B.

I don't really know where to start though, any tips would be appreciated!

答案1

得分: 1

让我们从面向对象编程(OOP)开始:

  1. public class Team {
  2. private double /*int*/ strength; // 根据您的喜好更改数据类型
  3. private double formOfLastFiveMatches; // 失去全部为0,全部赢为1,赢了3场比赛为0.6
  4. private Random random; // 用于随机性
  5. // ... 构造函数、获取器、设置器
  6. }

这是模拟您的球队。
现在开始计算比赛。

  1. public class SoccerSimulator {
  2. private Team a, b;
  3. // ... 构造函数、获取器、设置器
  4. /**
  5. * 计算 A 赢得比赛的概率。
  6. * @return A 赢得比赛的概率。
  7. */
  8. public double calculateProbability() {
  9. double strengthA = a.getStrength();
  10. double strengthB = b.getStrength();
  11. if (a.getForm() <= 0.2)
  12. strengthA *= (1 + (Math.random % 0.1)); // 最多10%的奖励,因为他们在过去的5场比赛中只赢了0-1场
  13. if (b.getForm() <= 0.2)
  14. strengthB *= (1 + (Math.random % 0.1));
  15. // 对随机数生成器执行某些操作
  16. // ...
  17. // TODO:更好的算法
  18. double sum = strengthA + strengthB;
  19. return strengthA / sum; // 获取 A 相对于总和的分数。
  20. }
  21. }

这是一个相当基本的算法,但您可以将其用作起点。

英文:

Let's start with a bit of OOP:

  1. public class Team{
  2. private double /*int*/ strength;//Change the datatype, by your favors
  3. private double formOfLastFiveMatches;//0 for lost all, 1 for won all, 0.6 for won 3 of 5
  4. private Random random; //For the randomness
  5. //...Constructors, Getters,Setters
  6. }

This is models your team.
Now start with calculating the match.

  1. public class SoccerSimulator{
  2. private Team a,b;
  3. //...Constructors, Getters,Setters
  4. /**
  5. * Calculate the probability, that A wins.
  6. * @return the probability, A wins.
  7. */
  8. public double calculateProbability(){
  9. double strengthA = a.getStrength();
  10. double strengthB = b.getStrength();
  11. if(a.getForm() &lt;= 0.2)
  12. strengthA *= (1 + (Math.random % 0.1));//Up to 10% bonus, because they won only 0-1 games in the last 5 games
  13. if(b.getForm() &lt;= 0.2)
  14. strengthB *= (1 + (Math.random % 0.1));
  15. //Do something with the random number generator
  16. //....
  17. //TODO: Better algorithm
  18. double sum=strengthA + strengthB;
  19. return strengthA / sum;//Get the fraction A has in relationship to the sum.
  20. }
  21. }

This is an quite basic algorithm, but you can use it as a starting point.

huangapple
  • 本文由 发表于 2020年8月5日 23:59:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/63269048.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定