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

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

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)开始:

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

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

public class SoccerSimulator {
    private Team a, b;
    // ... 构造函数、获取器、设置器

    /**
     * 计算 A 赢得比赛的概率。
     * @return A 赢得比赛的概率。
     */
    public double calculateProbability() {
        double strengthA = a.getStrength();
        double strengthB = b.getStrength();
        if (a.getForm() <= 0.2)
            strengthA *= (1 + (Math.random % 0.1)); // 最多10%的奖励,因为他们在过去的5场比赛中只赢了0-1场
        if (b.getForm() <= 0.2)
            strengthB *= (1 + (Math.random % 0.1));
        // 对随机数生成器执行某些操作
        // ...
        // TODO:更好的算法
        double sum = strengthA + strengthB;
        return strengthA / sum; // 获取 A 相对于总和的分数。
    }
}

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

英文:

Let's start with a bit of OOP:

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

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

public class SoccerSimulator{
   private Team a,b;
   //...Constructors, Getters,Setters

   /**
   * Calculate the probability, that A wins.
   * @return the probability, A wins.
   */
   public double calculateProbability(){
      double strengthA = a.getStrength();
      double strengthB = b.getStrength();
      if(a.getForm() &lt;= 0.2)
          strengthA *= (1 + (Math.random % 0.1));//Up to 10% bonus, because they won only 0-1 games in the last 5 games
      if(b.getForm() &lt;= 0.2)
          strengthB *= (1 + (Math.random % 0.1));
      //Do something with the random number generator
      //....
      //TODO: Better algorithm
      double sum=strengthA + strengthB;
      return strengthA / sum;//Get the fraction A has in relationship to the sum.
   }
}

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:

确定