avoo/elo

Elo排名计算库

0.2.0 2015-12-07 11:04 UTC

This package is not auto-updated.

Last update: 2024-09-24 04:09:55 UTC


README

![构建状态] (https://scrutinizer-ci.com/g/avoo/Elo/badges/build.png?b=master) ![Scrutinizer 代码质量] (https://scrutinizer-ci.com/g/avoo/Elo/badges/quality-score.png?b=master) ![许可证] (https://poser.pugx.org/avoo/elo/license.svg)

这是一个PHP库,用于计算两名玩家之间的Elo排名。

文档

将以下内容添加到您的 composer.json 文件中

{
    "require": {
        "avoo/elo": "~0.2"
    }
}

默认使用方法

您需要在您的玩家类中实现 Avoo\Elo\Model\EloPlayerInterface

use Avoo\Elo\Model\EloPlayerInterface;
use Avoo\Elo\Model\EloUserInterface;

class EloPlayer implements EloPlayerInterface
{
    /**
     * @var integer
     */
    protected $elo;

    /**
     * @var EloUserInterface $user
     */
    protected $user;

    /**
     * {@inheritdoc}
     */
    public function setElo($elo)
    {
        $this->elo = $elo;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getElo()
    {
        return $this->elo;
    }

    /**
     * {@inheritdoc}
     */
    public function setUser(EloUserInterface $user)
    {
        $this->user = $user;

        return $this;
    }

    /**
     * {@inheritdoc}
     */
    public function getUser()
    {
        return $this->user;
    }

    //... Your own code
}

考虑玩家A拥有2300 Elo,玩家B拥有1800 Elo,玩家A输掉比赛。

默认设置中,胜利的得分是:- 0 玩家A输 - 0.5 平局 - 1 玩家A赢

示例1

use Avoo\Elo\EloPoint;
use Avoo\Elo\EloVersusInterface;
use Avoo\Elo\EloAggregagtionInterface;

$eloCalculator = new EloPoint();

/** @var EloVersusInterface $match */
$eloPoint->calculate($match);

/** @var EloAggregationInterface $aggregation */
$aggregation = $eloPoint->getAggregation(); 

示例2

use Avoo\Elo\EloPoint;
use Avoo\Elo\EloVersusInterface;
use Avoo\Elo\EloAggregagtionInterface;

/** @var EloVersusInterface $match */
$eloCalculator = new EloPoint($match);
$eloPoint->calculate();

/** @var EloAggregationInterface $aggregation */
$aggregation = $eloPoint->getAggregation(); 

覆盖配置

您可以通过覆盖默认配置来调整Elo计算器

use Avoo\Elo\EloPoint;
use Avoo\Elo\EloVersusInterface;
use Avoo\Elo\EloAggregagtionInterface;
use Avoo\Elo\ConfigurationInterface;

/** @var ConfigurationInterface $configuration */
$configuration = new Configuration();

/**
 * Floor is the experience range calculator
 */
$configuration->setFloor(200);

/**
 * Base range is ratio number for calculate the new elo
 * In this case between 0 and 1700 elo point the range is 50, over it's 20
 * For example with 1500 elo point for both players, with 50 elo range, the new elo will be 18 and -18,
 * and for 20 elo range, the new elo will be 7 and -7
 */
$configuration->setBaseRange(array(
    0 => 50
    1700 => 20
));

/*
 * Base elo is the start elo point for a new player
 */
$configuration->setBaseElo(1000);

/** @var EloVersusInterface $match */
$eloCalculator = new EloPoint($match, $configuration);
$eloPoint->calculate();

/** @var EloAggregationInterface $aggregation */
$aggregation = $eloPoint->getAggregation();