UNPKG

glicko-ts

Version:

A TypeScript implementation of the Glicko-1 rating system.

30 lines (29 loc) 973 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MathUtils = void 0; class MathUtils { /** * Calculates the g(RD) function, which dampens the effect of the opponent's RD. * @param rd The rating deviation of the opponent. * @returns The dampened RD value. */ static g(rd, q) { const term = 3 * Math.pow(q, 2) * Math.pow(rd, 2) / Math.pow(Math.PI, 2); return 1 / Math.sqrt(1 + term); } /** * Rounds a number to a specified number of decimal places. * @param num The number to round. * @param places The number of decimal places. * @returns The rounded number. */ static roundToDecimalPlaces(num, places) { if (places === 0) { return Math.round(num); } const p = Math.pow(10, places); const rounded = (Math.round(num * p) / p); return Number(rounded.toFixed(places)); } } exports.MathUtils = MathUtils;