lindelius/php-fide

A zero-dependency PHP implementation of the FIDE Rating System.

1.0 2021-02-07 16:48 UTC

This package is auto-updated.

Last update: 2024-04-29 03:44:21 UTC


README

CircleCI

A zero-dependency PHP implementation of the FIDE Rating System.

Requirements

  • PHP 7.4, or higher

Installation

If you are using Composer, you may install the latest version of this library by running the following command from your project's root folder:

composer require lindelius/php-fide

You may also manually download the library by navigating to the "Releases" page and then expanding the "Assets" section of the latest release.

Usage

Step 1. Implement the Lindelius\FIDE\ContestantInterface interface in your contestant entity model (the object holding rating information about a given contestant in a given competition).

use Lindelius\FIDE\ContestantInterface;

class Team 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;
    }
}

Step 2. Use the appropriate Lindelius\FIDE\RatingSystemInterface method(s) to calculate the new ratings for the contestants after each match. Please note that all available methods return the new rating for the contestant, and not just the rating change.

For matches with a winner, you will want to use the calculateRatingAfterWin() and calculateRatingAfterLoss() methods.

$newRatingForWinner = $ratingSystem->calculateRatingAfterWin($winner, $loser);
$newRatingForLoser = $ratingSystem->calculateRatingAfterLoss($loser, $winner);

And for matches that end in a draw, you will want to use the calculateRatingAfterDraw() method.

$newRatingForTeamA = $ratingSystem->calculateRatingAfterDraw($teamA, $teamB);
$newRatingForTeamB = $ratingSystem->calculateRatingAfterDraw($teamB, $teamA);