Skip to content

Commit

Permalink
Added usage information to the README file
Browse files Browse the repository at this point in the history
  • Loading branch information
lindelius committed May 13, 2017
1 parent 27a1300 commit f5ef6fd
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,54 @@ composer require "lindelius/php-fide=^0.1"
```

## Usage

First of all, implement the `Lindelius\FIDE\Contestant` interface in your ladder participant model (the object holding rating information about a given contestant in a given ladder or tournament)

```php
use Lindelius\FIDE\Contestant;

/**
* Class LadderParticipant
*/
class LadderParticipant implements Contestant
{
public function currentRating()
{
// TODO: Return the contestants current rating
}

public function highestRating()
{
// TODO: Return the contestants highest rating
}

public function totalMatchesPlayed()
{
// TODO: Return the total number of matches played by the contestant
}
}
```

then use the static `Lindelius\FIDE\RatingSystem::calculateRatingChange()` method to calculate the contestants rating changes after each match.

```php
use Lindelius\FIDE\RatingSystem;

/**
* Calculate rating changes.
*
* `$outcome` should be the outcome for `$contestant` and must be either of the
* constants defined in the `Lindelius\FIDE\RatingSystem` class.
*/
$contestantRatingChange = RatingSystem::calculateRatingChange($contestant, $opponent, $outcome);
$opponentRatingChange = RatingSystem::calculateRatingChange($opponent, $contestant, -$outcome);

/**
* Set the contestants new ratings by adding the calculated rating changes to
* their current ratings.
*/
$contestantNewRating = $contestant->currentRating() + $contestantRatingChange;
$opponentNewRating = $opponent->currentRating() + $opponentRatingChange;

// TODO: Save the new ratings
```

0 comments on commit f5ef6fd

Please sign in to comment.