@studimax/elo
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

@studimax/elo

npm Code: TypeScript Made By: StudiMax

Implementation of Elo rating system.

Installation

npm install @studimax/elo
# or
yarn add @studimax/elo

Usage

Calculate calculatePerformance

/**
* Calculates the probability to win based on the rating of the opponent.
* @param Ra Elo rating of hero A.
* @param Rb Elo rating of hero B.
*/
calculatePerformance(Ra: number, Rb: number): {Ea: number; Eb: number};
import Elo from '@studimax/elo';

const elo = new Elo();

/** Caclculate performance **/
const {Ea, Eb} = elo.calculatePerformance(1613, 1609);
// Ea: 0.506
// Eb: 0.494

Calculate Rating

/**
* Calculates the expected score of a hero based on the rating of the other hero.
* @param Ra Elo rating of hero A.
* @param Rb Elo rating of hero B.
* @param S Expected score of hero A. (0 <= S <= 1)
*/
calculateRating(Ra: number, Rb: number, S = 1): {Rb: number; Ra: number};
const elo = new Elo({kFactor: 20});
const {Ra, Rb} = elo.calculateRating(1800, 2005, 1); // 1 = win
// Ra: ~1815
// Rb: ~1990
const elo = new Elo({kFactor: 20});
const {Ra, Rb} = elo.calculateRating(1800, 2005, 0.5); // 0.5 = draw
// Ra: ~1805
// Rb: ~2000
const elo = new Elo({kFactor: 20});
const {Ra, Rb} = elo.calculateRating(1800, 2005, 0); // 0 = loss
// Ra: ~1795
// Rb: ~2010

Package Sidebar

Install

npm i @studimax/elo

Weekly Downloads

7

Version

1.0.1

License

MIT

Unpacked Size

12.3 kB

Total Files

9

Last publish

Collaborators

  • maxscharwath