PHP code example of zelenin / elo

1. Go to this page and download the library: Download zelenin/elo library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zelenin / elo example snippets


use Zelenin\Elo\Player;

$player1 = new Player(1200);
$player2 = new Player(800);

use Zelenin\Elo\Match;

$match = new Match($player1, $player2);
$match->setScore(1, 0)
    ->setK(32)
    ->count();

$player1 = $match->getPlayer1();
$player2 = $match->getPlayer2();

$newRating1 = $player1->getRating();
$newRating2 = $player2->getRating();

use Zelenin\Elo\Match;
use Zelenin\Elo\Player;

$player1 = new Player(1200);
$player2 = new Player(800);

$goalIndexHandler = function ($score1, $score2) {
    $diff = abs($score1 - $score2);
    if ($diff > 0) {
        return sqrt($diff);
    }
    return 1;
};

$homeCorrectionHandler = function ($home, $diff) {
    $coefficient = 100;
    if ($home == 1) {
        return $diff - $coefficient;
    }
    if ($home == 2) {
        return $diff + $coefficient;
    }
    return $diff;
};

$match = new Match($player1, $player2);
$match->setScore(1, 0)
    ->setK(32)
    ->setGoalIndexHandler($goalIndexHandler)
    ->setHome(2)
    ->setHomeCorrectionHandler($homeCorrectionHandler)
    ->count();

$newRating1 = $player1->getRating();
$newRating2 = $player2->getRating();

php composer.phar