Skip to content

A zero-dependency PHP implementation of the FIDE Rating System

License

Notifications You must be signed in to change notification settings

lindelius/php-fide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-fide

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);

About

A zero-dependency PHP implementation of the FIDE Rating System

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages