Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.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
Php ELO评分算法的实现_Php_Algorithm_Rating - Fatal编程技术网

Php ELO评分算法的实现

Php ELO评分算法的实现,php,algorithm,rating,Php,Algorithm,Rating,嘿,伙计们,我想实现elo算法来评估我局域网中的玩家。我的php脚本包含以下内容 <?php class Rating { const KFACTOR = 16; protected $_ratingA; protected $_ratingB; protected $_scoreA; protected $_scoreB; protected $_expectedA; protected $_expectedB; prote

嘿,伙计们,我想实现elo算法来评估我局域网中的玩家。我的php脚本包含以下内容

<?php
class Rating
{
    const KFACTOR = 16;
    protected $_ratingA;
    protected $_ratingB;
    protected $_scoreA;
    protected $_scoreB;
    protected $_expectedA;
    protected $_expectedB;
    protected $_newRatingA;
    protected $_newRatingB;
    public function  __construct($ratingA,$ratingB,$scoreA,$scoreB)
    {
        $this->_ratingA = $ratingA;
        $this->_ratingB = $ratingB;
        $this->_scoreA = $scoreA;
        $this->_scoreB = $scoreB;
        $expectedScores = $this -> _getExpectedScores($this -> _ratingA,$this -> _ratingB);
        $this->_expectedA = $expectedScores['a'];
        $this->_expectedB = $expectedScores['b'];
        $newRatings = $this ->_getNewRatings($this -> _ratingA, $this -> _ratingB, $this -> _expectedA, $this -> _expectedB, $this -> _scoreA, $this -> _scoreB);
        $this->_newRatingA = $newRatings['a'];
        $this->_newRatingB = $newRatings['b'];
    }
    public function setNewSettings($ratingA,$ratingB,$scoreA,$scoreB)
    {
        $this -> _ratingA = $ratingA;
        $this -> _ratingB = $ratingB;
        $this -> _scoreA = $scoreA;
        $this -> _scoreB = $scoreB;
        $expectedScores = $this -> _getExpectedScores($this -> _ratingA,$this -> _ratingB);
        $this -> _expectedA = $expectedScores['a'];
        $this -> _expectedB = $expectedScores['b'];
        $newRatings = $this ->_getNewRatings($this -> _ratingA, $this -> _ratingB, $this -> _expectedA, $this -> _expectedB, $this -> _scoreA, $this -> _scoreB);
        $this -> _newRatingA = $newRatings['a'];
        $this -> _newRatingB = $newRatings['b'];
    }
    public function getNewRatings()
    {
        return array (
            'a' => $this -> _newRatingA,
            'b' => $this -> _newRatingB
        );
    }
    protected function _getExpectedScores($ratingA,$ratingB)
    {
        $expectedScoreA = 1 / ( 1 + ( pow( 10 , ( $ratingB - $ratingA ) / 400 ) ) );
        $expectedScoreB = 1 / ( 1 + ( pow( 10 , ( $ratingA - $ratingB ) / 400 ) ) );
        return array (
            'a' => $expectedScoreA,
            'b' => $expectedScoreB
        );
    }
    protected function _getNewRatings($ratingA,$ratingB,$expectedA,$expectedB,$scoreA,$scoreB)
    {
        $newRatingA = $ratingA + ( self::KFACTOR * ( $scoreA - $expectedA ) );
        $newRatingB = $ratingB + ( self::KFACTOR * ( $scoreB - $expectedB ) );
        return array (
            'a' => $newRatingA,
            'b' => $newRatingB
        );
    }
}
//first player won
$first_player_rating=200;
$second_player_rating=200;
$n=new Rating($first_pic_rating,$second_pic_rating,1400,1400);
$a=$n->getNewRatings();
var_dump($a);
?>


我给第一名球员和第二名球员的评分都是200,这是错误的,但问题是,如果第一名球员刚刚赢得比赛,第一名球员和第二名球员的评分值应该是多少…

方法是错误的

<?php
class elo
{
    private $Ra,$Rb,$Pa,$Pb;
    public $won,$NRa,$NRb;
    function __construct($Ra,$Rb,$won)//$Ra and $Rb are rating given...
    {
        $k=24;
        $this->Ra=$Ra;
        $this->Rb=$Rb;
        $Pa=1/(1+10^(($Rb-$Ra)/400));
        $Pb=1/(1+10^(($Ra-$Rb)/400));
        $this->won=$won;
        if($won=="first")
        {
            $this->NRa=$this->Ra+($k*$Pa);
            $this->NRb=$this->Rb-($k*$Pb);
        }else
        {
            $this->NRa=$this->Ra-($k*$Pa);
            $this->NRb=$this->Rb+($k*$Pb);
        }
    }
    function getNewRatings()
    {
        $result=array($this->NRa,$this->NRb);
        return $result;
    }
}

?>
<?php
require_once('elo.php');
$n=new elo(1400,1400,"first");
$a=$n->getNewRatings();
var_dump($a);
?>


现在可以使用给定的类了…

我投了反对票,因为我没有看到任何代码问题。我没有看到任何问题,任何错误或任何错误。我认为这是不恰当的。当然,我可能不对。更好地描述你的问题,展示解决方案尝试。正确地看问题,给两名球员的评分,这不是真的,两名球员的评分都必须有一个值,我要的是初始值,如果第一名球员刚刚赢得比赛