lindelius / php-fide
一个零依赖的FIDE评级系统PHP实现。
1.0
2021-02-07 16:48 UTC
Requires
- php: ^7.4||^8.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-01 14:54:35 UTC
README
一个零依赖的FIDE评级系统PHP实现。
要求
- PHP 8.1,或更高版本
安装
如果您使用Composer,您可以从项目的根目录运行以下命令来安装此库的最新版本
composer require lindelius/php-fide
您也可以手动通过导航到“发布”页面,然后展开最新版本的“资产”部分来下载库。
使用方法
步骤1. 在您的参赛实体模型(包含有关给定竞赛中给定参赛者评级信息的对象)中实现Lindelius\FIDE\ContestantInterface
接口。
use Lindelius\FIDE\ContestantInterface; final class MyContestant implements ContestantInterface { private int $highestRating; private int $matchesPlayed; private int $rating; // ... public function getCurrentRating(): int { return $this->rating; } public function getHighestRating(): int { return $this->highestRating; } public function getTotalMatchesPlayed(): int { return $this->matchesPlayed; } }
步骤2. 使用适当的Lindelius\FIDE\RatingSystemInterface
方法来计算每场比赛后参赛者的新评级。请注意,所有可用的方法都返回参赛者的新评级,而不仅仅是评级变化。
对于有胜者的比赛,您将想要使用calculateRatingAfterWin()
和calculateRatingAfterLoss()
方法。
$newRatingForWinner = $ratingSystem->calculateRatingAfterWin($winner, $loser); $newRatingForLoser = $ratingSystem->calculateRatingAfterLoss($loser, $winner);
对于以平局结束的比赛,您将想要使用calculateRatingAfterDraw()
方法。
$newRatingForContestant = $ratingSystem->calculateRatingAfterDraw($contestant, $opponent); $newRatingForOpponent = $ratingSystem->calculateRatingAfterDraw($opponent, $contestant);
基准测试
此库使用PHPBench进行基准测试。
您可以从库的根目录运行以下命令来在您的系统上基准测试此库
./vendor/bin/phpbench run --report=default