Skip to content

Instantly share code, notes, and snippets.

@mkuklis
Created July 7, 2013 06:39
Show Gist options
  • Save mkuklis/5942570 to your computer and use it in GitHub Desktop.
Save mkuklis/5942570 to your computer and use it in GitHub Desktop.
elo rating
function elo(oldRating, opponentRating, result) {
var kFactor;
var expected = 1.0 / (1.0 + Math.pow(10.0, ((opponentRating - oldRating) / 400)));
if (oldRating < 2100) {
kFactor = 32;
} else if (oldRating >= 2100 && oldRating <= 2400) {
kFactor = 24;
}
else if (oldRating > 2400) {
kFactor = 16;
}
return oldRating + kFactor * (result - expected);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment