toefungi-elo-calculator
Version:
A package to do all necessary computations to determine ELO rankings
99 lines • 4.33 kB
TypeScript
import { ScoringBonus } from './enums/ScoringBonus';
import { Probabilities } from './types/Probabilities';
/**
* https://metinmediamath.wordpress.com/2013/11/27/how-to-calculate-the-elo-rating-including-example/
*
* EloCalculator class to do calculations to determine the elo of a player after a match.
*/
declare class EloCalculator {
readonly kFactor: number;
readonly shouldRound: boolean;
/**
* Constructor method for the EloCalculator class.
*
* @param {boolean} shouldRound Whether or not the new ELO should be rounded before being returned.
* @param {number} kFactor The factor the new ELO is calculated against.
*/
constructor(shouldRound?: boolean, kFactor?: number);
/**
* @private
*
* Takes a current ELO score and will convert it to it's equivalent base10 value which can be used
* to determine ELO for a win, loss or draw.
*
* @param {number} elo An ELO score to be converted to base10.
* @return {Promise<number>} The equivalent base10 rank of the given ELO.
*/
private convertEloToBase10;
/**
* @private
*
* Calculates the base10 equivalent value of each player's ELO score which can then be used to determine the new ELO
* score for the player.
*
* @param {number} playerElo The initial ELO of the player.
* @param {number} opponentElo The initial ELO of the opponent.
* @return {Promise<RelativeRank>} An object containing the equivalent base10 value of both player's ELO score.
*/
private determineRelativeRank;
/**
* @private
*
* Determines the scoring factor of the player based on their rank against their opponents rank.
*
* @param {number} playerRank The base10 value of the player's ELO score.
* @param {number} opponentRank The base10 value of the opponent's ELO score.
* @return {Promise<number>} The determined scoring factor.
*/
private determineScoreFactor;
/**
* @private
*
* Determines the new ELO of a player based on the score factor, a win or loss and current ELO score.
*
* @param {number} playerElo A player's current ELO score.
* @param {number} scoringFactor A factor derived from the player's relative base10 ELO score with their opponent's .
* @param {ScoringBonus} score Enum with [ WIN, LOSS, DRAW ].
* @param {number} scoreDiff The difference in the score as a number.
* @return {Promise<number>} The new calculated ELO.
*/
private determineElo;
/**
* @private
*
* Rounds off the ELO score before it is returned.
*
* @param {number} elo A value representing the ELO.
* @return {Promise<number>} The rounded off ELO value.
*/
private rounding;
/**
* @private
*
* Creates a probability object which will be returned to the user.
*
* @param {number} probability The probability of the `player` to win the game.
* @return {Promise<Probabilities>} The probability of a win for either player based on the `player` ELO.
*/
private createProbability;
/**
* Calculate the ELO of a player after a match based on their opponent's ELO and whether or not the player won the game.
*
* @param {number} playerElo The ELO of the player.
* @param {number} opponentElo The ELO of the opponent.
* @param {ScoringBonus} score The outcome of the game for the player, enum with [ WIN, LOSS, DRAW ].
* @param {number} scoreDiff The difference in the score as a number.
* @return {Promise<number>} The new ELO of the player.
*/
calculateElo(playerElo: number, opponentElo: number, score: ScoringBonus, scoreDiff?: number): Promise<number>;
/**
* Calculate the win probability for players in a match up given their respective ELO's.
*
* @param {number} playerElo The ELO of the player.
* @param {number} opponentElo The ELO of the opponent.
* @return {Promise<Probabilities>} The win probability for each player respectively.
*/
caluclateWinProbability(playerElo: number, opponentElo: number): Promise<Probabilities>;
}
export { EloCalculator };
//# sourceMappingURL=EloCalculator.d.ts.map