Created
November 9, 2020 20:34
-
-
Save mattmazzola/24f8b8317e7c930db7a5e49c66f68591 to your computer and use it in GitHub Desktop.
Create Rating System Final
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type KFactorOption = | |
| KFactorFunctionWithPlayers | |
| KFactorFunction | |
| number | |
export function createRatingSystem(kFactor: KFactorOption = 32, exponentDenominator: number = 400, exponentBase: number = 10): RatingSystem { | |
let resolvedKFactor: KFactorFunctionWithPlayers | |
if (typeof kFactor === 'number') { | |
resolvedKFactor = () => kFactor | |
} | |
else { | |
resolvedKFactor = kFactor | |
} | |
// Standard Elo implementation with symmetric kfactor functions for each player | |
// This would be a true zero-sum game where A(-x) = B(+x) | |
const symmetricKFactorFn = (rating: number) => resolvedKFactor(rating, undefined) | |
const getPlayerProbabilities = createPlayerProbabilitiesFn(exponentBase, exponentDenominator) | |
const getNextRating = createNextRatingFn(symmetricKFactorFn) | |
// Modified Elo implementation with potentially *asymmetric* kfactor functions (e.g. One play kfactor is higher than the others) | |
// This means one player may gain or lose more than the other player would in similar | |
const aKFactor = (rating: number) => resolvedKFactor(rating, 0) | |
const getNextARating = createNextRatingFn(aKFactor) | |
const bKFactor = (rating: number) => resolvedKFactor(rating, 1) | |
const getNextBRating = createNextRatingFn(bKFactor) | |
const getNextRatings = createNextRatingsFn(getPlayerProbabilities, getNextARating, getNextBRating) | |
return { | |
getPlayerProbabilities, | |
getNextRating, | |
getNextRatings | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment