Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 设计了一种基于变量的团队获胜概率计算算法_Java_Algorithm_Math - Fatal编程技术网

Java 设计了一种基于变量的团队获胜概率计算算法

Java 设计了一种基于变量的团队获胜概率计算算法,java,algorithm,math,Java,Algorithm,Math,因此,我正在设计一款基于足球的Java游戏,两队将对决。然后我想设计一个算法,根据一些因素计算A队或B队获胜的概率 团队实力(设定后不变) 球队的状态(过去5场比赛中他们赢或输了多少场) 一些随机性,所以它可以走任何一条路,即使A队比B队更强,状态更好 我真的不知道从哪里开始虽然,任何提示将不胜感激 让我们从一点OOP开始: public class Team{ private double /*int*/ strength;//Change the datatype, by yo

因此,我正在设计一款基于足球的Java游戏,两队将对决。然后我想设计一个算法,根据一些因素计算A队或B队获胜的概率

  • 团队实力(设定后不变)

  • 球队的状态(过去5场比赛中他们赢或输了多少场)

  • 一些随机性,所以它可以走任何一条路,即使A队比B队更强,状态更好


  • 我真的不知道从哪里开始虽然,任何提示将不胜感激

    让我们从一点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
    }
    
    这是你的团队。 现在从计算比赛开始

    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() <= 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() <= 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.
       }
    }
    
    公共类足球模拟器{
    私人a队、b队;
    //…构造函数、getter、setter
    /**
    *计算A获胜的概率。
    *@返回概率,A赢。
    */
    公共双重计算可能性(){
    双重强度a=a.getStrength();
    双强度HB=b.getStrength();
    
    如果(a.getForm(),因为Java是一种OO语言,您可以从设计一个类来表示一个团队开始。谢谢,这就清楚了!我想知道为什么要使用“私有团队a,b;”,因为这会产生NullPointerException?我理解这是因为您还没有创建对象,但为什么不使用团队a=new team();例如?仍在努力学习哈哈。你必须初始化构造函数中的对象。