Glicko2
PHP implementation of the Glicko-2 rating algorithm
Install / Use
/learn @MaartenStaa/Glicko2README
Glicko2
PHP implementation of the Glicko-2 rating algorithm. This is a PHP port of goochjs/glicko2.
Installation
Using Composer, add the package to your require section.
{
"require": {
"maartenstaa/glicko2": "dev-master"
}
}
Run composer update to fetch the new requirement.
Usage
use MaartenStaa\Glicko2\Rating;
use MaartenStaa\Glicko2\RatingCalculator;
use MaartenStaa\Glicko2\RatingPeriodResults;
// Instantiate a RatingCalculator object.
// At instantiation, you can set the default rating for a player's volatility and
// the system constant for your game ("τ", which constrains changes in volatility
// over time) or just accept the defaults.
$calculator = new RatingCalculator(/* $initVolatility, $tau */);
// Instantiate a Rating object for each player.
$player1 = new Rating($calculator/* , $rating, $ratingDeviation, $volatility */);
$player2 = new Rating($calculator/* , $rating, $ratingDeviation, $volatility */);
$player3 = new Rating($calculator/* , $rating, $ratingDeviation, $volatility */);
// Instantiate a RatingPeriodResults object.
$results = new RatingPeriodResults();
// Add game results to the RatingPeriodResults object until you reach the end of your rating period.
// Use addResult($winner, $loser) for games that had an outcome.
$results->addResult($player1, $player2);
// Use addDraw($player1, $player2) for games that resulted in a draw.
$results->addDraw($player1, $player2);
// Use addParticipant($player) to add players that played no games in the rating period.
$results->addParticipant($player3);
// Once you've reached the end of your rating period, call the updateRatings method
// against the RatingCalculator; this takes the RatingPeriodResults object as argument.
// * Note that the RatingPeriodResults object is cleared down of game results once
// the new ratings have been calculated.
// * Participants remain within the RatingPeriodResults object, however, and will
// have their rating deviations recalculated at the end of future rating periods
// even if they don't play any games. This is in-line with Glickman's algorithm.
$calculator->updateRatings($results);
// Access the getRating, getRatingDeviation, and getVolatility methods of each
// player's Rating to see the new values.
foreach (array($player1, $player2, $player3) as $index => $player) {
echo 'Player #', $index, ' values: ', $player->getRating(), ', ',
$player->getRatingDeviation(), ', ', $player->getVolatility(), PHP_EOL;
}
Contributing
Coding standard
All code is to follow the PSR-2 coding standard.
Unit tests
If you find a bug, feel free to send a pull request to fix it, but make sure to always include a regression test.
Related Skills
node-connect
349.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。


