ghorwood/phelo
Composer 安装命令:
composer require ghorwood/phelo
包简介
An elo ranking system library for php.
README 文档
README
Phelo is a simple library for managing the elo rating system.
The elo system is a rating method used in chess and other comptetitive games to calculate an estimate of the strength of the player, based on his or her performance versus other players.
Installation
The preferred installation method is via composer
composer require ghorwood/phelo
Usage
Phelo works by creating an object to which you can add an arbitrary number of players and their associated initial elo scores. You can then:
- Calculate the percentage chance of a given player defeating another player
- Match two players against each other, setting a winner, and harvest the resulting elos
Instantiation
Presuming you have used an autoloader, you can use and instantiate phelo as such:
use ghorwood\Phelo\Phelo; $phelo = new Phelo();
Adding players
Players can be set directly into the Phelo object as such
$phelo = new Phelo(); // Create player 'jasminder' with elo of 1000 $phelo->jasminder = 1000; // You can also use variables. This is the method you should use for multi-word names. $player1 = 'jasminder'; $phelo->$player1 = 1000; $player2 = 'Barry Clarke'; $phelo->$player2 = 1000; $player3 = "白百柏"; $phelo->$player3 = 1000;
Getting a players elo
An individual player's elo can be retreived by referencing their name
$phelo = new Phelo(); $phelo->jasminder = 1000; print $phelo->jasminder; // 1000
All players can be retreived using getAll() which returns an array keyed by the player name.
$phelo = new Phelo(); $phelo->jasminder = 1000; $phelo->ahmed = 1200; $all = $phelo->getAll(); print_r($all); // ['jasminder' => 1000, 'ahmed' => 1200]
Calculating chance of win
If two players with different elo ratings are matched against each other, it is assumed the player with the higher elo score has a greater probability of winning. Phelo can calculate the percent chance of a given player defeating another player with the chance() method.
The chance() method takes two player names as arguments. The first argument is the player for whom the chance of winning will be calculated
$phelo = new Phelo(); $phelo->Jerry = 1000; $phelo->Sigrid = 910; // Calculate the percent chance of Jerry winning by passing as first argument $chanceJerryWins = $phelo->chance("Jerry", "Sigrid"); // Repeat, but for Sigrid $chanceSigridWins = $phelo->chance("Sigrid", "Jerry"); // Chance of winning is a percent to two decimal places. print $chanceJerryWins; // 62.67 print $chanceSigridWins; // 37.33 // Percentage chances add up to 100.00 print $chanceSigridWins + $chanceJerryWins; // 100.00
Running matches to calculate elo changes
Elo scores change for players after they win or lose matches. Phelo provides the method match() to simulate a contest between two players. The leftmost of the two players is the winner. After a call to match() the new elo scores for the contestants is updated in the object and can be retreived.
$phelo = new \ghorwood\Phelo\Phelo(); $phelo->Tyrone = 1200; $phelo->Katarina = 800; // Katarina defeats Tyrone $phelo->match('Katarina', 'Tyrone'); // Get the updated elo scores print $phelo->Katarina; // 827 print $phelo->Tyrone; // 1173
Calls to match() can be chained to simulate several consecutive contests.
$phelo = new \ghorwood\Phelo\Phelo(); $phelo->Tyrone = 1200; $phelo->Katarina = 800; // Katarina defeats Tyrone in four consecutive matches $phelo->match("Katarina", "Tyrone") ->match("Katarina", "Tyrone") ->match("Katarina", "Tyrone") ->match("Katarina", "Tyrone"); // Get the updated elo scores print $phelo->Katarina; // 902 print $phelo->Tyrone; // 1099
Errors
Phelo will throw an Exception in the following cases:
- Attempt to get a player that does not exist
- Attempt a match() or chance() on a player that does not exist
- Attempt to create a player with an elo less than 1
The use of try/catch blocks for Exception is encouraged.
K factor
The K factor affects the sensitivity of changes: a higher K factor increases the changes in elo scores created by matches.
Choosig a K factor that is right for your requirements can be difficult. A good starting place to read on K factor is the 'Most accurate K-factor' sectionof the wikipedia entry on elo.
Phelo's default K factor is 30. You can change this to your custom value at instation by passing a new value to the contructor:
// K factor FIDE uses for players under 18. $phelo = new \ghorwood\Phelo\Phelo(40);
Gradation of K factor for different elo ratings is not supported in Phelo as this time.
Getting support or contributing
Any prs should conform to PSR-2 formatting, pass phpstan static analysis at level 7 and be accompanied by tests.
The precommit.sh script is provided to do the formatting, analysis and tests.
Support requests, questions or bug reports should also be accompanied by a twitter dm to @gbhorwood, because i'm terrible at email.
ghorwood/phelo 适用场景与选型建议
ghorwood/phelo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 02 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Rating」 「games」 「ranking」 「chess」 「elo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ghorwood/phelo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ghorwood/phelo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ghorwood/phelo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PHP glicko2 implementation with an easy to use interface
This Extension integrates a credit check and more made by the LEONEX Risk Management Platform into your order process. Extensive configuration and evaluation options is provided in the Platform
Epic Games OAuth 2.0 Client Provider for The PHP League OAuth2-Client
A points-based leaderboard extension for Flarum with configurable point sources, period filtering, and podium display.
Rating syetem for Laravel 5
This is a ranking.
统计信息
- 总下载量: 41
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-02-16